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