Skip to content

Commit c7b1ae8

Browse files
committed
Adds more tests to Model.find(), deprecates old ones
1 parent 1a5143f commit c7b1ae8

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/integration2/model-find.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ describe("Model.find()", function() {
192192
});
193193
});
194194

195+
it("should accept comparison objects", function (done) {
196+
Person.find({ age: ORM.gt(18) }, function (err, people) {
197+
should.not.exist(err);
198+
people.should.be.a("object");
199+
people.should.have.property("length", 2);
200+
Number(people[0].age).should.equal(20);
201+
Number(people[1].age).should.equal(20);
202+
203+
return done();
204+
});
205+
});
206+
195207
describe("with another Object as argument", function () {
196208
before(setup());
197209

@@ -221,6 +233,21 @@ describe("Model.find()", function() {
221233
});
222234
});
223235

236+
describe("if an offset is passed", function () {
237+
before(setup());
238+
239+
it("should use it", function (done) {
240+
Person.find({}, { offset: 1 }, "age", function (err, people) {
241+
should.not.exist(err);
242+
people.should.be.a("object");
243+
people.should.have.property("length");
244+
Number(people[0].age).should.equal(18);
245+
246+
return done();
247+
});
248+
});
249+
});
250+
224251
describe("if an order is passed", function () {
225252
before(setup());
226253

@@ -248,4 +275,27 @@ describe("Model.find()", function() {
248275
});
249276
});
250277
});
278+
279+
describe("if defined static methods", function () {
280+
before(setup());
281+
282+
it("should be rechainable", function (done) {
283+
Person.over18 = function () {
284+
return this.find({ age: ORM.gt(18) });
285+
};
286+
Person.family = function (family) {
287+
return this.find({ surname: family });
288+
};
289+
290+
Person.over18().family("Doe").run(function (err, people) {
291+
should.not.exist(err);
292+
people.should.be.a("object");
293+
people.should.have.property("length", 1);
294+
people[0].name.should.equal("Jasmine");
295+
people[0].surname.should.equal("Doe");
296+
297+
return done();
298+
});
299+
});
300+
});
251301
});

0 commit comments

Comments
 (0)