mongoid_monkey 0.2.0 → 0.2.1

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.
@@ -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