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.
- checksums.yaml +4 -4
- data/lib/patches/only_pluck_localized.rb +0 -1
- data/lib/version.rb +1 -1
- data/spec/unit/atomic/mongoid3_style/atomic/add_to_set_spec.rb +266 -266
- data/spec/unit/atomic/mongoid3_style/atomic/bit_spec.rb +92 -92
- data/spec/unit/atomic/mongoid3_style/atomic/inc_spec.rb +137 -137
- data/spec/unit/atomic/mongoid3_style/atomic/pop_spec.rb +115 -115
- data/spec/unit/atomic/mongoid3_style/atomic/pull_all_spec.rb +81 -81
- data/spec/unit/atomic/mongoid3_style/atomic/pull_spec.rb +84 -84
- data/spec/unit/atomic/mongoid3_style/atomic/push_all_spec.rb +81 -81
- data/spec/unit/atomic/mongoid3_style/atomic/push_spec.rb +81 -81
- data/spec/unit/atomic/mongoid3_style/atomic/rename_spec.rb +46 -46
- data/spec/unit/atomic/mongoid3_style/atomic/sets_spec.rb +158 -158
- data/spec/unit/atomic/mongoid3_style/atomic/unset_spec.rb +69 -69
- data/spec/unit/atomic/mongoid3_style/atomic_spec.rb +220 -220
- data/spec/unit/atomic/mongoid4_style/incrementable_spec.rb +232 -232
- data/spec/unit/atomic/mongoid4_style/logical_spec.rb +262 -262
- data/spec/unit/atomic/mongoid4_style/poppable_spec.rb +139 -139
- data/spec/unit/atomic/mongoid4_style/pullable_spec.rb +172 -172
- data/spec/unit/atomic/mongoid4_style/pushable_spec.rb +159 -159
- data/spec/unit/atomic/mongoid4_style/renamable_spec.rb +139 -139
- data/spec/unit/atomic/mongoid4_style/unsettable_spec.rb +28 -28
- metadata +2 -2
@@ -1,69 +1,69 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if Mongoid::VERSION =~ /\A3\./
|
4
|
-
|
5
|
-
describe Mongoid::Persistence::Atomic::Unset do
|
6
|
-
|
7
|
-
describe "#persist" do
|
8
|
-
|
9
|
-
context "when unsetting a field" do
|
10
|
-
|
11
|
-
let(:person) do
|
12
|
-
Person.create(age: 100)
|
13
|
-
end
|
14
|
-
|
15
|
-
let!(:removed) do
|
16
|
-
person.unset(:age)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "removes the field" do
|
20
|
-
person.age.should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "resets the dirty attributes" do
|
24
|
-
person.changes["age"].should be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns nil" do
|
28
|
-
removed.should be_nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
[[ :age, :score, { safe: true }], [ :age, :score ], [ [:age, :score ]]].each do |args|
|
34
|
-
|
35
|
-
context "when unsetting multiple fields using #{args}" do
|
36
|
-
|
37
|
-
let(:person) do
|
38
|
-
Person.create(age: 100, score: 2)
|
39
|
-
end
|
40
|
-
|
41
|
-
let!(:removed) do
|
42
|
-
person.unset *(args)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "removes age field" do
|
46
|
-
person.age.should be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "removes score field" do
|
50
|
-
person.score.should be_nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it "resets the age dirty attribute" do
|
54
|
-
person.changes["age"].should be_nil
|
55
|
-
end
|
56
|
-
|
57
|
-
it "resets the score dirty attribute" do
|
58
|
-
person.changes["score"].should be_nil
|
59
|
-
end
|
60
|
-
|
61
|
-
it "returns nil" do
|
62
|
-
removed.should be_nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
if Mongoid::VERSION =~ /\A3\./
|
4
|
+
|
5
|
+
describe Mongoid::Persistence::Atomic::Unset do
|
6
|
+
|
7
|
+
describe "#persist" do
|
8
|
+
|
9
|
+
context "when unsetting a field" do
|
10
|
+
|
11
|
+
let(:person) do
|
12
|
+
Person.create(age: 100)
|
13
|
+
end
|
14
|
+
|
15
|
+
let!(:removed) do
|
16
|
+
person.unset(:age)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "removes the field" do
|
20
|
+
person.age.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "resets the dirty attributes" do
|
24
|
+
person.changes["age"].should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns nil" do
|
28
|
+
removed.should be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
[[ :age, :score, { safe: true }], [ :age, :score ], [ [:age, :score ]]].each do |args|
|
34
|
+
|
35
|
+
context "when unsetting multiple fields using #{args}" do
|
36
|
+
|
37
|
+
let(:person) do
|
38
|
+
Person.create(age: 100, score: 2)
|
39
|
+
end
|
40
|
+
|
41
|
+
let!(:removed) do
|
42
|
+
person.unset *(args)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "removes age field" do
|
46
|
+
person.age.should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "removes score field" do
|
50
|
+
person.score.should be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "resets the age dirty attribute" do
|
54
|
+
person.changes["age"].should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "resets the score dirty attribute" do
|
58
|
+
person.changes["score"].should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns nil" do
|
62
|
+
removed.should be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -1,220 +1,220 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if Mongoid::VERSION =~ /\A3\./
|
4
|
-
|
5
|
-
describe Mongoid::Persistence::Atomic do
|
6
|
-
|
7
|
-
context "when using aliased field names" do
|
8
|
-
|
9
|
-
describe "#add_to_set" do
|
10
|
-
|
11
|
-
let(:person) do
|
12
|
-
Person.create(array: [ "test" ])
|
13
|
-
end
|
14
|
-
|
15
|
-
before do
|
16
|
-
person.add_to_set(:array, "testy")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "adds to the aliased field" do
|
20
|
-
person.array.should eq([ "test", "testy" ])
|
21
|
-
end
|
22
|
-
|
23
|
-
it "persists the change" do
|
24
|
-
person.reload.array.should eq([ "test", "testy" ])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#bit" do
|
29
|
-
|
30
|
-
let(:person) do
|
31
|
-
Person.create(inte: 60)
|
32
|
-
end
|
33
|
-
|
34
|
-
before do
|
35
|
-
person.bit(:inte, { and: 13 })
|
36
|
-
end
|
37
|
-
|
38
|
-
it "performs the bitwise operation" do
|
39
|
-
person.inte.should eq(12)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "persists the changes" do
|
43
|
-
person.reload.inte.should eq(12)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#inc" do
|
48
|
-
|
49
|
-
let(:person) do
|
50
|
-
Person.create(inte: 5)
|
51
|
-
end
|
52
|
-
|
53
|
-
before do
|
54
|
-
person.inc(:inte, 1)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "increments the aliased field" do
|
58
|
-
person.inte.should eq(6)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "persists the change" do
|
62
|
-
person.reload.inte.should eq(6)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#pop" do
|
67
|
-
|
68
|
-
let(:person) do
|
69
|
-
Person.create(array: [ "test1", "test2" ])
|
70
|
-
end
|
71
|
-
|
72
|
-
before do
|
73
|
-
person.pop(:array, 1)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "removes from the aliased field" do
|
77
|
-
person.array.should eq([ "test1" ])
|
78
|
-
end
|
79
|
-
|
80
|
-
it "persists the change" do
|
81
|
-
person.reload.array.should eq([ "test1" ])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#pull" do
|
86
|
-
|
87
|
-
let(:person) do
|
88
|
-
Person.create(array: [ "test1", "test2" ])
|
89
|
-
end
|
90
|
-
|
91
|
-
before do
|
92
|
-
person.pull(:array, "test1")
|
93
|
-
end
|
94
|
-
|
95
|
-
it "removes from the aliased field" do
|
96
|
-
person.array.should eq([ "test2" ])
|
97
|
-
end
|
98
|
-
|
99
|
-
it "persists the change" do
|
100
|
-
person.reload.array.should eq([ "test2" ])
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#pull_all" do
|
105
|
-
|
106
|
-
let(:person) do
|
107
|
-
Person.create(array: [ "test1", "test2" ])
|
108
|
-
end
|
109
|
-
|
110
|
-
before do
|
111
|
-
person.pull_all(:array, [ "test1", "test2" ])
|
112
|
-
end
|
113
|
-
|
114
|
-
it "removes from the aliased field" do
|
115
|
-
person.array.should be_empty
|
116
|
-
end
|
117
|
-
|
118
|
-
it "persists the change" do
|
119
|
-
person.reload.array.should be_empty
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "#push" do
|
124
|
-
|
125
|
-
let(:person) do
|
126
|
-
Person.create(array: [ "test" ])
|
127
|
-
end
|
128
|
-
|
129
|
-
before do
|
130
|
-
person.push(:array, "testy")
|
131
|
-
end
|
132
|
-
|
133
|
-
it "adds to the aliased field" do
|
134
|
-
person.array.should eq([ "test", "testy" ])
|
135
|
-
end
|
136
|
-
|
137
|
-
it "persists the change" do
|
138
|
-
person.reload.array.should eq([ "test", "testy" ])
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "#push_all" do
|
143
|
-
|
144
|
-
let(:person) do
|
145
|
-
Person.create(array: [ "test" ])
|
146
|
-
end
|
147
|
-
|
148
|
-
before do
|
149
|
-
person.push_all(:array, [ "testy", "test2" ])
|
150
|
-
end
|
151
|
-
|
152
|
-
it "adds to the aliased field" do
|
153
|
-
person.array.should eq([ "test", "testy", "test2" ])
|
154
|
-
end
|
155
|
-
|
156
|
-
it "persists the change" do
|
157
|
-
person.reload.array.should eq([ "test", "testy", "test2" ])
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe "#rename" do
|
162
|
-
|
163
|
-
let(:person) do
|
164
|
-
Person.create(inte: 5)
|
165
|
-
end
|
166
|
-
|
167
|
-
before do
|
168
|
-
person.rename(:inte, :integer)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "renames the aliased field" do
|
172
|
-
person.integer.should eq(5)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "persists the change" do
|
176
|
-
person.reload.integer.should eq(5)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "#set" do
|
181
|
-
|
182
|
-
let(:person) do
|
183
|
-
Person.create(inte: 5)
|
184
|
-
end
|
185
|
-
|
186
|
-
before do
|
187
|
-
person.set(:inte, 8)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "sets the aliased field" do
|
191
|
-
person.inte.should eq(8)
|
192
|
-
end
|
193
|
-
|
194
|
-
it "persists the change" do
|
195
|
-
person.reload.inte.should eq(8)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "#unset" do
|
200
|
-
|
201
|
-
let(:person) do
|
202
|
-
Person.create(inte: 5)
|
203
|
-
end
|
204
|
-
|
205
|
-
before do
|
206
|
-
person.unset(:inte)
|
207
|
-
end
|
208
|
-
|
209
|
-
it "unsets the aliased field" do
|
210
|
-
person.inte.should be_nil
|
211
|
-
end
|
212
|
-
|
213
|
-
it "persists the change" do
|
214
|
-
person.reload.inte.should be_nil
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
if Mongoid::VERSION =~ /\A3\./
|
4
|
+
|
5
|
+
describe Mongoid::Persistence::Atomic do
|
6
|
+
|
7
|
+
context "when using aliased field names" do
|
8
|
+
|
9
|
+
describe "#add_to_set" do
|
10
|
+
|
11
|
+
let(:person) do
|
12
|
+
Person.create(array: [ "test" ])
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
person.add_to_set(:array, "testy")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "adds to the aliased field" do
|
20
|
+
person.array.should eq([ "test", "testy" ])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "persists the change" do
|
24
|
+
person.reload.array.should eq([ "test", "testy" ])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#bit" do
|
29
|
+
|
30
|
+
let(:person) do
|
31
|
+
Person.create(inte: 60)
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
person.bit(:inte, { and: 13 })
|
36
|
+
end
|
37
|
+
|
38
|
+
it "performs the bitwise operation" do
|
39
|
+
person.inte.should eq(12)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "persists the changes" do
|
43
|
+
person.reload.inte.should eq(12)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#inc" do
|
48
|
+
|
49
|
+
let(:person) do
|
50
|
+
Person.create(inte: 5)
|
51
|
+
end
|
52
|
+
|
53
|
+
before do
|
54
|
+
person.inc(:inte, 1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "increments the aliased field" do
|
58
|
+
person.inte.should eq(6)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "persists the change" do
|
62
|
+
person.reload.inte.should eq(6)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#pop" do
|
67
|
+
|
68
|
+
let(:person) do
|
69
|
+
Person.create(array: [ "test1", "test2" ])
|
70
|
+
end
|
71
|
+
|
72
|
+
before do
|
73
|
+
person.pop(:array, 1)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "removes from the aliased field" do
|
77
|
+
person.array.should eq([ "test1" ])
|
78
|
+
end
|
79
|
+
|
80
|
+
it "persists the change" do
|
81
|
+
person.reload.array.should eq([ "test1" ])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#pull" do
|
86
|
+
|
87
|
+
let(:person) do
|
88
|
+
Person.create(array: [ "test1", "test2" ])
|
89
|
+
end
|
90
|
+
|
91
|
+
before do
|
92
|
+
person.pull(:array, "test1")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "removes from the aliased field" do
|
96
|
+
person.array.should eq([ "test2" ])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "persists the change" do
|
100
|
+
person.reload.array.should eq([ "test2" ])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#pull_all" do
|
105
|
+
|
106
|
+
let(:person) do
|
107
|
+
Person.create(array: [ "test1", "test2" ])
|
108
|
+
end
|
109
|
+
|
110
|
+
before do
|
111
|
+
person.pull_all(:array, [ "test1", "test2" ])
|
112
|
+
end
|
113
|
+
|
114
|
+
it "removes from the aliased field" do
|
115
|
+
person.array.should be_empty
|
116
|
+
end
|
117
|
+
|
118
|
+
it "persists the change" do
|
119
|
+
person.reload.array.should be_empty
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#push" do
|
124
|
+
|
125
|
+
let(:person) do
|
126
|
+
Person.create(array: [ "test" ])
|
127
|
+
end
|
128
|
+
|
129
|
+
before do
|
130
|
+
person.push(:array, "testy")
|
131
|
+
end
|
132
|
+
|
133
|
+
it "adds to the aliased field" do
|
134
|
+
person.array.should eq([ "test", "testy" ])
|
135
|
+
end
|
136
|
+
|
137
|
+
it "persists the change" do
|
138
|
+
person.reload.array.should eq([ "test", "testy" ])
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#push_all" do
|
143
|
+
|
144
|
+
let(:person) do
|
145
|
+
Person.create(array: [ "test" ])
|
146
|
+
end
|
147
|
+
|
148
|
+
before do
|
149
|
+
person.push_all(:array, [ "testy", "test2" ])
|
150
|
+
end
|
151
|
+
|
152
|
+
it "adds to the aliased field" do
|
153
|
+
person.array.should eq([ "test", "testy", "test2" ])
|
154
|
+
end
|
155
|
+
|
156
|
+
it "persists the change" do
|
157
|
+
person.reload.array.should eq([ "test", "testy", "test2" ])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#rename" do
|
162
|
+
|
163
|
+
let(:person) do
|
164
|
+
Person.create(inte: 5)
|
165
|
+
end
|
166
|
+
|
167
|
+
before do
|
168
|
+
person.rename(:inte, :integer)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "renames the aliased field" do
|
172
|
+
person.integer.should eq(5)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "persists the change" do
|
176
|
+
person.reload.integer.should eq(5)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "#set" do
|
181
|
+
|
182
|
+
let(:person) do
|
183
|
+
Person.create(inte: 5)
|
184
|
+
end
|
185
|
+
|
186
|
+
before do
|
187
|
+
person.set(:inte, 8)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "sets the aliased field" do
|
191
|
+
person.inte.should eq(8)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "persists the change" do
|
195
|
+
person.reload.inte.should eq(8)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#unset" do
|
200
|
+
|
201
|
+
let(:person) do
|
202
|
+
Person.create(inte: 5)
|
203
|
+
end
|
204
|
+
|
205
|
+
before do
|
206
|
+
person.unset(:inte)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "unsets the aliased field" do
|
210
|
+
person.inte.should be_nil
|
211
|
+
end
|
212
|
+
|
213
|
+
it "persists the change" do
|
214
|
+
person.reload.inte.should be_nil
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|