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

[BUGFIX release] Revert blueprints to use the old import DS format #4481

Merged
merged 1 commit into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion blueprints/adapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module.exports = {
],

locals: function(options) {
return extendFromApplicationEntity('adapter', 'JSONAPIAdapter', 'ember-data/adapters/json-api', options);
return extendFromApplicationEntity('adapter', 'DS.JSONAPIAdapter', options);
}
};
17 changes: 7 additions & 10 deletions blueprints/model/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ For instance: <green>\`ember generate model taco filling:belongs-to:protein topp
would result in the following model:

```js
import Model from 'ember-data/model';
import DS from 'ember-data';

import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';

export default Model.extend({
filling: belongsTo('protein'),
toppings: hasMany('topping'),
name: attr('string'),
price: attr('number'),
misc: attr()
export default DS.Model.extend({
filling: DS.belongsTo('protein'),
toppings: DS.hasMany('topping'),
name: DS.attr('string'),
price: DS.attr('number'),
misc: DS.attr()
});
```
4 changes: 2 additions & 2 deletions blueprints/model/files/__root__/__path__/__name__.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= importStatements %>
import DS from 'ember-data';

export default Model.extend({
export default DS.Model.extend({
<%= attrs.length ? ' ' + attrs : '' %>
});
35 changes: 4 additions & 31 deletions blueprints/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ module.exports = {
var attrs = [];
var needs = [];
var entityOptions = options.entity.options;
var importStatements = ['import Model from \'ember-data/model\';'];
var shouldImportAttr = false;
var shouldImportBelongsTo = false;
var shouldImportHasMany = false;

for (var name in entityOptions) {
var type = entityOptions[name] || '';
Expand All @@ -39,15 +35,12 @@ module.exports = {
var camelizedNamePlural = inflection.pluralize(camelizedName);
attr = dsAttr(dasherizedForeignModelSingular, dasherizedType);
attrs.push(camelizedNamePlural + ': ' + attr);
shouldImportHasMany = true;
} else if (/belongs-to/.test(dasherizedType)) {
attr = dsAttr(dasherizedForeignModel, dasherizedType);
attrs.push(camelizedName + ': ' + attr);
shouldImportBelongsTo = true;
} else {
attr = dsAttr(dasherizedName, dasherizedType);
attrs.push(camelizedName + ': ' + attr);
shouldImportAttr = true;
}

if (/has-many|belongs-to/.test(dasherizedType)) {
Expand All @@ -59,30 +52,10 @@ module.exports = {
return needs.indexOf(need) === i;
});

if (shouldImportAttr) {
importStatements.push('import attr from \'ember-data/attr\';');
} else {
importStatements.push('// import attr from \'ember-data/attr\';');
}

if (shouldImportBelongsTo && shouldImportHasMany) {
importStatements.push('import { belongsTo, hasMany } from \'ember-data/relationships\';');
} else if (shouldImportBelongsTo) {
importStatements.push('import { belongsTo } from \'ember-data/relationships\';');
importStatements.push('// import { hasMany } from \'ember-data/relationships\';');
} else if (shouldImportHasMany) {
importStatements.push('// import { belongsTo } from \'ember-data/relationships\';');
importStatements.push('import { hasMany } from \'ember-data/relationships\';');
} else {
importStatements.push('// import { belongsTo, hasMany } from \'ember-data/relationships\';');
}

importStatements = importStatements.join(EOL);
attrs = attrs.join(',' + EOL + ' ');
needs = ' needs: [' + needsDeduplicated.join(', ') + ']';

return {
importStatements: importStatements,
attrs: attrs,
needs: needs
};
Expand All @@ -92,14 +65,14 @@ module.exports = {
function dsAttr(name, type) {
switch (type) {
case 'belongs-to':
return 'belongsTo(\'' + name + '\')';
return 'DS.belongsTo(\'' + name + '\')';
case 'has-many':
return 'hasMany(\'' + name + '\')';
return 'DS.hasMany(\'' + name + '\')';
case '':
//"If you don't specify the type of the attribute, it will be whatever was provided by the server"
//http://emberjs.com/guides/models/defining-models/
return 'attr()';
return 'DS.attr()';
default:
return 'attr(\'' + type + '\')';
return 'DS.attr(\'' + type + '\')';
}
}
2 changes: 1 addition & 1 deletion blueprints/serializer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module.exports = {
],

locals: function(options) {
return extendFromApplicationEntity('serializer', 'JSONAPISerializer', 'ember-data/serializers/json-api', options);
return extendFromApplicationEntity('serializer', 'DS.JSONAPISerializer', options);
}
};
4 changes: 2 additions & 2 deletions blueprints/transform/files/__root__/__path__/__name__.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Transform from 'ember-data/transform';
import DS from 'ember-data';

export default Transform.extend({
export default DS.Transform.extend({
deserialize(serialized) {
return serialized;
},
Expand Down
6 changes: 2 additions & 4 deletions lib/utilities/extend-from-application-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var pathUtil = require('ember-cli-path-utils');
var existsSync = require('exists-sync');
var path = require('path');

module.exports = function(type, baseClass, packagePath, options) {
module.exports = function(type, baseClass, options) {
var entityName = options.entity.name;
var isAddon = options.inRepoAddon || options.project.isEmberCLIAddon();
var relativePath = pathUtil.getRelativePath(options.entity.name);
Expand All @@ -18,14 +18,12 @@ module.exports = function(type, baseClass, packagePath, options) {
var hasApplicationEntity = existsSync(applicationEntityPath);
if (!isAddon && !options.baseClass && entityName !== 'application' && hasApplicationEntity) {
options.baseClass = 'application';
packagePath = './application';
}

if (options.baseClass === entityName) {
throw new SilentError(stringUtil.classify(type) + 's cannot extend from themself. To resolve this, remove the `--base-class` option or change to a different base-class.');
}

var importStatement = 'import ' + baseClass + ' from \'' + packagePath + '\';';
var importStatement = 'import DS from \'ember-data\';';

if (options.baseClass) {
baseClass = stringUtil.classify(options.baseClass.replace('\/', '-'));
Expand Down
8 changes: 4 additions & 4 deletions node-tests/blueprints/adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('Acceptance: generate and destroy adapter blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/adapters/foo.js'))
.to.contain('import JSONAPIAdapter from \'ember-data/adapters/json-api\';')
.to.contain('export default JSONAPIAdapter.extend({');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.JSONAPIAdapter.extend({');

expect(_file('tests/unit/adapters/foo-test.js'))
.to.contain('moduleFor(\'adapter:foo\'');
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('Acceptance: generate and destroy adapter blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/adapters/application.js'))
.to.contain('import JSONAPIAdapter from \'ember-data/adapters/json-api\';')
.to.contain('export default JSONAPIAdapter.extend({');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.JSONAPIAdapter.extend({');

expect(_file('tests/unit/adapters/application-test.js'))
.to.contain('moduleFor(\'adapter:application\'');
Expand Down
69 changes: 20 additions & 49 deletions node-tests/blueprints/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ describe('Acceptance: generate and destroy model blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/models/foo.js'))
.to.contain('import Model from \'ember-data/model\';')
.to.contain('export default Model.extend(')
.to.contain('// import attr from \'ember-data/attr\';')
.to.contain('// import { belongsTo, hasMany } from \'ember-data/relationships\';')
.to.not.contain('import { belongsTo } from \'ember-data/relationships\';')
.to.not.contain('import { hasMany } from \'ember-data/relationships\';');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')

expect(_file('tests/unit/models/foo-test.js'))
.to.contain('moduleForModel(\'foo\'');
Expand All @@ -45,20 +41,16 @@ describe('Acceptance: generate and destroy model blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/models/foo.js'))
.to.contain('import Model from \'ember-data/model\';')
.to.contain('import attr from \'ember-data/attr\';')
.to.contain('export default Model.extend(')
.to.contain('misc: attr()')
.to.contain('skills: attr(\'array\')')
.to.contain('isActive: attr(\'boolean\')')
.to.contain('birthday: attr(\'date\')')
.to.contain('someObject: attr(\'object\')')
.to.contain('age: attr(\'number\')')
.to.contain('name: attr(\'string\')')
.to.contain('customAttr: attr(\'custom-transform\')')
.to.contain('// import { belongsTo, hasMany } from \'ember-data/relationships\';')
.to.not.contain('import { belongsTo } from \'ember-data/relationships\';')
.to.not.contain('import { hasMany } from \'ember-data/relationships\';');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')
.to.contain('misc: DS.attr()')
.to.contain('skills: DS.attr(\'array\')')
.to.contain('isActive: DS.attr(\'boolean\')')
.to.contain('birthday: DS.attr(\'date\')')
.to.contain('someObject: DS.attr(\'object\')')
.to.contain('age: DS.attr(\'number\')')
.to.contain('name: DS.attr(\'string\')')
.to.contain('customAttr: DS.attr(\'custom-transform\')')

expect(_file('tests/unit/models/foo-test.js'))
.to.contain('moduleForModel(\'foo\'');
Expand All @@ -71,14 +63,10 @@ describe('Acceptance: generate and destroy model blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/models/comment.js'))
.to.contain('import Model from \'ember-data/model\';')
.to.contain('import { belongsTo } from \'ember-data/relationships\';')
.to.contain('export default Model.extend(')
.to.contain('post: belongsTo(\'post\')')
.to.contain('author: belongsTo(\'user\')')
.to.contain('// import attr from \'ember-data/attr\';')
.to.contain('// import { hasMany } from \'ember-data/relationships\';')
.to.not.contain('import { belongsTo, hasMany } from \'ember-data/relationships\';');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')
.to.contain('post: DS.belongsTo(\'post\')')
.to.contain('author: DS.belongsTo(\'user\')')

expect(_file('tests/unit/models/comment-test.js'))
.to.contain('moduleForModel(\'comment\'')
Expand All @@ -92,34 +80,17 @@ describe('Acceptance: generate and destroy model blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/models/post.js'))
.to.contain('import Model from \'ember-data/model\';')
.to.contain('import { hasMany } from \'ember-data/relationships\';')
.to.contain('export default Model.extend(')
.to.contain('comments: hasMany(\'comment\')')
.to.contain('otherComments: hasMany(\'comment\')')
.to.contain('// import attr from \'ember-data/attr\';')
.to.contain('// import { belongsTo } from \'ember-data/relationships\';')
.to.not.contain('import { belongsTo, hasMany } from \'ember-data/relationships\';');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Model.extend(')
.to.contain('comments: DS.hasMany(\'comment\')')
.to.contain('otherComments: DS.hasMany(\'comment\')')

expect(_file('tests/unit/models/post-test.js'))
.to.contain('moduleForModel(\'post\'')
.to.contain('needs: [\'model:comment\']');
}));
});

it('model with belongsTo and hasMany has both imports', function() {
var args = ['model', 'post', 'comments:has-many', 'user:belongs-to'];

return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/models/post.js'))
.to.contain('import { belongsTo, hasMany } from \'ember-data/relationships\';')
.to.contain('// import attr from \'ember-data/attr\';')
.to.not.contain('import { belongsTo } from \'ember-data/relationships\';')
.to.not.contain('import { hasMany } from \'ember-data/relationships\';');
}));
});

it('model-test', function() {
var args = ['model-test', 'foo'];

Expand Down
8 changes: 4 additions & 4 deletions node-tests/blueprints/serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('Acceptance: generate and destroy serializer blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/serializers/foo.js'))
.to.contain('import JSONAPISerializer from \'ember-data/serializers/json-api\';')
.to.contain('export default JSONAPISerializer.extend(');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.JSONAPISerializer.extend(');

expect(_file('tests/unit/serializers/foo-test.js'))
.to.contain('moduleForModel(\'foo\'');
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('Acceptance: generate and destroy serializer blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/serializers/application.js'))
.to.contain('import JSONAPISerializer from \'ember-data/serializers/json-api\';')
.to.contain('export default JSONAPISerializer.extend({');
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.JSONAPISerializer.extend({');

expect(_file('tests/unit/serializers/application-test.js'))
.to.contain('moduleForModel(\'application\'');
Expand Down
4 changes: 2 additions & 2 deletions node-tests/blueprints/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('Acceptance: generate and destroy transform blueprints', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('app/transforms/foo.js'))
.to.contain('import Transform from \'ember-data/transform\';')
.to.contain('export default Transform.extend(')
.to.contain('import DS from \'ember-data\';')
.to.contain('export default DS.Transform.extend(')
.to.contain('deserialize(serialized) {')
.to.contain('serialize(deserialized) {');

Expand Down