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,81 +1,81 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::PushAll do
6
-
7
- describe "#persist" do
8
-
9
- context "when the field exists" do
10
-
11
- let(:person) do
12
- Person.create(aliases: [ "007" ])
13
- end
14
-
15
- let!(:pushed) do
16
- person.push_all(:aliases, [ "Bond", "James" ])
17
- end
18
-
19
- let(:reloaded) do
20
- person.reload
21
- end
22
-
23
- it "pushes the value onto the array" do
24
- person.aliases.should eq([ "007", "Bond", "James" ])
25
- end
26
-
27
- it "persists the data" do
28
- reloaded.aliases.should eq([ "007", "Bond", "James" ])
29
- end
30
-
31
- it "removes the field from the dirty attributes" do
32
- person.changes["aliases"].should be_nil
33
- end
34
-
35
- it "resets the document dirty flag" do
36
- person.should_not be_changed
37
- end
38
-
39
- it "returns the new array value" do
40
- pushed.should eq([ "007", "Bond", "James" ])
41
- end
42
- end
43
-
44
- context "when the field does not exist" do
45
-
46
- let(:person) do
47
- Person.create
48
- end
49
-
50
- let!(:pushed) do
51
- person.push_all(:aliases, [ "Bond", "James" ])
52
- end
53
-
54
- let(:reloaded) do
55
- person.reload
56
- end
57
-
58
- it "pushes the value onto the array" do
59
- person.aliases.should eq([ "Bond", "James" ])
60
- end
61
-
62
- it "persists the data" do
63
- reloaded.aliases.should eq([ "Bond", "James" ])
64
- end
65
-
66
- it "removes the field from the dirty attributes" do
67
- person.changes["aliases"].should be_nil
68
- end
69
-
70
- it "resets the document dirty flag" do
71
- person.should_not be_changed
72
- end
73
-
74
- it "returns the new array value" do
75
- pushed.should eq([ "Bond", "James" ])
76
- end
77
- end
78
- end
79
- end
80
-
81
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::PushAll do
6
+
7
+ describe "#persist" do
8
+
9
+ context "when the field exists" do
10
+
11
+ let(:person) do
12
+ Person.create(aliases: [ "007" ])
13
+ end
14
+
15
+ let!(:pushed) do
16
+ person.push_all(:aliases, [ "Bond", "James" ])
17
+ end
18
+
19
+ let(:reloaded) do
20
+ person.reload
21
+ end
22
+
23
+ it "pushes the value onto the array" do
24
+ person.aliases.should eq([ "007", "Bond", "James" ])
25
+ end
26
+
27
+ it "persists the data" do
28
+ reloaded.aliases.should eq([ "007", "Bond", "James" ])
29
+ end
30
+
31
+ it "removes the field from the dirty attributes" do
32
+ person.changes["aliases"].should be_nil
33
+ end
34
+
35
+ it "resets the document dirty flag" do
36
+ person.should_not be_changed
37
+ end
38
+
39
+ it "returns the new array value" do
40
+ pushed.should eq([ "007", "Bond", "James" ])
41
+ end
42
+ end
43
+
44
+ context "when the field does not exist" do
45
+
46
+ let(:person) do
47
+ Person.create
48
+ end
49
+
50
+ let!(:pushed) do
51
+ person.push_all(:aliases, [ "Bond", "James" ])
52
+ end
53
+
54
+ let(:reloaded) do
55
+ person.reload
56
+ end
57
+
58
+ it "pushes the value onto the array" do
59
+ person.aliases.should eq([ "Bond", "James" ])
60
+ end
61
+
62
+ it "persists the data" do
63
+ reloaded.aliases.should eq([ "Bond", "James" ])
64
+ end
65
+
66
+ it "removes the field from the dirty attributes" do
67
+ person.changes["aliases"].should be_nil
68
+ end
69
+
70
+ it "resets the document dirty flag" do
71
+ person.should_not be_changed
72
+ end
73
+
74
+ it "returns the new array value" do
75
+ pushed.should eq([ "Bond", "James" ])
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ end
@@ -1,81 +1,81 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::Push do
6
-
7
- describe "#persist" do
8
-
9
- context "when the field exists" do
10
-
11
- let(:person) do
12
- Person.create(aliases: [ "007" ])
13
- end
14
-
15
- let!(:pushed) do
16
- person.push(:aliases, "Bond")
17
- end
18
-
19
- let(:reloaded) do
20
- person.reload
21
- end
22
-
23
- it "pushes the value onto the array" do
24
- person.aliases.should eq([ "007", "Bond" ])
25
- end
26
-
27
- it "persists the data" do
28
- reloaded.aliases.should eq([ "007", "Bond" ])
29
- end
30
-
31
- it "removes the field from the dirty attributes" do
32
- person.changes["aliases"].should be_nil
33
- end
34
-
35
- it "resets the document dirty flag" do
36
- person.should_not be_changed
37
- end
38
-
39
- it "returns the new array value" do
40
- pushed.should eq([ "007", "Bond" ])
41
- end
42
- end
43
-
44
- context "when the field does not exist" do
45
-
46
- let(:person) do
47
- Person.create
48
- end
49
-
50
- let!(:pushed) do
51
- person.push(:aliases, "Bond")
52
- end
53
-
54
- let(:reloaded) do
55
- person.reload
56
- end
57
-
58
- it "pushes the value onto the array" do
59
- person.aliases.should eq([ "Bond" ])
60
- end
61
-
62
- it "persists the data" do
63
- reloaded.aliases.should eq([ "Bond" ])
64
- end
65
-
66
- it "removes the field from the dirty attributes" do
67
- person.changes["aliases"].should be_nil
68
- end
69
-
70
- it "resets the document dirty flag" do
71
- person.should_not be_changed
72
- end
73
-
74
- it "returns the new array value" do
75
- pushed.should eq([ "Bond" ])
76
- end
77
- end
78
- end
79
- end
80
-
81
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::Push do
6
+
7
+ describe "#persist" do
8
+
9
+ context "when the field exists" do
10
+
11
+ let(:person) do
12
+ Person.create(aliases: [ "007" ])
13
+ end
14
+
15
+ let!(:pushed) do
16
+ person.push(:aliases, "Bond")
17
+ end
18
+
19
+ let(:reloaded) do
20
+ person.reload
21
+ end
22
+
23
+ it "pushes the value onto the array" do
24
+ person.aliases.should eq([ "007", "Bond" ])
25
+ end
26
+
27
+ it "persists the data" do
28
+ reloaded.aliases.should eq([ "007", "Bond" ])
29
+ end
30
+
31
+ it "removes the field from the dirty attributes" do
32
+ person.changes["aliases"].should be_nil
33
+ end
34
+
35
+ it "resets the document dirty flag" do
36
+ person.should_not be_changed
37
+ end
38
+
39
+ it "returns the new array value" do
40
+ pushed.should eq([ "007", "Bond" ])
41
+ end
42
+ end
43
+
44
+ context "when the field does not exist" do
45
+
46
+ let(:person) do
47
+ Person.create
48
+ end
49
+
50
+ let!(:pushed) do
51
+ person.push(:aliases, "Bond")
52
+ end
53
+
54
+ let(:reloaded) do
55
+ person.reload
56
+ end
57
+
58
+ it "pushes the value onto the array" do
59
+ person.aliases.should eq([ "Bond" ])
60
+ end
61
+
62
+ it "persists the data" do
63
+ reloaded.aliases.should eq([ "Bond" ])
64
+ end
65
+
66
+ it "removes the field from the dirty attributes" do
67
+ person.changes["aliases"].should be_nil
68
+ end
69
+
70
+ it "resets the document dirty flag" do
71
+ person.should_not be_changed
72
+ end
73
+
74
+ it "returns the new array value" do
75
+ pushed.should eq([ "Bond" ])
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ end
@@ -1,46 +1,46 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::Rename do
6
-
7
- describe "#rename" do
8
-
9
- context "when incrementing a field with a value" do
10
-
11
- let(:person) do
12
- Person.create(age: 100)
13
- end
14
-
15
- let!(:rename) do
16
- person.rename(:age, :years)
17
- end
18
-
19
- it "removes the old field" do
20
- person.age.should be_nil
21
- end
22
-
23
- it "adds the new field" do
24
- person.years.should eq(100)
25
- end
26
-
27
- it "returns the value" do
28
- rename.should eq(100)
29
- end
30
-
31
- it "resets the old dirty attributes" do
32
- person.changes["age"].should be_nil
33
- end
34
-
35
- it "resets the new field dirty attributes" do
36
- person.changes["years"].should be_nil
37
- end
38
-
39
- it "persists the changes" do
40
- person.reload.years.should eq(100)
41
- end
42
- end
43
- end
44
- end
45
-
46
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::Rename do
6
+
7
+ describe "#rename" do
8
+
9
+ context "when incrementing a field with a value" do
10
+
11
+ let(:person) do
12
+ Person.create(age: 100)
13
+ end
14
+
15
+ let!(:rename) do
16
+ person.rename(:age, :years)
17
+ end
18
+
19
+ it "removes the old field" do
20
+ person.age.should be_nil
21
+ end
22
+
23
+ it "adds the new field" do
24
+ person.years.should eq(100)
25
+ end
26
+
27
+ it "returns the value" do
28
+ rename.should eq(100)
29
+ end
30
+
31
+ it "resets the old dirty attributes" do
32
+ person.changes["age"].should be_nil
33
+ end
34
+
35
+ it "resets the new field dirty attributes" do
36
+ person.changes["years"].should be_nil
37
+ end
38
+
39
+ it "persists the changes" do
40
+ person.reload.years.should eq(100)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -1,158 +1,158 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe Mongoid::Persistence::Atomic::Sets do
6
-
7
- describe "#set" do
8
-
9
- let(:person) do
10
- Person.create(age: 100, pets: true)
11
- end
12
-
13
- let(:reloaded) do
14
- person.reload
15
- end
16
-
17
- context "when setting 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!(:set) do
24
- address.set(:number, 5)
25
- end
26
-
27
- it "sets the provided value" do
28
- set.should eq(5)
29
- end
30
-
31
- it "persists the change" do
32
- reloaded.addresses.first.number.should eq(5)
33
- end
34
- end
35
-
36
- context "when setting a field with a value" do
37
-
38
- let!(:set) do
39
- person.set(:age, 2)
40
- end
41
-
42
- it "sets the provided value" do
43
- person.age.should eq(2)
44
- end
45
-
46
- it "returns the new value" do
47
- set.should eq(2)
48
- end
49
-
50
- it "persists the changes" do
51
- reloaded.age.should eq(2)
52
- end
53
-
54
- it "resets the dirty attributes" do
55
- person.changes["age"].should be_nil
56
- end
57
- end
58
-
59
- context "when setting a field with a value that must be cast" do
60
-
61
- let(:date_time) do
62
- DateTime.new(2012, 1, 2)
63
- end
64
-
65
- let!(:set) do
66
- person.set(:lunch_time, date_time)
67
- end
68
-
69
- it "sets the provided value" do
70
- person.lunch_time.should eq(date_time)
71
- end
72
-
73
- it "returns the new value" do
74
- set.should eq(date_time)
75
- end
76
-
77
- it "persists the changes" do
78
- reloaded.lunch_time.should eq(date_time)
79
- end
80
-
81
- it "resets the dirty attributes" do
82
- person.changes["lunch_time"].should be_nil
83
- end
84
- end
85
-
86
- context "when setting a field to false" do
87
-
88
- let!(:set) do
89
- person.set(:pets, false)
90
- end
91
-
92
- it "sets the provided value" do
93
- person.pets.should be false
94
- end
95
-
96
- it "returns the new value" do
97
- set.should be false
98
- end
99
-
100
- it "persists the changes" do
101
- reloaded.pets.should be false
102
- end
103
-
104
- it "resets the dirty attributes" do
105
- person.changes["pets"].should be_nil
106
- end
107
-
108
- end
109
-
110
- context "when setting a nil field" do
111
-
112
- let!(:set) do
113
- person.set(:score, 2)
114
- end
115
-
116
- it "sets the value to the provided number" do
117
- person.score.should eq(2)
118
- end
119
-
120
- it "returns the new value" do
121
- set.should eq(2)
122
- end
123
-
124
- it "persists the changes" do
125
- reloaded.score.should eq(2)
126
- end
127
-
128
- it "resets the dirty attributes" do
129
- person.changes["score"].should be_nil
130
- end
131
- end
132
-
133
- context "when setting a non existant field" do
134
-
135
- let!(:set) do
136
- person.set(:high_score, 5)
137
- end
138
-
139
- it "sets the value to the provided number" do
140
- person.high_score.should eq(5)
141
- end
142
-
143
- it "returns the new value" do
144
- set.should eq(5)
145
- end
146
-
147
- it "persists the changes" do
148
- reloaded.high_score.should eq(5)
149
- end
150
-
151
- it "resets the dirty attributes" do
152
- person.changes["high_score"].should be_nil
153
- end
154
- end
155
- end
156
- end
157
-
158
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe Mongoid::Persistence::Atomic::Sets do
6
+
7
+ describe "#set" do
8
+
9
+ let(:person) do
10
+ Person.create(age: 100, pets: true)
11
+ end
12
+
13
+ let(:reloaded) do
14
+ person.reload
15
+ end
16
+
17
+ context "when setting 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!(:set) do
24
+ address.set(:number, 5)
25
+ end
26
+
27
+ it "sets the provided value" do
28
+ set.should eq(5)
29
+ end
30
+
31
+ it "persists the change" do
32
+ reloaded.addresses.first.number.should eq(5)
33
+ end
34
+ end
35
+
36
+ context "when setting a field with a value" do
37
+
38
+ let!(:set) do
39
+ person.set(:age, 2)
40
+ end
41
+
42
+ it "sets the provided value" do
43
+ person.age.should eq(2)
44
+ end
45
+
46
+ it "returns the new value" do
47
+ set.should eq(2)
48
+ end
49
+
50
+ it "persists the changes" do
51
+ reloaded.age.should eq(2)
52
+ end
53
+
54
+ it "resets the dirty attributes" do
55
+ person.changes["age"].should be_nil
56
+ end
57
+ end
58
+
59
+ context "when setting a field with a value that must be cast" do
60
+
61
+ let(:date_time) do
62
+ DateTime.new(2012, 1, 2)
63
+ end
64
+
65
+ let!(:set) do
66
+ person.set(:lunch_time, date_time)
67
+ end
68
+
69
+ it "sets the provided value" do
70
+ person.lunch_time.should eq(date_time)
71
+ end
72
+
73
+ it "returns the new value" do
74
+ set.should eq(date_time)
75
+ end
76
+
77
+ it "persists the changes" do
78
+ reloaded.lunch_time.should eq(date_time)
79
+ end
80
+
81
+ it "resets the dirty attributes" do
82
+ person.changes["lunch_time"].should be_nil
83
+ end
84
+ end
85
+
86
+ context "when setting a field to false" do
87
+
88
+ let!(:set) do
89
+ person.set(:pets, false)
90
+ end
91
+
92
+ it "sets the provided value" do
93
+ person.pets.should be false
94
+ end
95
+
96
+ it "returns the new value" do
97
+ set.should be false
98
+ end
99
+
100
+ it "persists the changes" do
101
+ reloaded.pets.should be false
102
+ end
103
+
104
+ it "resets the dirty attributes" do
105
+ person.changes["pets"].should be_nil
106
+ end
107
+
108
+ end
109
+
110
+ context "when setting a nil field" do
111
+
112
+ let!(:set) do
113
+ person.set(:score, 2)
114
+ end
115
+
116
+ it "sets the value to the provided number" do
117
+ person.score.should eq(2)
118
+ end
119
+
120
+ it "returns the new value" do
121
+ set.should eq(2)
122
+ end
123
+
124
+ it "persists the changes" do
125
+ reloaded.score.should eq(2)
126
+ end
127
+
128
+ it "resets the dirty attributes" do
129
+ person.changes["score"].should be_nil
130
+ end
131
+ end
132
+
133
+ context "when setting a non existant field" do
134
+
135
+ let!(:set) do
136
+ person.set(:high_score, 5)
137
+ end
138
+
139
+ it "sets the value to the provided number" do
140
+ person.high_score.should eq(5)
141
+ end
142
+
143
+ it "returns the new value" do
144
+ set.should eq(5)
145
+ end
146
+
147
+ it "persists the changes" do
148
+ reloaded.high_score.should eq(5)
149
+ end
150
+
151
+ it "resets the dirty attributes" do
152
+ person.changes["high_score"].should be_nil
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ end