mongoid_monkey 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/lib/mongoid_monkey.rb +1 -0
  4. data/lib/patches/embedded_touch.rb +37 -0
  5. data/lib/version.rb +1 -1
  6. data/spec/unit/atomic/mongoid3_style/atomic/add_to_set_spec.rb +266 -266
  7. data/spec/unit/atomic/mongoid3_style/atomic/bit_spec.rb +92 -92
  8. data/spec/unit/atomic/mongoid3_style/atomic/inc_spec.rb +137 -137
  9. data/spec/unit/atomic/mongoid3_style/atomic/pop_spec.rb +115 -115
  10. data/spec/unit/atomic/mongoid3_style/atomic/pull_all_spec.rb +81 -81
  11. data/spec/unit/atomic/mongoid3_style/atomic/pull_spec.rb +84 -84
  12. data/spec/unit/atomic/mongoid3_style/atomic/push_all_spec.rb +81 -81
  13. data/spec/unit/atomic/mongoid3_style/atomic/push_spec.rb +81 -81
  14. data/spec/unit/atomic/mongoid3_style/atomic/rename_spec.rb +46 -46
  15. data/spec/unit/atomic/mongoid3_style/atomic/sets_spec.rb +158 -158
  16. data/spec/unit/atomic/mongoid3_style/atomic/unset_spec.rb +69 -69
  17. data/spec/unit/atomic/mongoid3_style/atomic_spec.rb +220 -220
  18. data/spec/unit/atomic/mongoid4_style/incrementable_spec.rb +232 -232
  19. data/spec/unit/atomic/mongoid4_style/logical_spec.rb +262 -262
  20. data/spec/unit/atomic/mongoid4_style/poppable_spec.rb +139 -139
  21. data/spec/unit/atomic/mongoid4_style/pullable_spec.rb +172 -172
  22. data/spec/unit/atomic/mongoid4_style/pushable_spec.rb +159 -159
  23. data/spec/unit/atomic/mongoid4_style/renamable_spec.rb +139 -139
  24. data/spec/unit/atomic/mongoid4_style/unsettable_spec.rb +28 -28
  25. data/spec/unit/embedded_touch_spec.rb +52 -0
  26. data/spec/unit/{only_pluck_localized.rb → only_pluck_localized_spec.rb} +0 -0
  27. metadata +7 -4
@@ -1,232 +1,232 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe 'Mongoid::Persistable::Pullable' do
6
-
7
- describe "#pull" do
8
-
9
- context "when the document is a root document" do
10
-
11
- shared_examples_for "a pullable root document" do
12
-
13
- it "pulls the first value" do
14
- expect(person.aliases).to eq([ 2, 3 ])
15
- end
16
-
17
- it "pulls the last value" do
18
- expect(person.array).to eq([ 4, 6 ])
19
- end
20
-
21
- it "returns self object" do
22
- expect(pull).to eq(person)
23
- end
24
-
25
- it "resets dirty changes" do
26
- expect(person).to_not be_changed
27
- end
28
-
29
- it "persists the first pull" do
30
- expect(person.reload.aliases).to eq([ 2, 3 ])
31
- end
32
-
33
- it "persists the last pull" do
34
- expect(person.reload.array).to eq([ 4, 6 ])
35
- end
36
- end
37
-
38
- let(:person) do
39
- Person.create(aliases: [ 1, 1, 2, 3 ], array: [ 4, 5, 6 ])
40
- end
41
-
42
- context "when providing string keys" do
43
-
44
- let!(:pull) do
45
- person.pull("aliases" => 1, "array" => 5, "test_array" => 2)
46
- end
47
-
48
- it_behaves_like "a pullable root document"
49
- end
50
-
51
- context "when providing symbol keys" do
52
-
53
- let!(:pull) do
54
- person.pull(aliases: 1, array: 5)
55
- end
56
-
57
- it_behaves_like "a pullable root document"
58
- end
59
- end
60
-
61
- context "when the document is embedded" do
62
-
63
- shared_examples_for "a pullable embedded document" do
64
-
65
- it "pulls the first value" do
66
- expect(address.services).to eq([ 2, 3 ])
67
- end
68
-
69
- it "pulls the last value" do
70
- expect(address.a).to eq([ 4, 6 ])
71
- end
72
-
73
- it "returns self object" do
74
- expect(pull).to eq(address)
75
- end
76
-
77
- it "resets dirty changes" do
78
- expect(address).to_not be_changed
79
- end
80
-
81
- it "persists the first pull" do
82
- expect(address.reload.services).to eq([ 2, 3 ])
83
- end
84
-
85
- it "persists the last pull" do
86
- expect(address.reload.a).to eq([ 4, 6 ])
87
- end
88
- end
89
-
90
- let(:person) do
91
- Person.create
92
- end
93
-
94
- let(:address) do
95
- person.addresses.create(street: "t", services: [ 1, 2, 3 ], a: [ 4, 5, 6 ])
96
- end
97
-
98
- context "when providing string keys" do
99
-
100
- let!(:pull) do
101
- address.pull("services" => 1, "a" => 5)
102
- end
103
-
104
- it_behaves_like "a pullable embedded document"
105
- end
106
-
107
- context "when providing symbol keys" do
108
-
109
- let!(:pull) do
110
- address.pull(services: 1, a: 5)
111
- end
112
-
113
- it_behaves_like "a pullable embedded document"
114
- end
115
- end
116
- end
117
-
118
- describe "#pull_all" do
119
-
120
- context "when the document is the root document" do
121
-
122
- shared_examples_for "a multi-pullable root document" do
123
-
124
- it "pulls the first value" do
125
- expect(person.aliases).to eq([ 3 ])
126
- end
127
-
128
- it "pulls the last value" do
129
- expect(person.array).to eq([ 4 ])
130
- end
131
-
132
- it "returns self object" do
133
- expect(pull_all).to eq(person)
134
- end
135
-
136
- it "resets dirty changes" do
137
- expect(person).to_not be_changed
138
- end
139
-
140
- it "persists the first pull" do
141
- expect(person.reload.aliases).to eq([ 3 ])
142
- end
143
-
144
- it "persists the last pull" do
145
- expect(person.reload.array).to eq([ 4 ])
146
- end
147
- end
148
-
149
- let(:person) do
150
- Person.create(aliases: [ 1, 1, 2, 3 ], array: [ 4, 5, 6 ])
151
- end
152
-
153
- context "when providing string keys" do
154
-
155
- let!(:pull_all) do
156
- person.pull_all(
157
- "aliases" => [ 1, 2 ], "array" => [ 5, 6 ], "test_array" => [ 1 ]
158
- )
159
- end
160
-
161
- it_behaves_like "a multi-pullable root document"
162
- end
163
-
164
- context "when providing symbol keys" do
165
-
166
- let!(:pull_all) do
167
- person.pull_all(aliases: [ 1, 2 ], array: [ 5, 6 ])
168
- end
169
-
170
- it_behaves_like "a multi-pullable root document"
171
- end
172
- end
173
-
174
- context "when the document is embedded" do
175
-
176
- shared_examples_for "a multi-pullable embedded document" do
177
-
178
- it "pulls the first value" do
179
- expect(address.services).to eq([ 3 ])
180
- end
181
-
182
- it "pulls the last value" do
183
- expect(address.a).to eq([ 4 ])
184
- end
185
-
186
- it "returns self object" do
187
- expect(pull_all).to eq(address)
188
- end
189
-
190
- it "resets dirty changes" do
191
- expect(address).to_not be_changed
192
- end
193
-
194
- it "persists the first pull" do
195
- expect(address.reload.services).to eq([ 3 ])
196
- end
197
-
198
- it "persists the last pull" do
199
- expect(address.reload.a).to eq([ 4 ])
200
- end
201
- end
202
-
203
- let(:person) do
204
- Person.create
205
- end
206
-
207
- let(:address) do
208
- person.addresses.create(street: "t", services: [ 1, 2, 3 ], a: [ 4, 5, 6 ])
209
- end
210
-
211
- context "when providing string keys" do
212
-
213
- let!(:pull_all) do
214
- address.pull_all("services" => [ 1, 2 ], "a" => [ 5, 6 ])
215
- end
216
-
217
- it_behaves_like "a multi-pullable embedded document"
218
- end
219
-
220
- context "when providing symbol keys" do
221
-
222
- let!(:pull_all) do
223
- address.pull_all(services: [ 1, 2 ], a: [ 5, 6 ])
224
- end
225
-
226
- it_behaves_like "a multi-pullable embedded document"
227
- end
228
- end
229
- end
230
- end
231
-
232
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe 'Mongoid::Persistable::Pullable' do
6
+
7
+ describe "#pull" do
8
+
9
+ context "when the document is a root document" do
10
+
11
+ shared_examples_for "a pullable root document" do
12
+
13
+ it "pulls the first value" do
14
+ expect(person.aliases).to eq([ 2, 3 ])
15
+ end
16
+
17
+ it "pulls the last value" do
18
+ expect(person.array).to eq([ 4, 6 ])
19
+ end
20
+
21
+ it "returns self object" do
22
+ expect(pull).to eq(person)
23
+ end
24
+
25
+ it "resets dirty changes" do
26
+ expect(person).to_not be_changed
27
+ end
28
+
29
+ it "persists the first pull" do
30
+ expect(person.reload.aliases).to eq([ 2, 3 ])
31
+ end
32
+
33
+ it "persists the last pull" do
34
+ expect(person.reload.array).to eq([ 4, 6 ])
35
+ end
36
+ end
37
+
38
+ let(:person) do
39
+ Person.create(aliases: [ 1, 1, 2, 3 ], array: [ 4, 5, 6 ])
40
+ end
41
+
42
+ context "when providing string keys" do
43
+
44
+ let!(:pull) do
45
+ person.pull("aliases" => 1, "array" => 5, "test_array" => 2)
46
+ end
47
+
48
+ it_behaves_like "a pullable root document"
49
+ end
50
+
51
+ context "when providing symbol keys" do
52
+
53
+ let!(:pull) do
54
+ person.pull(aliases: 1, array: 5)
55
+ end
56
+
57
+ it_behaves_like "a pullable root document"
58
+ end
59
+ end
60
+
61
+ context "when the document is embedded" do
62
+
63
+ shared_examples_for "a pullable embedded document" do
64
+
65
+ it "pulls the first value" do
66
+ expect(address.services).to eq([ 2, 3 ])
67
+ end
68
+
69
+ it "pulls the last value" do
70
+ expect(address.a).to eq([ 4, 6 ])
71
+ end
72
+
73
+ it "returns self object" do
74
+ expect(pull).to eq(address)
75
+ end
76
+
77
+ it "resets dirty changes" do
78
+ expect(address).to_not be_changed
79
+ end
80
+
81
+ it "persists the first pull" do
82
+ expect(address.reload.services).to eq([ 2, 3 ])
83
+ end
84
+
85
+ it "persists the last pull" do
86
+ expect(address.reload.a).to eq([ 4, 6 ])
87
+ end
88
+ end
89
+
90
+ let(:person) do
91
+ Person.create
92
+ end
93
+
94
+ let(:address) do
95
+ person.addresses.create(street: "t", services: [ 1, 2, 3 ], a: [ 4, 5, 6 ])
96
+ end
97
+
98
+ context "when providing string keys" do
99
+
100
+ let!(:pull) do
101
+ address.pull("services" => 1, "a" => 5)
102
+ end
103
+
104
+ it_behaves_like "a pullable embedded document"
105
+ end
106
+
107
+ context "when providing symbol keys" do
108
+
109
+ let!(:pull) do
110
+ address.pull(services: 1, a: 5)
111
+ end
112
+
113
+ it_behaves_like "a pullable embedded document"
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#pull_all" do
119
+
120
+ context "when the document is the root document" do
121
+
122
+ shared_examples_for "a multi-pullable root document" do
123
+
124
+ it "pulls the first value" do
125
+ expect(person.aliases).to eq([ 3 ])
126
+ end
127
+
128
+ it "pulls the last value" do
129
+ expect(person.array).to eq([ 4 ])
130
+ end
131
+
132
+ it "returns self object" do
133
+ expect(pull_all).to eq(person)
134
+ end
135
+
136
+ it "resets dirty changes" do
137
+ expect(person).to_not be_changed
138
+ end
139
+
140
+ it "persists the first pull" do
141
+ expect(person.reload.aliases).to eq([ 3 ])
142
+ end
143
+
144
+ it "persists the last pull" do
145
+ expect(person.reload.array).to eq([ 4 ])
146
+ end
147
+ end
148
+
149
+ let(:person) do
150
+ Person.create(aliases: [ 1, 1, 2, 3 ], array: [ 4, 5, 6 ])
151
+ end
152
+
153
+ context "when providing string keys" do
154
+
155
+ let!(:pull_all) do
156
+ person.pull_all(
157
+ "aliases" => [ 1, 2 ], "array" => [ 5, 6 ], "test_array" => [ 1 ]
158
+ )
159
+ end
160
+
161
+ it_behaves_like "a multi-pullable root document"
162
+ end
163
+
164
+ context "when providing symbol keys" do
165
+
166
+ let!(:pull_all) do
167
+ person.pull_all(aliases: [ 1, 2 ], array: [ 5, 6 ])
168
+ end
169
+
170
+ it_behaves_like "a multi-pullable root document"
171
+ end
172
+ end
173
+
174
+ context "when the document is embedded" do
175
+
176
+ shared_examples_for "a multi-pullable embedded document" do
177
+
178
+ it "pulls the first value" do
179
+ expect(address.services).to eq([ 3 ])
180
+ end
181
+
182
+ it "pulls the last value" do
183
+ expect(address.a).to eq([ 4 ])
184
+ end
185
+
186
+ it "returns self object" do
187
+ expect(pull_all).to eq(address)
188
+ end
189
+
190
+ it "resets dirty changes" do
191
+ expect(address).to_not be_changed
192
+ end
193
+
194
+ it "persists the first pull" do
195
+ expect(address.reload.services).to eq([ 3 ])
196
+ end
197
+
198
+ it "persists the last pull" do
199
+ expect(address.reload.a).to eq([ 4 ])
200
+ end
201
+ end
202
+
203
+ let(:person) do
204
+ Person.create
205
+ end
206
+
207
+ let(:address) do
208
+ person.addresses.create(street: "t", services: [ 1, 2, 3 ], a: [ 4, 5, 6 ])
209
+ end
210
+
211
+ context "when providing string keys" do
212
+
213
+ let!(:pull_all) do
214
+ address.pull_all("services" => [ 1, 2 ], "a" => [ 5, 6 ])
215
+ end
216
+
217
+ it_behaves_like "a multi-pullable embedded document"
218
+ end
219
+
220
+ context "when providing symbol keys" do
221
+
222
+ let!(:pull_all) do
223
+ address.pull_all(services: [ 1, 2 ], a: [ 5, 6 ])
224
+ end
225
+
226
+ it_behaves_like "a multi-pullable embedded document"
227
+ end
228
+ end
229
+ end
230
+ end
231
+
232
+ end