Skip to content

Commit

Permalink
added passing tests for 'dirty'
Browse files Browse the repository at this point in the history
  • Loading branch information
weepy committed Mar 2, 2011
1 parent 29ffa44 commit c78fb34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/core.js
Expand Up @@ -90,9 +90,9 @@ mmodel.create = function(type, properties, store) {
return o
}

fn.merge = function(o) {
fn.merge = function(o, x) {
for(var name in properties)
if(name in o) this[name] = o[name]
if(name in o) (x || this)[name] = o[name]
return this
}

Expand All @@ -106,6 +106,7 @@ mmodel.create = function(type, properties, store) {
}

fn._saved = function(cb) {
this.merge(this, this._orig)
this.trigger("saved").complete(cb)
}

Expand Down
12 changes: 10 additions & 2 deletions test/test_memory.js
Expand Up @@ -54,15 +54,13 @@ exports.find_saved_task = function(done) {
})
}


exports.test_failed_create = function(done) {
Task.create({id: 21}, function(p) {
is.ok(p.errors.length, "task needs owner")
done()
})
}


exports.test_create = function(done) {
Task.create({user: "wibwob"}, function(p) {
is.ok(p.id)
Expand All @@ -76,3 +74,13 @@ exports.test_create = function(done) {
})
}

exports.test_dirty = function(done) {
task2 = new Task({user:"billy"})
task2.user = "johnny"
task2.dirty().should.be.ok
task2.save(function() {
task2.dirty().should.not.be.ok
done()
})
}

12 changes: 12 additions & 0 deletions test/test_redis.js
Expand Up @@ -272,6 +272,18 @@ exports.test_destroy2 = function(done) {
})
}

exports.test_dirty = function(done) {
task2 = new Task({user:"billy"})
task2.user = "johnny"
task2.dirty().should.be.ok
task2.dirty("user").should.be.ok
task2.save(function() {
task2.dirty().should.not.be.ok
task2.dirty("user").should.not.be.ok
done()
})
}


exports.cleanup = function(done) {
client.quit()
Expand Down

0 comments on commit c78fb34

Please sign in to comment.