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
@@ -1,92 +1,92 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::Bit do
6
-
7
- describe "#bit" do
8
-
9
- let(:person) do
10
- Person.create(age: 60)
11
- end
12
-
13
- let(:reloaded) do
14
- person.reload
15
- end
16
-
17
- context "when performing a bitwise and" do
18
-
19
- let!(:bit) do
20
- person.bit(:age, { and: 13 })
21
- end
22
-
23
- it "performs the bitwise operation" do
24
- person.age.should eq(12)
25
- end
26
-
27
- it "returns the new value" do
28
- bit.should eq(12)
29
- end
30
-
31
- it "persists the changes" do
32
- reloaded.age.should eq(12)
33
- end
34
-
35
- it "resets the dirty attributes" do
36
- person.changes["age"].should be_nil
37
- end
38
- end
39
-
40
- context "when performing a bitwise or" do
41
-
42
- let!(:bit) do
43
- person.bit(:age, { or: 13 })
44
- end
45
-
46
- it "performs the bitwise operation" do
47
- person.age.should eq(61)
48
- end
49
-
50
- it "returns the new value" do
51
- bit.should eq(61)
52
- end
53
-
54
- it "persists the changes" do
55
- reloaded.age.should eq(61)
56
- end
57
-
58
- it "resets the dirty attributes" do
59
- person.changes["age"].should be_nil
60
- end
61
- end
62
-
63
- context "when chaining bitwise operations" do
64
-
65
- let(:hash) do
66
- { and: 13, or: 10 }
67
- end
68
-
69
- let!(:bit) do
70
- person.bit(:age, hash)
71
- end
72
-
73
- it "performs the bitwise operation" do
74
- person.age.should eq(14)
75
- end
76
-
77
- it "returns the new value" do
78
- bit.should eq(14)
79
- end
80
-
81
- it "persists the changes" do
82
- reloaded.age.should eq(14)
83
- end
84
-
85
- it "resets the dirty attributes" do
86
- person.changes["age"].should be_nil
87
- end
88
- end
89
- end
90
- end
91
-
92
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::Bit do
6
+
7
+ describe "#bit" do
8
+
9
+ let(:person) do
10
+ Person.create(age: 60)
11
+ end
12
+
13
+ let(:reloaded) do
14
+ person.reload
15
+ end
16
+
17
+ context "when performing a bitwise and" do
18
+
19
+ let!(:bit) do
20
+ person.bit(:age, { and: 13 })
21
+ end
22
+
23
+ it "performs the bitwise operation" do
24
+ person.age.should eq(12)
25
+ end
26
+
27
+ it "returns the new value" do
28
+ bit.should eq(12)
29
+ end
30
+
31
+ it "persists the changes" do
32
+ reloaded.age.should eq(12)
33
+ end
34
+
35
+ it "resets the dirty attributes" do
36
+ person.changes["age"].should be_nil
37
+ end
38
+ end
39
+
40
+ context "when performing a bitwise or" do
41
+
42
+ let!(:bit) do
43
+ person.bit(:age, { or: 13 })
44
+ end
45
+
46
+ it "performs the bitwise operation" do
47
+ person.age.should eq(61)
48
+ end
49
+
50
+ it "returns the new value" do
51
+ bit.should eq(61)
52
+ end
53
+
54
+ it "persists the changes" do
55
+ reloaded.age.should eq(61)
56
+ end
57
+
58
+ it "resets the dirty attributes" do
59
+ person.changes["age"].should be_nil
60
+ end
61
+ end
62
+
63
+ context "when chaining bitwise operations" do
64
+
65
+ let(:hash) do
66
+ { and: 13, or: 10 }
67
+ end
68
+
69
+ let!(:bit) do
70
+ person.bit(:age, hash)
71
+ end
72
+
73
+ it "performs the bitwise operation" do
74
+ person.age.should eq(14)
75
+ end
76
+
77
+ it "returns the new value" do
78
+ bit.should eq(14)
79
+ end
80
+
81
+ it "persists the changes" do
82
+ reloaded.age.should eq(14)
83
+ end
84
+
85
+ it "resets the dirty attributes" do
86
+ person.changes["age"].should be_nil
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ end
@@ -1,137 +1,137 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::Inc do
6
-
7
- describe "#inc" do
8
-
9
- let(:person) do
10
- Person.create(age: 100)
11
- end
12
-
13
- let(:reloaded) do
14
- person.reload
15
- end
16
-
17
- context "when incrementing a field on an embedded document" do
18
-
19
- let(:address) do
20
- person.addresses.create(street: "Tauentzienstr", number: 5)
21
- end
22
-
23
- let!(:inced) do
24
- address.inc(:number, 5)
25
- end
26
-
27
- it "increments the provided value" do
28
- inced.should eq(10)
29
- end
30
-
31
- it "persists the change" do
32
- reloaded.addresses.first.number.should eq(10)
33
- end
34
- end
35
-
36
- context "when incrementing a field with a value" do
37
-
38
- context "when provided an integer" do
39
-
40
- let!(:inced) do
41
- person.inc(:age, 2)
42
- end
43
-
44
- it "increments by the provided value" do
45
- person.age.should eq(102)
46
- end
47
-
48
- it "returns the new value" do
49
- inced.should eq(102)
50
- end
51
-
52
- it "persists the changes" do
53
- reloaded.age.should eq(102)
54
- end
55
-
56
- it "keeps the field as an integer" do
57
- inced.should be_a(Integer)
58
- end
59
-
60
- it "resets the dirty attributes" do
61
- person.changes["age"].should be_nil
62
- end
63
- end
64
-
65
- context "when provided a big decimal" do
66
-
67
- let!(:inced) do
68
- person.inc(:blood_alcohol_content, BigDecimal.new("2.2"))
69
- end
70
-
71
- it "increments by the provided value" do
72
- person.blood_alcohol_content.should eq(2.2)
73
- end
74
-
75
- it "returns the new value" do
76
- inced.should eq(2.2)
77
- end
78
-
79
- it "persists the changes" do
80
- reloaded.blood_alcohol_content.should eq(2.2)
81
- end
82
-
83
- it "resets the dirty attributes" do
84
- person.changes["blood_alcohol_content"].should be_nil
85
- end
86
- end
87
- end
88
-
89
- context "when incrementing a nil field" do
90
-
91
- let!(:inced) do
92
- person.inc(:score, 2)
93
- end
94
-
95
- it "sets the value to the provided number" do
96
- person.score.should eq(2)
97
- end
98
-
99
- it "returns the new value" do
100
- inced.should eq(2)
101
- end
102
-
103
- it "persists the changes" do
104
- reloaded.score.should eq(2)
105
- end
106
-
107
- it "resets the dirty attributes" do
108
- person.changes["score"].should be_nil
109
- end
110
- end
111
-
112
- context "when incrementing a non existant field" do
113
-
114
- let!(:inced) do
115
- person.inc(:high_score, 5)
116
- end
117
-
118
- it "sets the value to the provided number" do
119
- person.high_score.should eq(5)
120
- end
121
-
122
- it "returns the new value" do
123
- inced.should eq(5)
124
- end
125
-
126
- it "persists the changes" do
127
- reloaded.high_score.should eq(5)
128
- end
129
-
130
- it "resets the dirty attributes" do
131
- person.changes["high_score"].should be_nil
132
- end
133
- end
134
- end
135
- end
136
-
137
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::Inc do
6
+
7
+ describe "#inc" do
8
+
9
+ let(:person) do
10
+ Person.create(age: 100)
11
+ end
12
+
13
+ let(:reloaded) do
14
+ person.reload
15
+ end
16
+
17
+ context "when incrementing a field on an embedded document" do
18
+
19
+ let(:address) do
20
+ person.addresses.create(street: "Tauentzienstr", number: 5)
21
+ end
22
+
23
+ let!(:inced) do
24
+ address.inc(:number, 5)
25
+ end
26
+
27
+ it "increments the provided value" do
28
+ inced.should eq(10)
29
+ end
30
+
31
+ it "persists the change" do
32
+ reloaded.addresses.first.number.should eq(10)
33
+ end
34
+ end
35
+
36
+ context "when incrementing a field with a value" do
37
+
38
+ context "when provided an integer" do
39
+
40
+ let!(:inced) do
41
+ person.inc(:age, 2)
42
+ end
43
+
44
+ it "increments by the provided value" do
45
+ person.age.should eq(102)
46
+ end
47
+
48
+ it "returns the new value" do
49
+ inced.should eq(102)
50
+ end
51
+
52
+ it "persists the changes" do
53
+ reloaded.age.should eq(102)
54
+ end
55
+
56
+ it "keeps the field as an integer" do
57
+ inced.should be_a(Integer)
58
+ end
59
+
60
+ it "resets the dirty attributes" do
61
+ person.changes["age"].should be_nil
62
+ end
63
+ end
64
+
65
+ context "when provided a big decimal" do
66
+
67
+ let!(:inced) do
68
+ person.inc(:blood_alcohol_content, BigDecimal.new("2.2"))
69
+ end
70
+
71
+ it "increments by the provided value" do
72
+ person.blood_alcohol_content.should eq(2.2)
73
+ end
74
+
75
+ it "returns the new value" do
76
+ inced.should eq(2.2)
77
+ end
78
+
79
+ it "persists the changes" do
80
+ reloaded.blood_alcohol_content.should eq(2.2)
81
+ end
82
+
83
+ it "resets the dirty attributes" do
84
+ person.changes["blood_alcohol_content"].should be_nil
85
+ end
86
+ end
87
+ end
88
+
89
+ context "when incrementing a nil field" do
90
+
91
+ let!(:inced) do
92
+ person.inc(:score, 2)
93
+ end
94
+
95
+ it "sets the value to the provided number" do
96
+ person.score.should eq(2)
97
+ end
98
+
99
+ it "returns the new value" do
100
+ inced.should eq(2)
101
+ end
102
+
103
+ it "persists the changes" do
104
+ reloaded.score.should eq(2)
105
+ end
106
+
107
+ it "resets the dirty attributes" do
108
+ person.changes["score"].should be_nil
109
+ end
110
+ end
111
+
112
+ context "when incrementing a non existant field" do
113
+
114
+ let!(:inced) do
115
+ person.inc(:high_score, 5)
116
+ end
117
+
118
+ it "sets the value to the provided number" do
119
+ person.high_score.should eq(5)
120
+ end
121
+
122
+ it "returns the new value" do
123
+ inced.should eq(5)
124
+ end
125
+
126
+ it "persists the changes" do
127
+ reloaded.high_score.should eq(5)
128
+ end
129
+
130
+ it "resets the dirty attributes" do
131
+ person.changes["high_score"].should be_nil
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ end