-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4986 - gabrielgrant:fix-model-blueprint, r=stefanpenner
fix model relationship name generation It is not currently possible to generate a model with a relationship named differently from the model's name ([despite the help indicating it should be](https://github.com/ember-cli/ember-cli/blob/master/blueprints/model/HELP.md)) This patch brings the code's behavior in line with the docs. The blueprint part of this patch will be obsoleted if #4909 lands, so I've also PRed the changes to the blueprint in ED: emberjs/data#3885 (the arg-parsing-fix part of this patch is still needed to pass a distinct name, though)
- Loading branch information
Showing
3 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; | ||
|
||
var Blueprint = require('../../../lib/models/blueprint'); | ||
var expect = require('chai').expect; | ||
|
||
var EOL = require('os').EOL; | ||
|
||
function makeOpts(opts){ | ||
return {entity: {options: opts}}; | ||
} | ||
|
||
describe('blueprint - model', function(){ | ||
describe('entityName', function(){ | ||
it('generates individual un-typed properties', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
name: '' | ||
})); | ||
console.log(out); | ||
expect(out.attrs).to.equal('name: DS.attr()'); | ||
expect(out.needs).to.equal(' needs: []'); | ||
}); | ||
|
||
it('generates individual typed properties', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
name: 'type' | ||
})); | ||
expect(out.attrs).to.equal('name: DS.attr(\'type\')'); | ||
expect(out.needs).to.equal(' needs: []'); | ||
}) | ||
|
||
it('accepts camel-cased properties', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
aliceTheCamel: 'humps' | ||
})); | ||
console.log(out); | ||
expect(out.attrs).to.equal('aliceTheCamel: DS.attr(\'humps\')'); | ||
expect(out.needs).to.equal(' needs: []'); | ||
}); | ||
|
||
it('accepts dasheriezed properties', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
'dash-to-the-future': 'time-machine' | ||
})); | ||
expect(out.attrs).to.equal('dashToTheFuture: DS.attr(\'time-machine\')'); | ||
expect(out.needs).to.equal(' needs: []'); | ||
}) | ||
|
||
it('accepts underscored properties', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
six_feet_underscored: '' | ||
})); | ||
console.log(out); | ||
expect(out.attrs).to.equal('sixFeetUnderscored: DS.attr()'); | ||
expect(out.needs).to.equal(' needs: []'); | ||
}); | ||
|
||
it('generates multiple properties', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
one: 'Fish', | ||
two: 'Fish' | ||
})); | ||
console.log(out); | ||
expect(out.attrs).to.equal('one: DS.attr(\'fish\'),' + EOL + ' two: DS.attr(\'fish\')'); | ||
expect(out.needs).to.equal(' needs: []'); | ||
}); | ||
|
||
it('links model by name if type is undefined', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
virtue: 'belongs-to', | ||
vices: 'has-many' | ||
})); | ||
console.log(out); | ||
expect(out.attrs).to.equal('virtue: DS.belongsTo(\'virtue\'),' + EOL + ' vices: DS.hasMany(\'vice\')'); | ||
expect(out.needs).to.equal(' needs: [\'model:virtue\', \'model:vice\']'); | ||
}); | ||
|
||
it('links supplied model name (singularized) if defined', function(){ | ||
var blueprint = Blueprint.lookup('model'); | ||
|
||
var out = blueprint.locals(makeOpts({ | ||
tomster: 'belongs-to:leah', | ||
irlTom: 'has-many:twitterRants' | ||
})); | ||
console.log(out); | ||
expect(out.attrs).to.equal('tomster: DS.belongsTo(\'leah\'),' + EOL + ' irlToms: DS.hasMany(\'twitter-rant\')'); | ||
expect(out.needs).to.equal(' needs: [\'model:leah\', \'model:twitter-rant\']'); | ||
}); | ||
|
||
}); | ||
}); |