Repository navigation
Expand file tree
/
Copy pathsettings.js
More file actions
139 lines (110 loc) · 3.33 KB
/
Copy pathsettings.js
File metadata and controls
139 lines (110 loc) · 3.33 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var should = require('should');
var helper = require('../support/spec_helper');
var ORM = require('../../');
var Settings = ORM.Settings;
describe("Settings", function () {
describe("changed on connection instance", function() {
it("should not change global defaults", function (done) {
var setting = 'instance.returnAllErrors';
var defaultValue = ORM.settings.get(setting);
helper.connect(function (db) {
db.settings.set(setting, !defaultValue);
db.close();
helper.connect(function (db) {
db.settings.get(setting).should.equal(defaultValue);
db.close();
done();
});
});
});
});
describe("#get", function () {
var settings, returned;
beforeEach(function () {
settings = new Settings.Container({ a: [1,2] });
returned = null;
});
it("should clone everything it returns", function () {
returned = settings.get('*');
returned.a = 123;
settings.get('a').should.eql([1,2]);
});
it("should deep clone everything it returns", function () {
returned = settings.get('*');
returned.a.push(3);
settings.get('a').should.eql([1,2]);
});
});
describe("manipulating:", function () {
var testFunction = function testFunction() {
return "test";
};
var settings = new Settings.Container({});
describe("some.sub.object = 123.45", function () {
before(function (done) {
settings.set("some.sub.object", 123.45);
return done();
});
it("should be 123.45", function (done) {
settings.get("some.sub.object").should.equal(123.45);
return done();
});
});
describe("some....object = testFunction", function () {
before(function (done) {
settings.set("some....object", testFunction);
return done();
});
it("should be testFunction", function (done) {
settings.get("some....object").should.equal(testFunction);
return done();
});
});
describe("not setting some.unknown.object", function () {
it("should be undefined", function (done) {
should.equal(settings.get("some.unknown.object"), undefined);
return done();
});
});
describe("unsetting some.sub.object", function () {
before(function (done) {
settings.unset("some.sub.object");
return done();
});
it("should be undefined", function (done) {
should.equal(settings.get("some.sub.object"), undefined);
return done();
});
});
describe("unsetting some....object", function () {
before(function (done) {
settings.unset("some....object");
return done();
});
it("should be undefined", function (done) {
should.equal(settings.get("some....object"), undefined);
return done();
});
});
describe("unsetting some.*", function () {
before(function (done) {
settings.unset("some.*");
return done();
});
it("should return undefined for any 'some' sub-element", function (done) {
should.equal(settings.get("some.other.stuff"), undefined);
return done();
});
it("should return an empty object for some.*", function (done) {
settings.get("some.*").should.be.a("object");
Object.keys(settings.get("some.*")).should.have.lengthOf(0);
return done();
});
it("should return an empty object for some", function (done) {
settings.get("some").should.be.a("object");
Object.keys(settings.get("some")).should.have.lengthOf(0);
return done();
});
});
});
});