From 3e9c3ccfef8d1c6ee3e6e99a82117981fcec7d13 Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Sun, 25 Jan 2015 11:26:17 +0800 Subject: [PATCH] Add test case for sync problem --- test/fixtures/db.json | 2 +- test/scripts/model.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/fixtures/db.json b/test/fixtures/db.json index 14ab480e..fd23a0c6 100644 --- a/test/fixtures/db.json +++ b/test/fixtures/db.json @@ -1 +1 @@ -{"meta":{"version":1,"warehouse":"1.0.0-rc.4"},"models":{"Test":[{"_id":"A"},{"_id":"B"},{"_id":"C"}]}} \ No newline at end of file +{"meta":{"version":1,"warehouse":"1.0.0-rc.5"},"models":{"Test":[{"_id":"A"},{"_id":"B"},{"_id":"C"}]}} \ No newline at end of file diff --git a/test/scripts/model.js b/test/scripts/model.js index b009ec47..3c093cf9 100644 --- a/test/scripts/model.js +++ b/test/scripts/model.js @@ -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'},