Skip to content

Commit

Permalink
Prepare v0.10.42
Browse files Browse the repository at this point in the history
Add many-to-many update test
  • Loading branch information
dmarcelino committed Mar 24, 2015
1 parent 8fafca0 commit aede793
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
62 changes: 62 additions & 0 deletions test/integration-orientdb/tests/associations/manyThrough.update.js
Original file line number Diff line number Diff line change
@@ -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);
});

});
});
});



0 comments on commit aede793

Please sign in to comment.