Skip to content

Commit

Permalink
fix(collection): allow changed() function to work properly with colle…
Browse files Browse the repository at this point in the history
…ction properties of type object.
  • Loading branch information
andreialecu authored and ericfong committed Jan 10, 2015
1 parent ab89ec3 commit 46f518d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/resources/collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Collection.prototype.save = function (ctx, fn) {

domain.changed = function (property) {
if(domain.data.hasOwnProperty(property)) {
if(domain.previous && domain.previous[property] === domain.data[property]) {
if(domain.previous && _.isEqual(domain.previous[property], domain.data[property])) {
return false;
}

Expand Down
19 changes: 19 additions & 0 deletions test-app/public/test/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,25 @@ describe('Collection', function() {
});
});

it('should not return true when a value of type object has not changed', function(done) {
dpd.changed.post({name: 'irrelevant', data: { 'key': '$NO_CHANGE'} }, function (c) {
dpd.changed.put(c.id, { data: { 'key': '$NO_CHANGE'} }, function (c) {
expect(c.data.changed).to.not.exist;
done();
});
});
});

it('should detect when a value of type object has changed', function(done) {
dpd.changed.post({name: 'irrelevant', data: { 'key': '$NO_CHANGE'} }, function (c) {
dpd.changed.put(c.id, { data: { 'key': '$CHANGED'} }, function (c) {
expect(c.data.key).to.equal("$CHANGED");
expect(c.data.changed).to.be.true;
done();
});
});
});

afterEach(function (done) {
this.timeout(10000);
cleanCollection(dpd.changed, done);
Expand Down
8 changes: 8 additions & 0 deletions test-app/resources/changed/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"required": false,
"id": "name",
"order": 0
},
"data": {
"name": "data",
"type": "object",
"typeLabel": "object",
"required": false,
"id": "data",
"order": 1
}
}
}
4 changes: 4 additions & 0 deletions test-app/resources/changed/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ if(this.name === '$NO_CHANGE') {
if(changed('name')) {
this.name = 'saw name change';
}
}

if (changed('data')) {
this.data.changed = true;
}

0 comments on commit 46f518d

Please sign in to comment.