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,139 +1,139 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe 'Mongoid::Persistable::Renamable' do
6
-
7
- describe "#rename" do
8
-
9
- context "when the document is a root document" do
10
-
11
- shared_examples_for "a renamable root document" do
12
-
13
- it "renames the first field" do
14
- expect(person.salutation).to eq("sir")
15
- end
16
-
17
- it "removes the first original value" do
18
- expect(person.title).to be_nil
19
- end
20
-
21
- it "renames the second field" do
22
- expect(person.date_of_birth.to_date).to eq(date)
23
- end
24
-
25
- it "removes the second original value" do
26
- expect(person.dob).to be_nil
27
- end
28
-
29
- it "returns self object" do
30
- expect(rename).to eq(person)
31
- end
32
-
33
- it "persists the first rename" do
34
- expect(person.reload.salutation).to eq("sir")
35
- end
36
-
37
- it "persists the first original removal" do
38
- expect(person.reload.title).to be_nil
39
- end
40
-
41
- it "persists the second rename" do
42
- expect(person.reload.date_of_birth.to_date).to eq(date)
43
- end
44
-
45
- it "persists the second original removal" do
46
- expect(person.reload.dob).to be_nil
47
- end
48
-
49
- it "clears out the dirty changes" do
50
- expect(person).to_not be_changed
51
- end
52
- end
53
-
54
- let(:date) do
55
- Date.new(2013, 1, 1)
56
- end
57
-
58
- let(:person) do
59
- Person.create(title: "sir", dob: date)
60
- end
61
-
62
- context "when provided symbol names" do
63
-
64
- let!(:rename) do
65
- person.rename(title: :salutation, dob: :date_of_birth)
66
- end
67
-
68
- it_behaves_like "a renamable root document"
69
- end
70
-
71
- context "when provided string names" do
72
-
73
- let!(:rename) do
74
- person.rename(title: "salutation", dob: "date_of_birth")
75
- end
76
-
77
- it_behaves_like "a renamable root document"
78
- end
79
- end
80
-
81
- context "when the document is embedded" do
82
-
83
- shared_examples_for "a renamable embedded document" do
84
-
85
- it "renames the first field" do
86
- expect(name.mi).to eq("blah")
87
- end
88
-
89
- it "removes the first original value" do
90
- expect(name.middle).to be_nil
91
- end
92
-
93
- it "returns self object" do
94
- expect(rename).to eq(name)
95
- end
96
-
97
- it "persists the first rename" do
98
- expect(name.reload.mi).to eq("blah")
99
- end
100
-
101
- it "persists the first original removal" do
102
- expect(name.reload.middle).to be_nil
103
- end
104
-
105
- it "clears out the dirty changes" do
106
- expect(name).to_not be_changed
107
- end
108
- end
109
-
110
- let(:person) do
111
- Person.create
112
- end
113
-
114
- let(:name) do
115
- person.create_name(first_name: "test", last_name: "user", middle: "blah")
116
- end
117
-
118
- context "when provided symbol names" do
119
-
120
- let!(:rename) do
121
- name.rename(middle: :mi)
122
- end
123
-
124
- it_behaves_like "a renamable embedded document"
125
- end
126
-
127
- context "when provided string names" do
128
-
129
- let!(:rename) do
130
- name.rename(middle: "mi")
131
- end
132
-
133
- it_behaves_like "a renamable embedded document"
134
- end
135
- end
136
- end
137
- end
138
-
139
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe 'Mongoid::Persistable::Renamable' do
6
+
7
+ describe "#rename" do
8
+
9
+ context "when the document is a root document" do
10
+
11
+ shared_examples_for "a renamable root document" do
12
+
13
+ it "renames the first field" do
14
+ expect(person.salutation).to eq("sir")
15
+ end
16
+
17
+ it "removes the first original value" do
18
+ expect(person.title).to be_nil
19
+ end
20
+
21
+ it "renames the second field" do
22
+ expect(person.date_of_birth.to_date).to eq(date)
23
+ end
24
+
25
+ it "removes the second original value" do
26
+ expect(person.dob).to be_nil
27
+ end
28
+
29
+ it "returns self object" do
30
+ expect(rename).to eq(person)
31
+ end
32
+
33
+ it "persists the first rename" do
34
+ expect(person.reload.salutation).to eq("sir")
35
+ end
36
+
37
+ it "persists the first original removal" do
38
+ expect(person.reload.title).to be_nil
39
+ end
40
+
41
+ it "persists the second rename" do
42
+ expect(person.reload.date_of_birth.to_date).to eq(date)
43
+ end
44
+
45
+ it "persists the second original removal" do
46
+ expect(person.reload.dob).to be_nil
47
+ end
48
+
49
+ it "clears out the dirty changes" do
50
+ expect(person).to_not be_changed
51
+ end
52
+ end
53
+
54
+ let(:date) do
55
+ Date.new(2013, 1, 1)
56
+ end
57
+
58
+ let(:person) do
59
+ Person.create(title: "sir", dob: date)
60
+ end
61
+
62
+ context "when provided symbol names" do
63
+
64
+ let!(:rename) do
65
+ person.rename(title: :salutation, dob: :date_of_birth)
66
+ end
67
+
68
+ it_behaves_like "a renamable root document"
69
+ end
70
+
71
+ context "when provided string names" do
72
+
73
+ let!(:rename) do
74
+ person.rename(title: "salutation", dob: "date_of_birth")
75
+ end
76
+
77
+ it_behaves_like "a renamable root document"
78
+ end
79
+ end
80
+
81
+ context "when the document is embedded" do
82
+
83
+ shared_examples_for "a renamable embedded document" do
84
+
85
+ it "renames the first field" do
86
+ expect(name.mi).to eq("blah")
87
+ end
88
+
89
+ it "removes the first original value" do
90
+ expect(name.middle).to be_nil
91
+ end
92
+
93
+ it "returns self object" do
94
+ expect(rename).to eq(name)
95
+ end
96
+
97
+ it "persists the first rename" do
98
+ expect(name.reload.mi).to eq("blah")
99
+ end
100
+
101
+ it "persists the first original removal" do
102
+ expect(name.reload.middle).to be_nil
103
+ end
104
+
105
+ it "clears out the dirty changes" do
106
+ expect(name).to_not be_changed
107
+ end
108
+ end
109
+
110
+ let(:person) do
111
+ Person.create
112
+ end
113
+
114
+ let(:name) do
115
+ person.create_name(first_name: "test", last_name: "user", middle: "blah")
116
+ end
117
+
118
+ context "when provided symbol names" do
119
+
120
+ let!(:rename) do
121
+ name.rename(middle: :mi)
122
+ end
123
+
124
+ it_behaves_like "a renamable embedded document"
125
+ end
126
+
127
+ context "when provided string names" do
128
+
129
+ let!(:rename) do
130
+ name.rename(middle: "mi")
131
+ end
132
+
133
+ it_behaves_like "a renamable embedded document"
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ end
@@ -1,172 +1,172 @@
1
- require "spec_helper"
2
-
3
- if Mongoid::VERSION =~ /\A3\./
4
-
5
- describe 'Mongoid::Persistable::Settable' do
6
-
7
- describe "#set" do
8
-
9
- context "when the document is a root document" do
10
-
11
- shared_examples_for "a settable root document" do
12
-
13
- it "sets the normal field to the new value" do
14
- expect(person.title).to eq("kaiser")
15
- end
16
-
17
- it "properly sets aliased fields" do
18
- expect(person.test).to eq("alias-test")
19
- end
20
-
21
- it "casts fields that need typecasting" do
22
- expect(person.dob).to eq(date)
23
- end
24
-
25
- it "returns self object" do
26
- expect(set).to eq(person)
27
- end
28
-
29
- it "persists the normal field set" do
30
- expect(person.reload.title).to eq("kaiser")
31
- end
32
-
33
- it "persists sets on aliased fields" do
34
- expect(person.reload.test).to eq("alias-test")
35
- end
36
-
37
- it "persists fields that need typecasting" do
38
- expect(person.reload.dob).to eq(date)
39
- end
40
-
41
- it "resets the dirty attributes for the sets" do
42
- expect(person).to_not be_changed
43
- end
44
- end
45
-
46
- let(:person) do
47
- Person.create
48
- end
49
-
50
- let(:date) do
51
- Date.new(1976, 11, 19)
52
- end
53
-
54
- context "when provided string fields" do
55
-
56
- let!(:set) do
57
- person.set("title" => "kaiser", "test" => "alias-test", "dob" => date)
58
- end
59
-
60
- it_behaves_like "a settable root document"
61
- end
62
-
63
- context "when provided symbol fields" do
64
-
65
- let!(:set) do
66
- person.set(title: "kaiser", test: "alias-test", dob: date)
67
- end
68
-
69
- it_behaves_like "a settable root document"
70
- end
71
- end
72
-
73
- context "when the document is embedded" do
74
-
75
- shared_examples_for "a settable embedded document" do
76
-
77
- it "sets the normal field to the new value" do
78
- expect(address.number).to eq(44)
79
- end
80
-
81
- it "properly sets aliased fields" do
82
- expect(address.suite).to eq("400")
83
- end
84
-
85
- it "casts fields that need typecasting" do
86
- expect(address.end_date).to eq(date)
87
- end
88
-
89
- it "returns self object" do
90
- expect(set).to eq(address)
91
- end
92
-
93
- it "persists the normal field set" do
94
- expect(address.reload.number).to eq(44)
95
- end
96
-
97
- it "persists the aliased field set" do
98
- expect(address.reload.suite).to eq("400")
99
- end
100
-
101
- it "persists the fields that need typecasting" do
102
- expect(address.reload.end_date).to eq(date)
103
- end
104
-
105
- it "resets the dirty attributes for the sets" do
106
- expect(address).to_not be_changed
107
- end
108
- end
109
-
110
- let(:person) do
111
- Person.create
112
- end
113
-
114
- let(:address) do
115
- person.addresses.create(street: "t")
116
- end
117
-
118
- let(:date) do
119
- Date.new(1976, 11, 19)
120
- end
121
-
122
- context "when provided string fields" do
123
-
124
- let!(:set) do
125
- address.set("number" => 44, "suite" => "400", "end_date" => date)
126
- end
127
-
128
- it_behaves_like "a settable embedded document"
129
- end
130
-
131
- context "when provided symbol fields" do
132
-
133
- let!(:set) do
134
- address.set(number: 44, suite: "400", end_date: date)
135
- end
136
-
137
- it_behaves_like "a settable embedded document"
138
- end
139
- end
140
- end
141
-
142
- context "when dynamic attributes are not enabled" do
143
- let(:account) do
144
- Account.create
145
- end
146
-
147
- around do |example|
148
- Mongoid.allow_dynamic_fields = false
149
- example.run
150
- Mongoid.allow_dynamic_fields = true
151
- end
152
-
153
- it "raises exception for an unknown attribute " do
154
- expect {
155
- account.set(somethingnew: "somethingnew")
156
- }.to raise_error(Mongoid::Errors::UnknownAttribute)
157
- end
158
- end
159
-
160
- context "when dynamic attributes enabled" do
161
- let(:person) do
162
- Person.create
163
- end
164
-
165
- it "updates non existing attribute" do
166
- person.set(somethingnew: "somethingnew")
167
- expect(person.reload.somethingnew).to eq "somethingnew"
168
- end
169
- end
170
- end
171
-
172
- end
1
+ require "spec_helper"
2
+
3
+ if Mongoid::VERSION =~ /\A3\./
4
+
5
+ describe 'Mongoid::Persistable::Settable' do
6
+
7
+ describe "#set" do
8
+
9
+ context "when the document is a root document" do
10
+
11
+ shared_examples_for "a settable root document" do
12
+
13
+ it "sets the normal field to the new value" do
14
+ expect(person.title).to eq("kaiser")
15
+ end
16
+
17
+ it "properly sets aliased fields" do
18
+ expect(person.test).to eq("alias-test")
19
+ end
20
+
21
+ it "casts fields that need typecasting" do
22
+ expect(person.dob).to eq(date)
23
+ end
24
+
25
+ it "returns self object" do
26
+ expect(set).to eq(person)
27
+ end
28
+
29
+ it "persists the normal field set" do
30
+ expect(person.reload.title).to eq("kaiser")
31
+ end
32
+
33
+ it "persists sets on aliased fields" do
34
+ expect(person.reload.test).to eq("alias-test")
35
+ end
36
+
37
+ it "persists fields that need typecasting" do
38
+ expect(person.reload.dob).to eq(date)
39
+ end
40
+
41
+ it "resets the dirty attributes for the sets" do
42
+ expect(person).to_not be_changed
43
+ end
44
+ end
45
+
46
+ let(:person) do
47
+ Person.create
48
+ end
49
+
50
+ let(:date) do
51
+ Date.new(1976, 11, 19)
52
+ end
53
+
54
+ context "when provided string fields" do
55
+
56
+ let!(:set) do
57
+ person.set("title" => "kaiser", "test" => "alias-test", "dob" => date)
58
+ end
59
+
60
+ it_behaves_like "a settable root document"
61
+ end
62
+
63
+ context "when provided symbol fields" do
64
+
65
+ let!(:set) do
66
+ person.set(title: "kaiser", test: "alias-test", dob: date)
67
+ end
68
+
69
+ it_behaves_like "a settable root document"
70
+ end
71
+ end
72
+
73
+ context "when the document is embedded" do
74
+
75
+ shared_examples_for "a settable embedded document" do
76
+
77
+ it "sets the normal field to the new value" do
78
+ expect(address.number).to eq(44)
79
+ end
80
+
81
+ it "properly sets aliased fields" do
82
+ expect(address.suite).to eq("400")
83
+ end
84
+
85
+ it "casts fields that need typecasting" do
86
+ expect(address.end_date).to eq(date)
87
+ end
88
+
89
+ it "returns self object" do
90
+ expect(set).to eq(address)
91
+ end
92
+
93
+ it "persists the normal field set" do
94
+ expect(address.reload.number).to eq(44)
95
+ end
96
+
97
+ it "persists the aliased field set" do
98
+ expect(address.reload.suite).to eq("400")
99
+ end
100
+
101
+ it "persists the fields that need typecasting" do
102
+ expect(address.reload.end_date).to eq(date)
103
+ end
104
+
105
+ it "resets the dirty attributes for the sets" do
106
+ expect(address).to_not be_changed
107
+ end
108
+ end
109
+
110
+ let(:person) do
111
+ Person.create
112
+ end
113
+
114
+ let(:address) do
115
+ person.addresses.create(street: "t")
116
+ end
117
+
118
+ let(:date) do
119
+ Date.new(1976, 11, 19)
120
+ end
121
+
122
+ context "when provided string fields" do
123
+
124
+ let!(:set) do
125
+ address.set("number" => 44, "suite" => "400", "end_date" => date)
126
+ end
127
+
128
+ it_behaves_like "a settable embedded document"
129
+ end
130
+
131
+ context "when provided symbol fields" do
132
+
133
+ let!(:set) do
134
+ address.set(number: 44, suite: "400", end_date: date)
135
+ end
136
+
137
+ it_behaves_like "a settable embedded document"
138
+ end
139
+ end
140
+ end
141
+
142
+ context "when dynamic attributes are not enabled" do
143
+ let(:account) do
144
+ Account.create
145
+ end
146
+
147
+ around do |example|
148
+ Mongoid.allow_dynamic_fields = false
149
+ example.run
150
+ Mongoid.allow_dynamic_fields = true
151
+ end
152
+
153
+ it "raises exception for an unknown attribute " do
154
+ expect {
155
+ account.set(somethingnew: "somethingnew")
156
+ }.to raise_error(Mongoid::Errors::UnknownAttribute)
157
+ end
158
+ end
159
+
160
+ context "when dynamic attributes enabled" do
161
+ let(:person) do
162
+ Person.create
163
+ end
164
+
165
+ it "updates non existing attribute" do
166
+ person.set(somethingnew: "somethingnew")
167
+ expect(person.reload.somethingnew).to eq "somethingnew"
168
+ end
169
+ end
170
+ end
171
+
172
+ end