mongoid_monkey 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e3e1b1c557dfd20838b9e10d567598992c3a986
4
- data.tar.gz: 1e208434a126d2271cc7149adbc907a2bd89b2dd
3
+ metadata.gz: 1270657bcf2f5ccf0e861a86e0841a532195981c
4
+ data.tar.gz: 644db84d29dd1212ed509e6a84398ed49665742c
5
5
  SHA512:
6
- metadata.gz: dc3164dc9b3105e266d32c46276a46f1f973bcf785a1a3adc47db3488a54511844d041810969814e618f71afeef4063a19a49d7cde0767804fcd2f167b592d30
7
- data.tar.gz: baef2bf7858100e7ab2eb3c9e4dee5680fab26b3cdff96a091b6a0a396b93b261a6176856a42de97ddf4110a9db14e64340942c5173a961c67da9475069a5311
6
+ metadata.gz: eee46b50722dbff39018cb461d00ccaec280ac0a9e0d7de46d6121940849bb169e71853e21763054078a49314d2b016d4c7ab195727959a6c2ca5a2c9038c8f0
7
+ data.tar.gz: e262c2697046add13c455ba4e2406904d874cbe334e8c8566d490f047ff563323acaa621ae6e312db3ff8403db5b7b176524a226973e9d0f1d65f9d8b477b9f8
data/README.md CHANGED
@@ -37,6 +37,7 @@ If you would only like some of the patches, please copy and paste the code to yo
37
37
  | `instrument.rb` | Backport instrumentation change to Moped 1. | ● | ○ | ○ |
38
38
  | `reorder.rb` | Backport `Criteria#reorder` method from Mongoid 4. | ● | ○ | ○ |
39
39
  | `only_pluck_localized.rb` | Backport [PR #4299](https://github.com/mongodb/mongoid/pull/4299) from Mongoid 6 which fixes `#only`, `#without`, and `#pluck` with localized fields. | ● | × | × |
40
+ | `embedded_touch.rb` | Backport [Issue #3310](https://github.com/mongodb/mongoid/commit/a94c2f43573e58f973913c881ad9d11d62bf857c) from Mongoid 4 to add `:touch` option to `embedded_in`. | ● | ○ | ○ |
40
41
 
41
42
  ### License
42
43
 
@@ -6,3 +6,4 @@ require 'patches/db_commands'
6
6
  require 'patches/instrument'
7
7
  require 'patches/reorder'
8
8
  require 'patches/only_pluck_localized'
9
+ require 'patches/embedded_touch'
@@ -0,0 +1,37 @@
1
+ # Backport Mongoid 4 :touch option for #embedded_in to Mongoid 3.
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ module Mongoid
6
+ module Relations
7
+ module Embedded
8
+ class In < Relations::One
9
+ class << self
10
+ def valid_options
11
+ [ :autobuild, :cyclic, :polymorphic, :touch ]
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ module Macros
18
+ module ClassMethods
19
+
20
+ def embedded_in(name, options = {}, &block)
21
+ if ancestors.include?(Mongoid::Versioning)
22
+ raise Errors::VersioningNotOnRoot.new(self)
23
+ end
24
+ meta = characterize(name, Embedded::In, options, &block)
25
+ self.embedded = true
26
+ relate(name, meta)
27
+ builder(name, meta).creator(name, meta)
28
+ touchable(meta)
29
+ add_counter_cache_callbacks(meta) if meta.counter_cached?
30
+ meta
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MongoidMonkey
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -1,266 +1,266 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::AddToSet do
6
-
7
- describe "#persist" do
8
-
9
- context "when the document is new" do
10
-
11
- let(:person) do
12
- Person.new
13
- end
14
-
15
- context "when adding a single value" do
16
-
17
- let!(:added) do
18
- person.add_to_set(:aliases, "Bond")
19
- end
20
-
21
- it "adds the value onto the array" do
22
- person.aliases.should eq([ "Bond" ])
23
- end
24
-
25
- it "does not reset the dirty flagging" do
26
- person.changes["aliases"].should eq([nil, ["Bond"]])
27
- end
28
-
29
- it "returns the new array value" do
30
- added.should eq([ "Bond" ])
31
- end
32
- end
33
-
34
- context "when adding multiple values" do
35
-
36
- let!(:added) do
37
- person.add_to_set(:aliases, [ "Bond", "James" ])
38
- end
39
-
40
- it "adds the value onto the array" do
41
- person.aliases.should eq([ "Bond", "James" ])
42
- end
43
-
44
- it "does not reset the dirty flagging" do
45
- person.changes["aliases"].should eq([nil, ["Bond", "James"]])
46
- end
47
-
48
- it "returns the new array value" do
49
- added.should eq([ "Bond", "James" ])
50
- end
51
- end
52
- end
53
-
54
- context "when the field exists" do
55
-
56
- context "when the value is unique" do
57
-
58
- let(:person) do
59
- Person.create(aliases: [ "007" ])
60
- end
61
-
62
- context "when adding a single value" do
63
-
64
- let!(:added) do
65
- person.add_to_set(:aliases, "Bond")
66
- end
67
-
68
- let(:reloaded) do
69
- person.reload
70
- end
71
-
72
- it "adds the value onto the array" do
73
- person.aliases.should eq([ "007", "Bond" ])
74
- end
75
-
76
- it "persists the data" do
77
- reloaded.aliases.should eq([ "007", "Bond" ])
78
- end
79
-
80
- it "removes the field from the dirty attributes" do
81
- person.changes["aliases"].should be_nil
82
- end
83
-
84
- it "resets the document dirty flag" do
85
- person.should_not be_changed
86
- end
87
-
88
- it "returns the new array value" do
89
- added.should eq([ "007", "Bond" ])
90
- end
91
- end
92
-
93
- context "when adding a multiple values" do
94
-
95
- let!(:added) do
96
- person.add_to_set(:aliases, [ "Bond", "James" ])
97
- end
98
-
99
- let(:reloaded) do
100
- person.reload
101
- end
102
-
103
- it "adds the value onto the array" do
104
- person.aliases.should eq([ "007", "Bond", "James" ])
105
- end
106
-
107
- it "persists the data" do
108
- reloaded.aliases.should eq([ "007", "Bond", "James" ])
109
- end
110
-
111
- it "removes the field from the dirty attributes" do
112
- person.changes["aliases"].should be_nil
113
- end
114
-
115
- it "resets the document dirty flag" do
116
- person.should_not be_changed
117
- end
118
-
119
- it "returns the new array value" do
120
- added.should eq([ "007", "Bond", "James" ])
121
- end
122
- end
123
- end
124
-
125
- context "when the value is not unique" do
126
-
127
- let(:person) do
128
- Person.create(aliases: [ "Bond" ])
129
- end
130
-
131
- context "when adding a single value" do
132
-
133
- let!(:added) do
134
- person.add_to_set(:aliases, "Bond")
135
- end
136
-
137
- let(:reloaded) do
138
- person.reload
139
- end
140
-
141
- it "does not add the value" do
142
- person.aliases.should eq([ "Bond" ])
143
- end
144
-
145
- it "persists the data" do
146
- reloaded.aliases.should eq([ "Bond" ])
147
- end
148
-
149
- it "removes the field from the dirty attributes" do
150
- person.changes["aliases"].should be_nil
151
- end
152
-
153
- it "resets the document dirty flag" do
154
- person.should_not be_changed
155
- end
156
-
157
- it "returns the array value" do
158
- added.should eq([ "Bond" ])
159
- end
160
- end
161
-
162
- context "when adding multiple values" do
163
-
164
- let!(:added) do
165
- person.add_to_set(:aliases, [ "Bond", "James" ])
166
- end
167
-
168
- let(:reloaded) do
169
- person.reload
170
- end
171
-
172
- it "does not add the duplicate value" do
173
- person.aliases.should eq([ "Bond", "James" ])
174
- end
175
-
176
- it "persists the data" do
177
- reloaded.aliases.should eq([ "Bond", "James" ])
178
- end
179
-
180
- it "removes the field from the dirty attributes" do
181
- person.changes["aliases"].should be_nil
182
- end
183
-
184
- it "resets the document dirty flag" do
185
- person.should_not be_changed
186
- end
187
-
188
- it "returns the array value" do
189
- added.should eq([ "Bond", "James" ])
190
- end
191
- end
192
- end
193
- end
194
-
195
- context "when the field does not exist" do
196
-
197
- let(:person) do
198
- Person.create
199
- end
200
-
201
- context "when adding a single value" do
202
-
203
- let!(:added) do
204
- person.add_to_set(:aliases, "Bond")
205
- end
206
-
207
- let(:reloaded) do
208
- person.reload
209
- end
210
-
211
- it "adds the value onto the array" do
212
- person.aliases.should eq([ "Bond" ])
213
- end
214
-
215
- it "persists the data" do
216
- reloaded.aliases.should eq([ "Bond" ])
217
- end
218
-
219
- it "removes the field from the dirty attributes" do
220
- person.changes["aliases"].should be_nil
221
- end
222
-
223
- it "resets the document dirty flag" do
224
- person.should_not be_changed
225
- end
226
-
227
- it "returns the new array value" do
228
- added.should eq([ "Bond" ])
229
- end
230
- end
231
-
232
- context "when adding multiple values" do
233
-
234
- let!(:added) do
235
- person.add_to_set(:aliases, [ "Bond", "James" ])
236
- end
237
-
238
- let(:reloaded) do
239
- person.reload
240
- end
241
-
242
- it "adds the value onto the array" do
243
- person.aliases.should eq([ "Bond", "James" ])
244
- end
245
-
246
- it "persists the data" do
247
- reloaded.aliases.should eq([ "Bond", "James" ])
248
- end
249
-
250
- it "removes the field from the dirty attributes" do
251
- person.changes["aliases"].should be_nil
252
- end
253
-
254
- it "resets the document dirty flag" do
255
- person.should_not be_changed
256
- end
257
-
258
- it "returns the new array value" do
259
- added.should eq([ "Bond", "James" ])
260
- end
261
- end
262
- end
263
- end
264
- end
265
-
266
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::AddToSet do
6
+
7
+ describe "#persist" do
8
+
9
+ context "when the document is new" do
10
+
11
+ let(:person) do
12
+ Person.new
13
+ end
14
+
15
+ context "when adding a single value" do
16
+
17
+ let!(:added) do
18
+ person.add_to_set(:aliases, "Bond")
19
+ end
20
+
21
+ it "adds the value onto the array" do
22
+ person.aliases.should eq([ "Bond" ])
23
+ end
24
+
25
+ it "does not reset the dirty flagging" do
26
+ person.changes["aliases"].should eq([nil, ["Bond"]])
27
+ end
28
+
29
+ it "returns the new array value" do
30
+ added.should eq([ "Bond" ])
31
+ end
32
+ end
33
+
34
+ context "when adding multiple values" do
35
+
36
+ let!(:added) do
37
+ person.add_to_set(:aliases, [ "Bond", "James" ])
38
+ end
39
+
40
+ it "adds the value onto the array" do
41
+ person.aliases.should eq([ "Bond", "James" ])
42
+ end
43
+
44
+ it "does not reset the dirty flagging" do
45
+ person.changes["aliases"].should eq([nil, ["Bond", "James"]])
46
+ end
47
+
48
+ it "returns the new array value" do
49
+ added.should eq([ "Bond", "James" ])
50
+ end
51
+ end
52
+ end
53
+
54
+ context "when the field exists" do
55
+
56
+ context "when the value is unique" do
57
+
58
+ let(:person) do
59
+ Person.create(aliases: [ "007" ])
60
+ end
61
+
62
+ context "when adding a single value" do
63
+
64
+ let!(:added) do
65
+ person.add_to_set(:aliases, "Bond")
66
+ end
67
+
68
+ let(:reloaded) do
69
+ person.reload
70
+ end
71
+
72
+ it "adds the value onto the array" do
73
+ person.aliases.should eq([ "007", "Bond" ])
74
+ end
75
+
76
+ it "persists the data" do
77
+ reloaded.aliases.should eq([ "007", "Bond" ])
78
+ end
79
+
80
+ it "removes the field from the dirty attributes" do
81
+ person.changes["aliases"].should be_nil
82
+ end
83
+
84
+ it "resets the document dirty flag" do
85
+ person.should_not be_changed
86
+ end
87
+
88
+ it "returns the new array value" do
89
+ added.should eq([ "007", "Bond" ])
90
+ end
91
+ end
92
+
93
+ context "when adding a multiple values" do
94
+
95
+ let!(:added) do
96
+ person.add_to_set(:aliases, [ "Bond", "James" ])
97
+ end
98
+
99
+ let(:reloaded) do
100
+ person.reload
101
+ end
102
+
103
+ it "adds the value onto the array" do
104
+ person.aliases.should eq([ "007", "Bond", "James" ])
105
+ end
106
+
107
+ it "persists the data" do
108
+ reloaded.aliases.should eq([ "007", "Bond", "James" ])
109
+ end
110
+
111
+ it "removes the field from the dirty attributes" do
112
+ person.changes["aliases"].should be_nil
113
+ end
114
+
115
+ it "resets the document dirty flag" do
116
+ person.should_not be_changed
117
+ end
118
+
119
+ it "returns the new array value" do
120
+ added.should eq([ "007", "Bond", "James" ])
121
+ end
122
+ end
123
+ end
124
+
125
+ context "when the value is not unique" do
126
+
127
+ let(:person) do
128
+ Person.create(aliases: [ "Bond" ])
129
+ end
130
+
131
+ context "when adding a single value" do
132
+
133
+ let!(:added) do
134
+ person.add_to_set(:aliases, "Bond")
135
+ end
136
+
137
+ let(:reloaded) do
138
+ person.reload
139
+ end
140
+
141
+ it "does not add the value" do
142
+ person.aliases.should eq([ "Bond" ])
143
+ end
144
+
145
+ it "persists the data" do
146
+ reloaded.aliases.should eq([ "Bond" ])
147
+ end
148
+
149
+ it "removes the field from the dirty attributes" do
150
+ person.changes["aliases"].should be_nil
151
+ end
152
+
153
+ it "resets the document dirty flag" do
154
+ person.should_not be_changed
155
+ end
156
+
157
+ it "returns the array value" do
158
+ added.should eq([ "Bond" ])
159
+ end
160
+ end
161
+
162
+ context "when adding multiple values" do
163
+
164
+ let!(:added) do
165
+ person.add_to_set(:aliases, [ "Bond", "James" ])
166
+ end
167
+
168
+ let(:reloaded) do
169
+ person.reload
170
+ end
171
+
172
+ it "does not add the duplicate value" do
173
+ person.aliases.should eq([ "Bond", "James" ])
174
+ end
175
+
176
+ it "persists the data" do
177
+ reloaded.aliases.should eq([ "Bond", "James" ])
178
+ end
179
+
180
+ it "removes the field from the dirty attributes" do
181
+ person.changes["aliases"].should be_nil
182
+ end
183
+
184
+ it "resets the document dirty flag" do
185
+ person.should_not be_changed
186
+ end
187
+
188
+ it "returns the array value" do
189
+ added.should eq([ "Bond", "James" ])
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ context "when the field does not exist" do
196
+
197
+ let(:person) do
198
+ Person.create
199
+ end
200
+
201
+ context "when adding a single value" do
202
+
203
+ let!(:added) do
204
+ person.add_to_set(:aliases, "Bond")
205
+ end
206
+
207
+ let(:reloaded) do
208
+ person.reload
209
+ end
210
+
211
+ it "adds the value onto the array" do
212
+ person.aliases.should eq([ "Bond" ])
213
+ end
214
+
215
+ it "persists the data" do
216
+ reloaded.aliases.should eq([ "Bond" ])
217
+ end
218
+
219
+ it "removes the field from the dirty attributes" do
220
+ person.changes["aliases"].should be_nil
221
+ end
222
+
223
+ it "resets the document dirty flag" do
224
+ person.should_not be_changed
225
+ end
226
+
227
+ it "returns the new array value" do
228
+ added.should eq([ "Bond" ])
229
+ end
230
+ end
231
+
232
+ context "when adding multiple values" do
233
+
234
+ let!(:added) do
235
+ person.add_to_set(:aliases, [ "Bond", "James" ])
236
+ end
237
+
238
+ let(:reloaded) do
239
+ person.reload
240
+ end
241
+
242
+ it "adds the value onto the array" do
243
+ person.aliases.should eq([ "Bond", "James" ])
244
+ end
245
+
246
+ it "persists the data" do
247
+ reloaded.aliases.should eq([ "Bond", "James" ])
248
+ end
249
+
250
+ it "removes the field from the dirty attributes" do
251
+ person.changes["aliases"].should be_nil
252
+ end
253
+
254
+ it "resets the document dirty flag" do
255
+ person.should_not be_changed
256
+ end
257
+
258
+ it "returns the new array value" do
259
+ added.should eq([ "Bond", "James" ])
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ end