Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue cannot create two files of the same type, even if the name is different #80

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/adapters/gist-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({
seq: 0,

generateIdForRecord: function(store, type, inputProperties) {
return inputProperties.filePath.replace(/\//gi, '.');
return inputProperties.filePath.replace(/\//gi, '.') + "." + this.incrementProperty('seq');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of allowing duplicate filePath's, I think that we should delay calling store.createRecord until after we have prompted for the file name.

We should:

  • Add a build (or buildProperties) to ember-cli service.
  • Move main logic out of generate into build, leaving generate as roughly return this.store.createRecord('gistFile', this.build(type));.
  • Update addNew action in gist/controller.js to call build, then prompt, then createRecord.

}
});
});
4 changes: 4 additions & 0 deletions app/gist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default Em.Controller.extend({
* Build the application and set the iframe code
*/
buildApp () {
if (this.get('isDestroyed')) {
return;
}

this.set('isBuilding', true);
this.set('buildErrors', []);

Expand Down
2 changes: 1 addition & 1 deletion app/gist/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<li><a {{action 'addFile' 'model'}}>Model</a></li>
<li><a {{action 'addFile' 'controller'}}>Controller</a></li>
<li><a {{action 'addFile' 'route'}}>Route</a></li>
<li><a {{action 'addFile' 'template'}}>Template</a></li>
<li><a {{action 'addFile' 'template'}} class="test-template-action">Template</a></li>
<li><a {{action 'addFile' 'router'}}>Router</a></li>
<li><a {{action 'addFile' 'css'}}>CSS</a></li>
</ul>
Expand Down
40 changes: 39 additions & 1 deletion tests/acceptance/gist-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ const firstFilePicker = '.code:first-of-type .dropdown-toggle';
const secondFile = '.code:first-of-type .dropdown-menu li:nth-child(2) a';
const anyFile = '.code:first-of-type .dropdown-menu li:nth-child(1) a';
const fileMenu = '.file-menu .dropdown-toggle';
// const firstColumn = '.code:first-of-type';
//const firstColumn = '.code:first-of-type';
const deleteAction = '.file-menu a:contains(Delete)';
const addTemplateAction = '.test-template-action';
const firstFilePickerFiles = '.code:first-of-type .dropdown-menu>li';

let promptValue = '';

module('Acceptance | gist', {
beforeEach: function() {
application = startApp();
cacheConfirm = window.confirm;
window.confirm = () => true;
window.prompt = () => promptValue;
},

afterEach: function() {
Expand Down Expand Up @@ -54,3 +59,36 @@ test('deleting a gist loaded in two columns', function(assert) {
});
});
});

test('can add two templates with different names', function(assert) {
visit('/');
let origFiles;

andThen(function() {
click(firstFilePicker);
});

andThen(function() {
origFiles = find(firstFilePickerFiles).length;
promptValue = "foo/template.hbs";
click(fileMenu);
click(addTemplateAction);
click(firstFilePicker);
});

let numFiles;

andThen(function() {
numFiles = find(firstFilePickerFiles).length;
assert.equal(numFiles, origFiles + 1, 'Added first file');
promptValue = "bar/template.hbs";
click(fileMenu);
click(addTemplateAction);
click(firstFilePicker);
});

andThen(function() {
numFiles = find(firstFilePickerFiles).length;
assert.equal(numFiles, origFiles + 2, 'Added second file');
});
});