不要怂,就是干,撸起袖子干!

Commit 0ce92678 by Sascha Depold

added tests for reloading associations

1 parent f178b9ef
Showing with 34 additions and 1 deletions
......@@ -216,7 +216,7 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
});
});
describe('refresh', function () {
describe('reload', function () {
it("should return a reference to the same DAO instead of creating a new one", function (done) {
this.User.create({ username: 'John Doe' }).done(function (err, originalUser) {
......@@ -271,6 +271,39 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
}, 1000)
})
})
it("should update the associations as well", function(done) {
var Book = this.sequelize.define('Book', { title: Helpers.Sequelize.STRING })
, Page = this.sequelize.define('Page', { content: Helpers.Sequelize.TEXT })
Book.hasMany(Page)
Page.belongsTo(Book)
this.sequelize.sync({ force: true }).success(function() {
Book.create({ title: 'A very old book' }).success(function(book) {
Page.create({ content: 'om nom nom' }).success(function(page) {
book.setPages([ page ]).success(function() {
Book.find({
where: (dialect === 'postgres' ? '"Books"."id"=' : '`Books`.`id`=') + book.id,
include: [Page]
}).success(function(leBook) {
page.updateAttributes({ content: 'something totally different' }).success(function(page) {
expect(leBook.pages[0].content).toEqual('om nom nom')
expect(page.content).toEqual('something totally different')
leBook.reload().success(function(leBook) {
expect(leBook.pages[0].content).toEqual('something totally different')
expect(page.content).toEqual('something totally different')
done()
})
})
})
})
})
}.bind(this))
}.bind(this))
})
});
describe('default values', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!