Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event related tests for previousAttributes()
- Loading branch information
1 parent
54554b7
commit 3cdfa6e
Showing
1 changed file
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1583,6 +1583,17 @@ module.exports = function(bookshelf) { | |
}); | ||
}); | ||
|
||
it("returns the current model's attributes if no attributes were changed after save", function() { | ||
return new Models.Site({id: 1}) | ||
.fetch() | ||
.then(function(site) { | ||
return site.save({name: site.get('name')}); | ||
}) | ||
.then(function(site) { | ||
expect(site.previousAttributes()).to.eql(site.attributes); | ||
}); | ||
}); | ||
|
||
it("returns the model's original attributes if the model has changed", function() { | ||
return new Models.Site({id: 1}).fetch().then(function(site) { | ||
var originalAttributes = _.clone(site.attributes); | ||
|
@@ -1610,6 +1621,38 @@ module.exports = function(bookshelf) { | |
}); | ||
}); | ||
|
||
it("returns the model's original attributes after save on the 'updated' event", function(done) { | ||
var originalAttributes; | ||
var siteModel = new Models.Site({id: 1}); | ||
|
||
siteModel.on('updated', function(site) { | ||
expect(site.previousAttributes()).to.eql(originalAttributes); | ||
expect(site.previousAttributes()).to.not.eql(site.attributes); | ||
|
||
new Models.Site({id: 1}).save({name: originalAttributes.name}).finally(() => done()); | ||
}); | ||
|
||
siteModel.fetch().then(function(site) { | ||
originalAttributes = _.clone(site.attributes); | ||
return siteModel.save({name: 'Blah'}); | ||
}); | ||
}); | ||
|
||
it("returns the current model's attributes after save without changes on the 'updated' event", function(done) { | ||
var originalAttributes; | ||
var siteModel = new Models.Site({id: 1}); | ||
|
||
siteModel.on('updated', function(site) { | ||
expect(site.previousAttributes()).to.eql(site.attributes); | ||
new Models.Site({id: 1}).save({name: originalAttributes.name}).finally(() => done()); | ||
}); | ||
|
||
siteModel.fetch().then(function(site) { | ||
originalAttributes = _.clone(site.attributes); | ||
return siteModel.save({name: site.get('name')}); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ricardograca
Author
Member
|
||
}); | ||
}); | ||
|
||
it("returns the model's original attributes after destroy", function() { | ||
var originalAttributes; | ||
|
||
|
Maybe it makes a difference if you do
?