From fe7d1484f4847dafadceec9b6f043e7d8f67840d Mon Sep 17 00:00:00 2001 From: 0ff Date: Fri, 5 Jun 2015 12:26:36 +0200 Subject: [PATCH 1/2] add breaking test for `upsert` There is a quirk in this mixin: if you `upsert` a model (i.e. you just know the id and properties, but you don't want to `find` it first) the createdAt-Timestamp is updated, too. This must not happen, of course. I fear it's related to the lb-ds-juggler's implementation of default values. Can you think of a solution besides querying for the model everytime? --- test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test.js b/test.js index fc093c4..0417ac6 100644 --- a/test.js +++ b/test.js @@ -64,6 +64,21 @@ test('loopback datasource timestamps', function(tap) { }); }); }); + + t.test('should not change on upsert', function(tt) { + var createdAt; + Book.destroyAll(function() { + Book.create({name:'book 1', type:'fiction'}, function(err, book) { + tt.error(err); + tt.ok(book.createdAt); + Book.upsert({id: book.id, name:'book inf'}, function(err, b) { + tt.error(err); + tt.equal(book.createdAt, b.createdAt); + tt.end(); + }); + }); + }); + }); t.test('should not change with bulk updates', function(tt) { var createdAt; From 3ec7058d598add804ff6754becc6d4cf582979ff Mon Sep 17 00:00:00 2001 From: 0ff Date: Fri, 5 Jun 2015 12:29:07 +0200 Subject: [PATCH 2/2] Conform to the style rules. --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 0417ac6..0377d84 100644 --- a/test.js +++ b/test.js @@ -64,7 +64,7 @@ test('loopback datasource timestamps', function(tap) { }); }); }); - + t.test('should not change on upsert', function(tt) { var createdAt; Book.destroyAll(function() {