mongoid_monkey 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,262 +1,262 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe 'Mongoid::Persistable::Pushable' do
6
-
7
- describe "#add_to_set" do
8
-
9
- context "when the document is a root document" do
10
-
11
- shared_examples_for "a unique pushable root document" do
12
-
13
- it "adds single values" do
14
- expect(person.aliases).to eq([ 1, 2, 4 ])
15
- end
16
-
17
- it "does not add duplicate values" do
18
- expect(person.array).to eq([ 4, 5 ])
19
- end
20
-
21
- it "sets absent values" do
22
- expect(person.test_array).to eq([ 1 ])
23
- end
24
-
25
- it "returns self objet" do
26
- expect(add).to eq(person)
27
- end
28
-
29
- it "resets the dirty changes" do
30
- expect(person).to_not be_changed
31
- end
32
-
33
- it "persists single adds" do
34
- expect(person.reload.aliases).to eq([ 1, 2, 4 ])
35
- end
36
-
37
- it "persists absent values" do
38
- expect(person.reload.test_array).to eq([ 1 ])
39
- end
40
-
41
- it "flattens only 1 level" do
42
- expect(person.reload.arrays).to eq([[ 7, 8 ]])
43
- end
44
- end
45
-
46
- let(:person) do
47
- Person.create(aliases: [ 1, 2 ], array: [ 4, 5 ])
48
- end
49
-
50
- context "when provided string fields" do
51
-
52
- let!(:add) do
53
- person.add_to_set("aliases" => 4, "array" => [4, 5], "test_array" => 1, "arrays" => [[ 7, 8 ]])
54
- end
55
-
56
- it_behaves_like "a unique pushable root document"
57
- end
58
-
59
- context "when provided symbol fields" do
60
-
61
- let!(:add) do
62
- person.add_to_set(aliases: 4, array: [4, 5], test_array: 1, arrays: [[ 7, 8 ]])
63
- end
64
-
65
- it_behaves_like "a unique pushable root document"
66
- end
67
- end
68
-
69
- context "when the document is embedded" do
70
-
71
- shared_examples_for "a unique pushable embedded document" do
72
-
73
- it "adds single values" do
74
- expect(address.services).to eq([ 1, 4 ])
75
- end
76
-
77
- it "does not add duplicate values" do
78
- expect(address.a).to eq([ 4, 5 ])
79
- end
80
-
81
- it "sets absent values" do
82
- expect(address.test).to eq([ 1 ])
83
- end
84
-
85
- it "returns self object" do
86
- expect(add).to eq(address)
87
- end
88
-
89
- it "resets the dirty changes" do
90
- expect(address).to_not be_changed
91
- end
92
-
93
- it "persists single adds" do
94
- expect(address.reload.services).to eq([ 1, 4 ])
95
- end
96
-
97
- it "persists absent values" do
98
- expect(address.reload.test).to eq([ 1 ])
99
- end
100
- end
101
-
102
- let(:person) do
103
- Person.create
104
- end
105
-
106
- let(:address) do
107
- person.addresses.create(street: "t", services: [ 1 ], a: [ 4, 5 ])
108
- end
109
-
110
- context "when provided string fields" do
111
-
112
- let!(:add) do
113
- address.add_to_set("services" => 4, "a" => 5, "test" => 1)
114
- end
115
-
116
- it_behaves_like "a unique pushable embedded document"
117
- end
118
-
119
- context "when provided symbol fields" do
120
-
121
- let!(:add) do
122
- address.add_to_set(services: 4, a: 5, test: 1)
123
- end
124
-
125
- it_behaves_like "a unique pushable embedded document"
126
- end
127
- end
128
- end
129
-
130
- describe "#push" do
131
-
132
- context "when the document is a root document" do
133
-
134
- shared_examples_for "a pushable root document" do
135
-
136
- it "pushes single values" do
137
- expect(person.aliases).to eq([ 1, 2, 3, 4 ])
138
- end
139
-
140
- it "pushes multiple values" do
141
- expect(person.array).to eq([ 4, 5, 6, 7, 8 ])
142
- end
143
-
144
- it "sets absent values" do
145
- expect(person.test_array).to eq([ 1 ])
146
- end
147
-
148
- it "returns self object" do
149
- expect(push).to eq(person)
150
- end
151
-
152
- it "resets the dirty changes" do
153
- expect(person).to_not be_changed
154
- end
155
-
156
- it "persists single pushes" do
157
- expect(person.reload.aliases).to eq([ 1, 2, 3, 4 ])
158
- end
159
-
160
- it "persists multiple pushes" do
161
- expect(person.reload.array).to eq([ 4, 5, 6, 7, 8 ])
162
- end
163
-
164
- it "persists absent values" do
165
- expect(person.reload.test_array).to eq([ 1 ])
166
- end
167
-
168
- it "flattens only 1 level" do
169
- expect(person.reload.arrays).to eq([[ 7, 8 ]])
170
- end
171
- end
172
-
173
- let(:person) do
174
- Person.create(aliases: [ 1, 2, 3 ], array: [ 4, 5, 6 ])
175
- end
176
-
177
- context "when provided string fields" do
178
-
179
- let!(:push) do
180
- person.push("aliases" => 4, "array" => [ 7, 8 ], "test_array" => 1, "arrays" => [[ 7, 8 ]])
181
- end
182
-
183
- it_behaves_like "a pushable root document"
184
- end
185
-
186
- context "when provided symbol fields" do
187
-
188
- let!(:push) do
189
- person.push(aliases: 4, array: [ 7, 8 ], test_array: 1, arrays: [[ 7, 8 ]])
190
- end
191
-
192
- it_behaves_like "a pushable root document"
193
- end
194
- end
195
-
196
- context "when the document is embedded" do
197
-
198
- shared_examples_for "a pushable embedded document" do
199
-
200
- it "pushes single values" do
201
- expect(address.services).to eq([ 1, 4 ])
202
- end
203
-
204
- it "pushes multiple values" do
205
- expect(address.a).to eq([ 4, 5, 6, 7 ])
206
- end
207
-
208
- it "sets absent values" do
209
- expect(address.test).to eq([ 1 ])
210
- end
211
-
212
- it "returns self object" do
213
- expect(push).to eq(address)
214
- end
215
-
216
- it "resets the dirty changes" do
217
- expect(address).to_not be_changed
218
- end
219
-
220
- it "persists single pushes" do
221
- expect(address.reload.services).to eq([ 1, 4 ])
222
- end
223
-
224
- it "persists multiple pushes" do
225
- expect(address.reload.a).to eq([ 4, 5, 6, 7 ])
226
- end
227
-
228
- it "persists absent values" do
229
- expect(address.reload.test).to eq([ 1 ])
230
- end
231
- end
232
-
233
- let(:person) do
234
- Person.create
235
- end
236
-
237
- let(:address) do
238
- person.addresses.create(street: "t", services: [ 1 ], a: [ 4, 5 ])
239
- end
240
-
241
- context "when provided string fields" do
242
-
243
- let!(:push) do
244
- address.push("services" => 4, "a" => [ 6, 7 ], "test" => 1)
245
- end
246
-
247
- it_behaves_like "a pushable embedded document"
248
- end
249
-
250
- context "when provided symbol fields" do
251
-
252
- let!(:push) do
253
- address.push(services: 4, a: [ 6, 7 ], test: 1)
254
- end
255
-
256
- it_behaves_like "a pushable embedded document"
257
- end
258
- end
259
- end
260
- end
261
-
262
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe 'Mongoid::Persistable::Pushable' do
6
+
7
+ describe "#add_to_set" do
8
+
9
+ context "when the document is a root document" do
10
+
11
+ shared_examples_for "a unique pushable root document" do
12
+
13
+ it "adds single values" do
14
+ expect(person.aliases).to eq([ 1, 2, 4 ])
15
+ end
16
+
17
+ it "does not add duplicate values" do
18
+ expect(person.array).to eq([ 4, 5 ])
19
+ end
20
+
21
+ it "sets absent values" do
22
+ expect(person.test_array).to eq([ 1 ])
23
+ end
24
+
25
+ it "returns self objet" do
26
+ expect(add).to eq(person)
27
+ end
28
+
29
+ it "resets the dirty changes" do
30
+ expect(person).to_not be_changed
31
+ end
32
+
33
+ it "persists single adds" do
34
+ expect(person.reload.aliases).to eq([ 1, 2, 4 ])
35
+ end
36
+
37
+ it "persists absent values" do
38
+ expect(person.reload.test_array).to eq([ 1 ])
39
+ end
40
+
41
+ it "flattens only 1 level" do
42
+ expect(person.reload.arrays).to eq([[ 7, 8 ]])
43
+ end
44
+ end
45
+
46
+ let(:person) do
47
+ Person.create(aliases: [ 1, 2 ], array: [ 4, 5 ])
48
+ end
49
+
50
+ context "when provided string fields" do
51
+
52
+ let!(:add) do
53
+ person.add_to_set("aliases" => 4, "array" => [4, 5], "test_array" => 1, "arrays" => [[ 7, 8 ]])
54
+ end
55
+
56
+ it_behaves_like "a unique pushable root document"
57
+ end
58
+
59
+ context "when provided symbol fields" do
60
+
61
+ let!(:add) do
62
+ person.add_to_set(aliases: 4, array: [4, 5], test_array: 1, arrays: [[ 7, 8 ]])
63
+ end
64
+
65
+ it_behaves_like "a unique pushable root document"
66
+ end
67
+ end
68
+
69
+ context "when the document is embedded" do
70
+
71
+ shared_examples_for "a unique pushable embedded document" do
72
+
73
+ it "adds single values" do
74
+ expect(address.services).to eq([ 1, 4 ])
75
+ end
76
+
77
+ it "does not add duplicate values" do
78
+ expect(address.a).to eq([ 4, 5 ])
79
+ end
80
+
81
+ it "sets absent values" do
82
+ expect(address.test).to eq([ 1 ])
83
+ end
84
+
85
+ it "returns self object" do
86
+ expect(add).to eq(address)
87
+ end
88
+
89
+ it "resets the dirty changes" do
90
+ expect(address).to_not be_changed
91
+ end
92
+
93
+ it "persists single adds" do
94
+ expect(address.reload.services).to eq([ 1, 4 ])
95
+ end
96
+
97
+ it "persists absent values" do
98
+ expect(address.reload.test).to eq([ 1 ])
99
+ end
100
+ end
101
+
102
+ let(:person) do
103
+ Person.create
104
+ end
105
+
106
+ let(:address) do
107
+ person.addresses.create(street: "t", services: [ 1 ], a: [ 4, 5 ])
108
+ end
109
+
110
+ context "when provided string fields" do
111
+
112
+ let!(:add) do
113
+ address.add_to_set("services" => 4, "a" => 5, "test" => 1)
114
+ end
115
+
116
+ it_behaves_like "a unique pushable embedded document"
117
+ end
118
+
119
+ context "when provided symbol fields" do
120
+
121
+ let!(:add) do
122
+ address.add_to_set(services: 4, a: 5, test: 1)
123
+ end
124
+
125
+ it_behaves_like "a unique pushable embedded document"
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "#push" do
131
+
132
+ context "when the document is a root document" do
133
+
134
+ shared_examples_for "a pushable root document" do
135
+
136
+ it "pushes single values" do
137
+ expect(person.aliases).to eq([ 1, 2, 3, 4 ])
138
+ end
139
+
140
+ it "pushes multiple values" do
141
+ expect(person.array).to eq([ 4, 5, 6, 7, 8 ])
142
+ end
143
+
144
+ it "sets absent values" do
145
+ expect(person.test_array).to eq([ 1 ])
146
+ end
147
+
148
+ it "returns self object" do
149
+ expect(push).to eq(person)
150
+ end
151
+
152
+ it "resets the dirty changes" do
153
+ expect(person).to_not be_changed
154
+ end
155
+
156
+ it "persists single pushes" do
157
+ expect(person.reload.aliases).to eq([ 1, 2, 3, 4 ])
158
+ end
159
+
160
+ it "persists multiple pushes" do
161
+ expect(person.reload.array).to eq([ 4, 5, 6, 7, 8 ])
162
+ end
163
+
164
+ it "persists absent values" do
165
+ expect(person.reload.test_array).to eq([ 1 ])
166
+ end
167
+
168
+ it "flattens only 1 level" do
169
+ expect(person.reload.arrays).to eq([[ 7, 8 ]])
170
+ end
171
+ end
172
+
173
+ let(:person) do
174
+ Person.create(aliases: [ 1, 2, 3 ], array: [ 4, 5, 6 ])
175
+ end
176
+
177
+ context "when provided string fields" do
178
+
179
+ let!(:push) do
180
+ person.push("aliases" => 4, "array" => [ 7, 8 ], "test_array" => 1, "arrays" => [[ 7, 8 ]])
181
+ end
182
+
183
+ it_behaves_like "a pushable root document"
184
+ end
185
+
186
+ context "when provided symbol fields" do
187
+
188
+ let!(:push) do
189
+ person.push(aliases: 4, array: [ 7, 8 ], test_array: 1, arrays: [[ 7, 8 ]])
190
+ end
191
+
192
+ it_behaves_like "a pushable root document"
193
+ end
194
+ end
195
+
196
+ context "when the document is embedded" do
197
+
198
+ shared_examples_for "a pushable embedded document" do
199
+
200
+ it "pushes single values" do
201
+ expect(address.services).to eq([ 1, 4 ])
202
+ end
203
+
204
+ it "pushes multiple values" do
205
+ expect(address.a).to eq([ 4, 5, 6, 7 ])
206
+ end
207
+
208
+ it "sets absent values" do
209
+ expect(address.test).to eq([ 1 ])
210
+ end
211
+
212
+ it "returns self object" do
213
+ expect(push).to eq(address)
214
+ end
215
+
216
+ it "resets the dirty changes" do
217
+ expect(address).to_not be_changed
218
+ end
219
+
220
+ it "persists single pushes" do
221
+ expect(address.reload.services).to eq([ 1, 4 ])
222
+ end
223
+
224
+ it "persists multiple pushes" do
225
+ expect(address.reload.a).to eq([ 4, 5, 6, 7 ])
226
+ end
227
+
228
+ it "persists absent values" do
229
+ expect(address.reload.test).to eq([ 1 ])
230
+ end
231
+ end
232
+
233
+ let(:person) do
234
+ Person.create
235
+ end
236
+
237
+ let(:address) do
238
+ person.addresses.create(street: "t", services: [ 1 ], a: [ 4, 5 ])
239
+ end
240
+
241
+ context "when provided string fields" do
242
+
243
+ let!(:push) do
244
+ address.push("services" => 4, "a" => [ 6, 7 ], "test" => 1)
245
+ end
246
+
247
+ it_behaves_like "a pushable embedded document"
248
+ end
249
+
250
+ context "when provided symbol fields" do
251
+
252
+ let!(:push) do
253
+ address.push(services: 4, a: [ 6, 7 ], test: 1)
254
+ end
255
+
256
+ it_behaves_like "a pushable embedded document"
257
+ end
258
+ end
259
+ end
260
+ end
261
+
262
+ end