mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-06-19 06:36:47 +08:00
fixed #107, changed() returning incorrect true when values were equal
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# deployd v0.6.9
|
||||
# deployd v0.6.10
|
||||
|
||||
[](http://travis-ci.org/deployd/deployd)
|
||||
|
||||
|
||||
@@ -440,7 +440,13 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
};
|
||||
|
||||
domain.changed = function (property) {
|
||||
if(domain.data.hasOwnProperty(property)) return true;
|
||||
if(domain.data.hasOwnProperty(property)) {
|
||||
if(domain.previous && domain.previous[property] === domain.data[property]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -466,7 +472,8 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
prev[key] = obj[key];
|
||||
obj[key] = item[key];
|
||||
});
|
||||
|
||||
|
||||
prev.id = id;
|
||||
item = obj;
|
||||
domain['this'] = item;
|
||||
domain.data = item;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"author": "Ritchie Martori",
|
||||
"name": "deployd",
|
||||
"version": "0.6.9",
|
||||
"version": "0.6.10",
|
||||
"description": "the simplest way to build realtime APIs for web and mobile apps",
|
||||
"repository": {
|
||||
"url": "git://github.com/deployd/deployd.git"
|
||||
|
||||
@@ -871,6 +871,17 @@ describe('Collection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return true when a value has not changed', function(done) {
|
||||
dpd.changed.post({name: '$NO_CHANGE'}, function (c) {
|
||||
dpd.changed.put(c.id, {name: '$NO_CHANGE'}, function (c) {
|
||||
if(c.name != '$NO_CHANGE') {
|
||||
throw new Error('incorrect name change');
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
this.timeout(10000);
|
||||
cleanCollection(dpd.changed, done);
|
||||
|
||||
5
test-app/resources/changed/put.js
Normal file
5
test-app/resources/changed/put.js
Normal file
@@ -0,0 +1,5 @@
|
||||
if(this.name === '$NO_CHANGE') {
|
||||
if(changed('name')) {
|
||||
this.name = 'saw name change';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user