Skip to content

Commit 289ec1a

Browse files
committed
Moves hasMany extra properties tests to new framework
1 parent 4a9eb65 commit 289ec1a

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

test/integration/test-association-hasmany-add-extra.js renamed to test/integration/deprecated/test-association-hasmany-add-extra.js

File renamed without changes.

test/integration/test-association-hasmany-extra-find.js renamed to test/integration/deprecated/test-association-hasmany-extra-find.js

File renamed without changes.

test/integration/test-association-hasmany-extra.js renamed to test/integration/deprecated/test-association-hasmany-extra.js

File renamed without changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
var should = require('should');
2+
var helper = require('../support/spec_helper');
3+
var ORM = require('../../');
4+
5+
describe("hasMany extra properties", function() {
6+
var db = null;
7+
var Person = null;
8+
var Pet = null;
9+
10+
var setup = function (opts) {
11+
opts = opts || {};
12+
return function (done) {
13+
db.settings.set('instance.cache', false);
14+
15+
Person = db.define('person', {
16+
name : String,
17+
}, opts);
18+
Pet = db.define('pet', {
19+
name : String
20+
});
21+
Person.hasMany('pets', Pet, {
22+
since : Date
23+
});
24+
25+
return helper.dropSync([ Person, Pet ], done);
26+
};
27+
};
28+
29+
before(function(done) {
30+
helper.connect(function (connection) {
31+
db = connection;
32+
done();
33+
});
34+
});
35+
36+
describe("if passed to addAccessor", function () {
37+
before(setup());
38+
39+
it("should be added to association", function (done) {
40+
Person.create([{
41+
name : "John"
42+
}], function (err, people) {
43+
Pet.create([{
44+
name : "Deco"
45+
}, {
46+
name : "Mutt"
47+
}], function (err, pets) {
48+
people[0].addPets(pets, { since : new Date() }, function (err) {
49+
should.equal(err, null);
50+
51+
Person.find({ name: "John" }, { autoFetch : true }).first(function (err, John) {
52+
should.equal(err, null);
53+
54+
John.should.have.property("pets");
55+
should(Array.isArray(pets));
56+
57+
John.pets.length.should.equal(2);
58+
59+
John.pets[0].should.have.property("id");
60+
John.pets[0].should.have.property("name");
61+
John.pets[0].should.have.property("extra");
62+
John.pets[0].extra.should.be.a("object");
63+
John.pets[0].extra.should.have.property("since");
64+
should(John.pets[0].extra.since instanceof Date);
65+
66+
return done();
67+
});
68+
});
69+
});
70+
});
71+
});
72+
});
73+
});

0 commit comments

Comments
 (0)