Skip to content

Commit 3521e73

Browse files
committed
Fixes more test to work as primary key agnostic
1 parent 697e2d8 commit 3521e73

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

test/integration/model-find-chain.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var should = require('should');
22
var helper = require('../support/spec_helper');
33
var ORM = require('../../');
4+
var common = require('../common');
45

56
describe("Model.find() chaining", function() {
67
var db = null;
@@ -258,6 +259,17 @@ describe("Model.find() chaining", function() {
258259
});
259260
});
260261

262+
it("should return results if passed a callback as second argument", function (done) {
263+
Person.find().find({ age: 18 }, function (err, instances) {
264+
should.equal(err, null);
265+
instances.should.have.property("length", 2);
266+
267+
return done();
268+
});
269+
});
270+
271+
if (common.protocol() == "mongodb") return;
272+
261273
it("should allow sql where conditions", function (done) {
262274
Person.find({ age: 18 }).where("LOWER(surname) LIKE 'dea%'").all(function (err, items) {
263275
should.equal(err, null);
@@ -294,15 +306,6 @@ describe("Model.find() chaining", function() {
294306
});
295307
});
296308
});
297-
298-
it("should return results if passed a callback as second argument", function (done) {
299-
Person.find().find({ age: 18 }, function (err, instances) {
300-
should.equal(err, null);
301-
instances.should.have.property("length", 2);
302-
303-
return done();
304-
});
305-
});
306309
});
307310

308311
describe(".each()", function () {
@@ -428,6 +431,8 @@ describe("Model.find() chaining", function() {
428431
});
429432
});
430433

434+
if (common.protocol() == "mongodb") return;
435+
431436
describe(".hasAccessor() for hasOne associations", function () {
432437
it("should be chainable", function (done) {
433438
Person.find({ name: "John" }, function (err, John) {

test/integration/model-get.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ var helper = require('../support/spec_helper');
33
var ORM = require('../../');
44

55
describe("Model.get()", function() {
6-
var db = null;
6+
var db = null;
77
var Person = null;
8+
var John;
89

910
var setup = function (cache) {
1011
return function (done) {
@@ -14,7 +15,7 @@ describe("Model.get()", function() {
1415
cache : cache,
1516
methods: {
1617
UID: function () {
17-
return this.id;
18+
return this[Person.id];
1819
}
1920
}
2021
});
@@ -26,7 +27,11 @@ describe("Model.get()", function() {
2627
name: "John Doe"
2728
}, {
2829
name: "Jane Doe"
29-
}], done);
30+
}], function (err, people) {
31+
John = people[0];
32+
33+
return done();
34+
});
3035
});
3136
};
3237
};
@@ -47,39 +52,39 @@ describe("Model.get()", function() {
4752
before(setup(true));
4853

4954
it("should return item with id 1", function (done) {
50-
Person.get(1, function (err, John) {
55+
Person.get(John[Person.id], function (err, John) {
5156
should.equal(err, null);
5257

5358
John.should.be.a("object");
54-
John.should.have.property("id", 1);
59+
John.should.have.property(Person.id, John[Person.id]);
5560
John.should.have.property("name", "John Doe");
5661

5762
return done();
5863
});
5964
});
6065

6166
it("should have an UID method", function (done) {
62-
Person.get(1, function (err, John) {
67+
Person.get(John[Person.id], function (err, John) {
6368
should.equal(err, null);
6469

6570
John.UID.should.be.a("function");
66-
John.UID().should.equal(John.id);
71+
John.UID().should.equal(John[Person.id]);
6772

6873
return done();
6974
});
7075
});
7176

7277
describe("changing name and getting id 1 again", function () {
7378
it("should return the original object with unchanged name", function (done) {
74-
Person.get(1, function (err, John1) {
79+
Person.get(John[Person.id], function (err, John1) {
7580
should.equal(err, null);
7681

7782
John1.name = "James";
7883

79-
Person.get(1, function (err, John2) {
84+
Person.get(John[Person.id], function (err, John2) {
8085
should.equal(err, null);
8186

82-
John1.id.should.equal(John2.id);
87+
John1[Person.id].should.equal(John2[Person.id]);
8388
John2.name.should.equal("John Doe");
8489

8590
return done();
@@ -93,15 +98,15 @@ describe("Model.get()", function() {
9398
Person.settings.set("instance.cacheSaveCheck", false);
9499

95100
it("should return the same object with the changed name", function (done) {
96-
Person.get(1, function (err, John1) {
101+
Person.get(John[Person.id], function (err, John1) {
97102
should.equal(err, null);
98103

99104
John1.name = "James";
100105

101-
Person.get(1, function (err, John2) {
106+
Person.get(John[Person.id], function (err, John2) {
102107
should.equal(err, null);
103108

104-
John1.id.should.equal(John2.id);
109+
John1[Person.id].should.equal(John2[Person.id]);
105110
John2.name.should.equal("James");
106111

107112
return done();
@@ -117,12 +122,12 @@ describe("Model.get()", function() {
117122

118123
describe("fetching several times", function () {
119124
it("should return different objects", function (done) {
120-
Person.get(1, function (err, John1) {
125+
Person.get(John[Person.id], function (err, John1) {
121126
should.equal(err, null);
122-
Person.get(1, function (err, John2) {
127+
Person.get(John[Person.id], function (err, John2) {
123128
should.equal(err, null);
124129

125-
John1.id.should.equal(John2.id);
130+
John1[Person.id].should.equal(John2[Person.id]);
126131
John1.should.not.equal(John2);
127132

128133
return done();
@@ -137,14 +142,14 @@ describe("Model.get()", function() {
137142

138143
describe("fetching again after 0.2 secs", function () {
139144
it("should return same objects", function (done) {
140-
Person.get(1, function (err, John1) {
145+
Person.get(John[Person.id], function (err, John1) {
141146
should.equal(err, null);
142147

143148
setTimeout(function () {
144-
Person.get(1, function (err, John2) {
149+
Person.get(John[Person.id], function (err, John2) {
145150
should.equal(err, null);
146151

147-
John1.id.should.equal(John2.id);
152+
John1[Person.id].should.equal(John2[Person.id]);
148153
John1.should.equal(John2);
149154

150155
return done();
@@ -156,11 +161,11 @@ describe("Model.get()", function() {
156161

157162
describe("fetching again after 0.7 secs", function () {
158163
it("should return different objects", function (done) {
159-
Person.get(1, function (err, John1) {
164+
Person.get(John[Person.id], function (err, John1) {
160165
should.equal(err, null);
161166

162167
setTimeout(function () {
163-
Person.get(1, function (err, John2) {
168+
Person.get(John[Person.id], function (err, John2) {
164169
should.equal(err, null);
165170

166171
John1.should.not.equal(John2);
@@ -177,11 +182,11 @@ describe("Model.get()", function() {
177182
before(setup());
178183

179184
it("should return item with id 1 like previously", function (done) {
180-
Person.get(1, {}, function (err, John) {
185+
Person.get(John[Person.id], {}, function (err, John) {
181186
should.equal(err, null);
182187

183188
John.should.be.a("object");
184-
John.should.have.property("id", 1);
189+
John.should.have.property(Person.id, John[Person.id]);
185190
John.should.have.property("name", "John Doe");
186191

187192
return done();
@@ -194,7 +199,7 @@ describe("Model.get()", function() {
194199

195200
it("should throw", function (done) {
196201
(function () {
197-
Person.get(1);
202+
Person.get(John[Person.id]);
198203
}).should.throw();
199204

200205
return done();
@@ -218,11 +223,11 @@ describe("Model.get()", function() {
218223
before(setup(true));
219224

220225
it("should accept and try to fetch", function (done) {
221-
Person.get([ 1 ], function (err, John) {
226+
Person.get([ John[Person.id] ], function (err, John) {
222227
should.equal(err, null);
223228

224229
John.should.be.a("object");
225-
John.should.have.property("id", 1);
230+
John.should.have.property(Person.id, John[Person.id]);
226231
John.should.have.property("name", "John Doe");
227232

228233
return done();
@@ -269,7 +274,6 @@ describe("Model.get()", function() {
269274
OtherPerson.get("Jane Doe", function (err, person) {
270275
should.equal(err, null);
271276

272-
person.id.should.be.a("number");
273277
person.name.should.equal("Jane Doe");
274278

275279
return done();

test/integration/model-save.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ describe("Model.save()", function() {
5454
});
5555
John.save(function (err) {
5656
should.equal(err, null);
57-
John.id.should.be.a("number");
57+
should.exist(John[Person.id]);
5858

59-
Person.get(John.id, function (err, JohnCopy) {
59+
Person.get(John[Person.id], function (err, JohnCopy) {
6060
should.equal(err, null);
6161

62-
JohnCopy.id.should.equal(John.id);
62+
JohnCopy[Person.id].should.equal(John[Person.id]);
6363
JohnCopy.name.should.equal(John.name);
6464

6565
return done();
@@ -78,12 +78,12 @@ describe("Model.save()", function() {
7878
John.save();
7979
John.on("save", function (err) {
8080
should.equal(err, null);
81-
John.id.should.be.a("number");
81+
should.exist(John[Person.id]);
8282

83-
Person.get(John.id, function (err, JohnCopy) {
83+
Person.get(John[Person.id], function (err, JohnCopy) {
8484
should.equal(err, null);
8585

86-
JohnCopy.id.should.equal(John.id);
86+
JohnCopy[Person.id].should.equal(John[Person.id]);
8787
JohnCopy.name.should.equal(John.name);
8888

8989
return done();
@@ -101,13 +101,13 @@ describe("Model.save()", function() {
101101
});
102102
John.save({ name: "John" }, function (err) {
103103
should.equal(err, null);
104-
John.id.should.be.a("number");
104+
should.exist(John[Person.id]);
105105
John.name.should.equal("John");
106106

107-
Person.get(John.id, function (err, JohnCopy) {
107+
Person.get(John[Person.id], function (err, JohnCopy) {
108108
should.equal(err, null);
109109

110-
JohnCopy.id.should.equal(John.id);
110+
JohnCopy[Person.id].should.equal(John[Person.id]);
111111
JohnCopy.name.should.equal(John.name);
112112

113113
return done();
@@ -147,8 +147,8 @@ describe("Model.save()", function() {
147147
John.saved().should.be.true;
148148
Jane.saved().should.be.true;
149149

150-
John.id.should.be.a("number");
151-
Jane.id.should.be.a("number");
150+
should.exist(John[Person.id]);
151+
should.exist(Jane[Person.id]);
152152

153153
return done();
154154
});
@@ -170,8 +170,8 @@ describe("Model.save()", function() {
170170
John.saved().should.be.true;
171171
John.parent.saved().should.be.true;
172172

173-
John.id.should.be.a("number");
174-
John.parent.id.should.be.a("number");
173+
should.exist(John[Person.id]);
174+
should.exist(John.parent[Person.id]);
175175

176176
return done();
177177
});

0 commit comments

Comments
 (0)