Repository navigation
Expand file tree
/
Copy pathmodel-keys.js
More file actions
109 lines (87 loc) · 2.6 KB
/
Copy pathmodel-keys.js
File metadata and controls
109 lines (87 loc) · 2.6 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var should = require('should');
var helper = require('../support/spec_helper');
var ORM = require('../../');
describe("Model keys option", function() {
var db = null;
before(function (done) {
helper.connect(function (connection) {
db = connection;
return done();
});
});
after(function () {
return db.close();
});
describe("if model id is a property", function () {
var Person = null;
before(function (done) {
Person = db.define("person", {
uid : String,
name : String,
surname : String
}, {
id : "uid"
});
return helper.dropSync(Person, done);
});
it("should not auto increment IDs", function (done) {
Person.create({
uid : "john-doe",
name : "John",
surname : "Doe"
}, function (err, JohnDoe) {
should.equal(err, null);
JohnDoe.uid.should.equal("john-doe");
JohnDoe.should.not.have.property("id");
return done();
});
});
});
describe("if model defines several keys", function () {
var DoorAccessHistory = null;
before(function (done) {
DoorAccessHistory = db.define("door_access_history", {
year : { type: 'number', rational: false },
month : { type: 'number', rational: false },
day : { type: 'number', rational: false },
user : String,
action : [ "in", "out" ]
}, {
id : [ "year", "month", "day" ]
});
return helper.dropSync(DoorAccessHistory, function () {
DoorAccessHistory.create([
{ year: 2013, month: 7, day : 11, user : "dresende", action : "in" },
{ year: 2013, month: 7, day : 12, user : "dresende", action : "out" }
], done);
});
});
it("should make possible to get instances based on all keys", function (done) {
DoorAccessHistory.get(2013, 7, 11, function (err, HistoryItem) {
should.equal(err, null);
HistoryItem.year.should.equal(2013);
HistoryItem.month.should.equal(7);
HistoryItem.day.should.equal(11);
HistoryItem.user.should.equal("dresende");
HistoryItem.action.should.equal("in");
return done();
})
});
it("should make possible to remove instances based on all keys", function (done) {
DoorAccessHistory.get(2013, 7, 12, function (err, HistoryItem) {
should.equal(err, null);
HistoryItem.remove(function (err) {
should.equal(err, null);
DoorAccessHistory.get(2013, 7, 12, function (err) {
err.should.have.property("code", ORM.ErrorCodes.NOT_FOUND);
DoorAccessHistory.exists(2013, 7, 12, function (err, exists) {
should.equal(err, null);
exists.should.be.false;
return done();
});
});
});
})
});
});
});