-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from kurenai-ryu/master
Fix named associations endpoints
- Loading branch information
Showing
6 changed files
with
65 additions
and
16 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
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,48 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect, | ||
rest = require('../../lib'), | ||
test = require('../support'); | ||
|
||
describe('Associations(named sub-resources)', function() { | ||
describe('without using "as" to name an association', function() { | ||
it('should name the sub-resources according to the model name', function(done) { | ||
var Person = test.db.define('person', { name: { type: test.Sequelize.STRING } }, { underscored: true }), | ||
Course = test.db.define('course', { name: { type: test.Sequelize.STRING } }, { underscored: true }); | ||
Course.hasMany(Person); | ||
Course.hasOne(Person); | ||
rest.initialize({ | ||
app: test.app, | ||
sequelize: test.Sequelize | ||
}); | ||
var resource = rest.resource({model: Course, | ||
endpoints: ['/courses', '/courses/:id'], | ||
associations: true}); | ||
expect(resource).to.not.have.property('students'); | ||
expect(resource).to.not.have.property('teacher'); | ||
expect(resource).to.have.property('people'); | ||
expect(resource).to.have.property('person'); | ||
done(); | ||
}); | ||
}); | ||
describe('using "as" to name an association', function() { | ||
it('should name the sub-resources using the name provided by "as"', function(done) { | ||
var Person = test.db.define('person', { name: { type: test.Sequelize.STRING } }, { underscored: true }), | ||
Course = test.db.define('course', { name: { type: test.Sequelize.STRING } }, { underscored: true }); | ||
Course.hasMany(Person, { as: 'students' }); | ||
Course.hasOne(Person, { as: 'teacher' }); | ||
rest.initialize({ | ||
app: test.app, | ||
sequelize: test.Sequelize | ||
}); | ||
var resource = rest.resource({model: Course, | ||
endpoints: ['/courses', '/courses/:id'], | ||
associations: true}); | ||
expect(resource).to.have.property('students'); | ||
expect(resource).to.have.property('teacher'); | ||
expect(resource).to.not.have.property('people'); | ||
expect(resource).to.not.have.property('person'); | ||
done(); | ||
}); | ||
}); | ||
}); |