diff --git a/package.json b/package.json index 5d63388..555a1b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waterline-orientdb", - "version": "0.10.41", + "version": "0.10.42", "description": "OrientDB adapter for Waterline / Sails.js ORM", "main": "./lib/adapter.js", "scripts": { diff --git a/test/integration-orientdb/tests/associations/manyThrough.update.js b/test/integration-orientdb/tests/associations/manyThrough.update.js new file mode 100644 index 0000000..4638932 --- /dev/null +++ b/test/integration-orientdb/tests/associations/manyThrough.update.js @@ -0,0 +1,62 @@ +var assert = require('assert'), + _ = require('lodash'), + utils = require('../../../../lib/utils'); + +describe('Association Interface', function() { + + describe('n:m through association :: .update', function() { + + ///////////////////////////////////////////////////// + // TEST SETUP + //////////////////////////////////////////////////// + + var stadiumRecord, teamRecord; + + before(function(done) { + Associations.Stadium.create({ name: 'update stadium' }, function(err, stadium) { + if(err) return done(err); + stadiumRecord = stadium; + Associations.Team.create({ name: 'populate team', mascot: 'elephant' }, function(err, team) { + if(err) return done(err); + teamRecord = team; + stadiumRecord.teams.add(teamRecord.id); + stadiumRecord.save(function(err){ + assert(!err, err); + done(); + }); + }); + }); + }); + + ///////////////////////////////////////////////////// + // TEST METHODS + //////////////////////////////////////////////////// + describe('update operations should not impact associations', function() { + + it('update record without populate with association using collection.update()', function(done) { + Associations.Stadium.findOne(stadiumRecord.id) + .then(function(stadium){ + assert.equal(stadium.teams.length, 0); + assert.equal(stadium.name, 'update stadium'); + + //var updatedStadium = _.merge(stadium, { name: 'update stadium updated' }); + return Associations.Stadium.update(stadiumRecord.id, { name: 'update stadium updated' }); + }) + .then(function(){ + return Associations.Stadium.findOne(stadiumRecord.id) + .populate('teams'); + }) + .then(function(updatedStadium){ + assert.equal(updatedStadium.name, 'update stadium updated'); + assert.equal(updatedStadium.teams.length, 1); + done(); + }) + .catch(done); + }); + + }); + }); +}); + + +