fixed #107, changed() returning incorrect true when values were equal

This commit is contained in:
Ritchie Martori
2012-12-04 09:39:36 -08:00
parent fc4ae32ff8
commit b545a8bf1f
5 changed files with 27 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
# deployd v0.6.9
# deployd v0.6.10
[![Build Status](https://secure.travis-ci.org/deployd/deployd.png)](http://travis-ci.org/deployd/deployd)

View File

@@ -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;

View File

@@ -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"

View File

@@ -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);

View File

@@ -0,0 +1,5 @@
if(this.name === '$NO_CHANGE') {
if(changed('name')) {
this.name = 'saw name change';
}
}