Skip to content

Commit

Permalink
Add test case for sync problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jan 25, 2015
1 parent a30ff54 commit 3e9c3cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/fixtures/db.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"meta":{"version":1,"warehouse":"1.0.0-rc.4"},"models":{"Test":[{"_id":"A"},{"_id":"B"},{"_id":"C"}]}}
{"meta":{"version":1,"warehouse":"1.0.0-rc.5"},"models":{"Test":[{"_id":"A"},{"_id":"B"},{"_id":"C"}]}}
20 changes: 20 additions & 0 deletions test/scripts/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ describe('Model', function(){
});
});

it('insert() - sync problem', function(callback){
var db = new Database();
var testSchema = new Schema();

testSchema.pre('save', function(data){
var item = Test.findOne({id: data.id});
if (item) throw new Error('ID "' + data.id + '" has been used.');
});

var Test = db.model('Test', testSchema);

Test.insert([
{id: 1},
{id: 1}
]).catch(function(err){
err.should.have.property('message', 'ID "1" has been used.');
callback();
});
});

it('save() - insert', function(){
return User.save({
name: {first: 'John', last: 'Doe'},
Expand Down

0 comments on commit 3e9c3cc

Please sign in to comment.