Repository navigation
Expand file tree
/
Copy pathmodel-count.js
More file actions
79 lines (62 loc) · 1.38 KB
/
Copy pathmodel-count.js
File metadata and controls
79 lines (62 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var should = require('should');
var helper = require('../support/spec_helper');
var ORM = require('../../');
describe("Model.count()", function() {
var db = null;
var Person = null;
var setup = function () {
return function (done) {
Person = db.define("person", {
name : String
});
return helper.dropSync(Person, function () {
Person.create([{
id : 1,
name: "John Doe"
}, {
id : 2,
name: "Jane Doe"
}, {
id : 3,
name: "John Doe"
}], done);
});
};
};
before(function (done) {
helper.connect(function (connection) {
db = connection;
return done();
});
});
after(function () {
return db.close();
});
describe("without callback", function () {
before(setup());
it("should throw", function (done) {
Person.count.should.throw();
return done();
});
});
describe("without conditions", function () {
before(setup());
it("should return all items in model", function (done) {
Person.count(function (err, count) {
should.equal(err, null);
count.should.equal(3);
return done();
});
});
});
describe("with conditions", function () {
before(setup());
it("should return only matching items", function (done) {
Person.count({ name: "John Doe" }, function (err, count) {
should.equal(err, null);
count.should.equal(2);
return done();
});
});
});
});