Skip to content

Commit 2fef6a9

Browse files
committed
Updates some tests to avoid depending on "id" as primary key
1 parent 3436434 commit 2fef6a9

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

test/integration/hook.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe("Hook", function() {
150150
items[0].name.should.equal("Jane Doe");
151151

152152
// ensure it was really saved
153-
Person.get(items[0].id, function (err, Item) {
153+
Person.get(items[0][Person.id], function (err, Item) {
154154
should.equal(err, null);
155155
Item.name.should.equal("Jane Doe");
156156

@@ -232,7 +232,7 @@ describe("Hook", function() {
232232
return done();
233233
});
234234
});
235-
235+
236236
it("should allow modification of instance", function (done) {
237237
Person.beforeSave(function () {
238238
this.name = "Hook Worked";
@@ -263,7 +263,7 @@ describe("Hook", function() {
263263
items[0].name.should.equal("Jane Doe");
264264

265265
// ensure it was really saved
266-
Person.get(items[0].id, function (err, Item) {
266+
Person.get(items[0][Person.id], function (err, Item) {
267267
should.equal(err, null);
268268
Item.name.should.equal("Jane Doe");
269269

test/integration/instance.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ describe("Model instance", function() {
2121

2222
return helper.dropSync(Person, function () {
2323
Person.create([{
24-
id : 1,
2524
name: "Jeremy Doe"
2625
}, {
27-
id : 2,
2826
name: "John Doe"
2927
}, {
30-
id : 3,
3128
name: "Jane Doe"
3229
}], done);
3330
});
@@ -52,7 +49,8 @@ describe("Model instance", function() {
5249
it("should always return true for instances", function (done) {
5350
should.equal((new Person).isInstance, true);
5451
should.equal((Person(4)).isInstance, true);
55-
Person.get(2, function (err, item) {
52+
53+
Person.find().first(function (err, item) {
5654
should.not.exist(err);
5755
should.equal(item.isInstance, true);
5856
return done();
@@ -67,7 +65,7 @@ describe("Model instance", function() {
6765

6866
describe("#isPersisted", function () {
6967
it("should return true for persisted instances", function (done) {
70-
Person.get(2, function (err, item) {
68+
Person.find().first(function (err, item) {
7169
should.not.exist(err);
7270
should.equal(item.isPersisted(), true);
7371
return done();
@@ -93,7 +91,7 @@ describe("Model instance", function() {
9391
});
9492

9593
it("should return false for existing models", function (done) {
96-
Person.get(2, function (err, item) {
94+
Person.find().first(function (err, item) {
9795
should.not.exist(err);
9896
should.equal(item.isShell(), false);
9997
return done();

test/integration/model-create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe("Model.create()", function() {
8484
should(Array.isArray(John.pets));
8585

8686
John.pets[0].should.have.property("name", "Deco");
87-
John.pets[0].should.have.property("id");
87+
John.pets[0].should.have.property(Pet.id);
8888
John.pets[0].saved().should.be.true;
8989

9090
return done();
@@ -103,7 +103,7 @@ describe("Model.create()", function() {
103103
should(Array.isArray(John.pets));
104104

105105
John.pets[0].should.have.property("name", "Deco");
106-
John.pets[0].should.have.property("id");
106+
John.pets[0].should.have.property(Pet.id);
107107
John.pets[0].saved().should.be.true;
108108

109109
return done();

test/integration/model-exists.js

Lines changed: 19 additions & 9 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.exists()", function() {
6-
var db = null;
6+
var db = null;
77
var Person = null;
8+
var good_id, bad_id;
89

910
var setup = function () {
1011
return function (done) {
@@ -14,15 +15,24 @@ describe("Model.exists()", function() {
1415

1516
return helper.dropSync(Person, function () {
1617
Person.create([{
17-
id : 1,
1818
name: "Jeremy Doe"
1919
}, {
20-
id : 2,
2120
name: "John Doe"
2221
}, {
23-
id : 3,
2422
name: "Jane Doe"
25-
}], done);
23+
}], function (err, people) {
24+
good_id = people[0][Person.id];
25+
26+
if (typeof good_id == "number") {
27+
// numeric ID
28+
bad_id = good_id * 100;
29+
} else {
30+
// string ID, keep same length..
31+
bad_id = good_id.split('').reverse().join('');
32+
}
33+
34+
return done();
35+
});
2636
});
2737
};
2838
};
@@ -53,7 +63,7 @@ describe("Model.exists()", function() {
5363
before(setup());
5464

5565
it("should return true if found", function (done) {
56-
Person.exists(2, function (err, exists) {
66+
Person.exists(good_id, function (err, exists) {
5767
should.equal(err, null);
5868

5969
exists.should.be.true;
@@ -63,7 +73,7 @@ describe("Model.exists()", function() {
6373
});
6474

6575
it("should return false if not found", function (done) {
66-
Person.exists(4, function (err, exists) {
76+
Person.exists(bad_id, function (err, exists) {
6777
should.equal(err, null);
6878

6979
exists.should.be.false;
@@ -77,7 +87,7 @@ describe("Model.exists()", function() {
7787
before(setup());
7888

7989
it("should return true if found", function (done) {
80-
Person.exists([ 2 ], function (err, exists) {
90+
Person.exists([ good_id ], function (err, exists) {
8191
should.equal(err, null);
8292

8393
exists.should.be.true;
@@ -87,7 +97,7 @@ describe("Model.exists()", function() {
8797
});
8898

8999
it("should return false if not found", function (done) {
90-
Person.exists([ 4 ], function (err, exists) {
100+
Person.exists([ bad_id ], function (err, exists) {
91101
should.equal(err, null);
92102

93103
exists.should.be.false;

0 commit comments

Comments
 (0)