diff --git a/interfaces/semantic/support/fixtures/crud.fixture.js b/interfaces/semantic/support/fixtures/crud.fixture.js index d50c090..459773f 100644 --- a/interfaces/semantic/support/fixtures/crud.fixture.js +++ b/interfaces/semantic/support/fixtures/crud.fixture.js @@ -3,6 +3,7 @@ */ var Waterline = require('waterline'); +var _ = require('lodash'); module.exports = Waterline.Collection.extend({ @@ -39,7 +40,13 @@ module.exports = Waterline.Collection.extend({ obj: 'json', fullName: function() { return this.first_name + ' ' + this.last_name; - } + }, + }, + + afterUpdate: function (values, cb) { + var afterUpdateValues = _.cloneDeep(values); + values.afterUpdateValues = afterUpdateValues; + cb(); } }); diff --git a/interfaces/semantic/types/array.type.js b/interfaces/semantic/types/array.type.js index 4c7635a..f86029f 100644 --- a/interfaces/semantic/types/array.type.js +++ b/interfaces/semantic/types/array.type.js @@ -9,16 +9,39 @@ describe('Semantic Interface', function() { ///////////////////////////////////////////////////// // TEST METHODS //////////////////////////////////////////////////// + + function assertArrayMatches(actual, expected){ + assert(Array.isArray(actual)); + assert.strictEqual(actual.length, expected.length); + assert.deepEqual(actual, expected); + } + + var id; it('should store proper array value', function(done) { - Semantic.User.create({ list: [0,1,2,3] }, function(err, createdRecord) { + var original = [0,1,2,3]; + Semantic.User.create({ list: original }, function(err, createdRecord) { + id = createdRecord.id; assert(!err); - assert(Array.isArray(createdRecord.list)); - assert.strictEqual(createdRecord.list.length, 4); + assertArrayMatches(createdRecord.list, original); Semantic.User.findOne({id: createdRecord.id}, function (err, record) { assert(!err); - assert(Array.isArray(record.list)); - assert.strictEqual(record.list.length, 4); + assertArrayMatches(record.list, original); + done(); + }); + }); + }); + + it('should update proper array value', function(done) { + var original = [0,1,2]; + Semantic.User.update(id, { list: original }, function(err, updatedRecords) { + var updatedRecord = updatedRecords[0]; + assert(!err); + assertArrayMatches(updatedRecord.list, original); + assertArrayMatches(updatedRecord.afterUpdateValues.list, original); + Semantic.User.findOne({id: updatedRecord.id}, function (err, record) { + assert(!err); + assertArrayMatches(record.list, original); done(); }); });