File tree Expand file tree Collapse file tree 11 files changed +88
-97
lines changed
lib/mongoid/criteria/queryable/extensions Expand file tree Collapse file tree 11 files changed +88
-97
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,8 @@ module ClassMethods
20
20
# @return [ true, false ] The boolean value.
21
21
def evolve ( object )
22
22
__evolve__ ( object ) do |obj |
23
- begin
24
- mongoize ( object )
25
- rescue InvalidValue
26
- object
27
- end
23
+ res = mongoize ( object )
24
+ res . nil? ? object : res
28
25
end
29
26
end
30
27
end
Original file line number Diff line number Diff line change 1583
1583
context "when attribute is a Hash" do
1584
1584
let ( :person ) { Person . new map : { somekey : "somevalue" } }
1585
1585
1586
- it "raises an error when trying to set a value of invalid type - array" do
1587
- expect do
1588
- person . map = [ ]
1589
- end . to raise_error ( Mongoid ::Errors ::InvalidValue , /The value \[ \] cannot be written to a field of type Hash/ )
1586
+ it "writes nil when trying to set a value of invalid type - array" do
1587
+ person . map = [ ]
1588
+ expect ( person . map ) . to be_nil
1590
1589
end
1591
1590
1592
- it "raises an error when trying to set a value of invalid type - boolean" do
1593
- expect do
1594
- person . map = false
1595
- end . to raise_error ( Mongoid ::Errors ::InvalidValue , /The value false cannot be written to a field of type Hash/ )
1591
+ it "writes nil when trying to set a value of invalid type - boolean" do
1592
+ person . map = false
1593
+ expect ( person . map ) . to be_nil
1596
1594
end
1597
1595
1598
1596
it "can set a Hash value" do
1607
1605
expect ( person . aliases ) . to eq ( [ :alias_1 ] )
1608
1606
end
1609
1607
1610
- it "raises an error when trying to set a value of invalid type - hash" do
1611
- expect do
1612
- person . aliases = { }
1613
- end . to raise_error ( Mongoid ::Errors ::InvalidValue , /The value {} cannot be written to a field of type Array/ )
1608
+ it "writes nil when trying to set a value of invalid type - hash" do
1609
+ person . aliases = { }
1610
+ expect ( person . aliases ) . to be_nil
1614
1611
end
1615
1612
1616
- it "raises an error when trying to set a value of invalid type - boolean" do
1617
- expect do
1618
- person . aliases = false
1619
- end . to raise_error ( Mongoid ::Errors ::InvalidValue , /The value false cannot be written to a field of type Array/ )
1613
+ it "writes nil when trying to set a value of invalid type - boolean" do
1614
+ person . aliases = false
1615
+ expect ( person . aliases ) . to be_nil
1620
1616
end
1621
1617
end
1622
1618
Original file line number Diff line number Diff line change 268
268
"1a2"
269
269
end
270
270
271
- it "raises an error" do
272
- expect do
273
- mongoized
274
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
271
+ it "returns nil" do
272
+ expect ( mongoized ) . to be_nil
275
273
end
276
274
end
277
275
292
290
true
293
291
end
294
292
295
- it "raises an error" do
296
- expect do
297
- mongoized
298
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
293
+ it "returns nil" do
294
+ expect ( mongoized ) . to be_nil
299
295
end
300
296
end
301
297
305
301
false
306
302
end
307
303
308
- it "raises an error" do
309
- expect do
310
- mongoized
311
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
304
+ it "returns nil" do
305
+ expect ( mongoized ) . to be_nil
312
306
end
313
307
end
314
308
712
706
"1a2"
713
707
end
714
708
715
- it "returns a decimal128" do
716
- expect do
717
- mongoized
718
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
709
+ it "returns nil" do
710
+ expect ( mongoized ) . to be_nil
719
711
end
720
712
end
721
713
736
728
true
737
729
end
738
730
739
- it "raises an error" do
740
- expect do
741
- mongoized
742
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
731
+ it "returns nil" do
732
+ expect ( mongoized ) . to be_nil
743
733
end
744
734
end
745
735
749
739
false
750
740
end
751
741
752
- it "raises an error" do
753
- expect do
754
- mongoized
755
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
742
+ it "returns nil" do
743
+ expect ( mongoized ) . to be_nil
756
744
end
757
745
end
758
746
Original file line number Diff line number Diff line change 56
56
57
57
let ( :value ) { true }
58
58
59
- it "raises an error" do
60
- expect do
61
- mongoized
62
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
59
+ it "returns nil" do
60
+ expect ( mongoized ) . to be_nil
63
61
end
64
62
end
65
63
end
Original file line number Diff line number Diff line change 102
102
Date . mongoize ( "" )
103
103
end
104
104
105
- it "raises an error" do
106
- expect do
107
- evolved
108
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
105
+ it "returns nil" do
106
+ expect ( evolved ) . to be_nil
109
107
end
110
108
end
111
109
112
110
context "when the string is an invalid time" do
113
111
114
- it "raises an error" do
115
- expect do
116
- Date . mongoize ( "time" )
117
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
112
+ let ( :evolved ) do
113
+ Date . mongoize ( "time" )
114
+ end
115
+
116
+ it "returns nil" do
117
+ expect ( evolved ) . to be_nil
118
118
end
119
119
end
120
120
end
Original file line number Diff line number Diff line change 79
79
80
80
context "when the string is an invalid time" do
81
81
82
- it "raises an error" do
83
- expect do
84
- DateTime . mongoize ( "time" )
85
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
82
+ let ( :mongoized ) do
83
+ DateTime . mongoize ( "time" )
84
+ end
85
+
86
+ it "returns nil" do
87
+ expect ( mongoized ) . to be_nil
86
88
end
87
89
end
88
90
end
Original file line number Diff line number Diff line change 60
60
61
61
context "when the value is not a float string" do
62
62
63
- it "return 0" do
64
- expect do
65
- Float . demongoize ( 'asdf' )
66
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
63
+ let ( :demongoized ) do
64
+ Float . demongoize ( 'asdf' )
65
+ end
66
+
67
+ it "returns nil" do
68
+ expect ( demongoized ) . to be_nil
67
69
end
68
70
end
69
71
end
126
128
127
129
context "when the string is non numerical" do
128
130
129
- it "return 0" do
130
- expect do
131
- Float . mongoize ( "foo" )
132
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
131
+ let ( :mongoized ) do
132
+ Float . mongoize ( "foo" )
133
+ end
134
+
135
+ it "returns nil" do
136
+ expect ( mongoized ) . to be_nil
133
137
end
134
138
end
135
139
Original file line number Diff line number Diff line change 111
111
112
112
context "when the string is non numerical" do
113
113
114
- it "returns 0" do
115
- expect do
116
- Integer . mongoize ( "foo" )
117
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
114
+ let ( :mongoized ) do
115
+ Integer . mongoize ( "foo" )
116
+ end
117
+
118
+ it "returns nil" do
119
+ expect ( mongoized ) . to be_nil
118
120
end
119
121
end
120
122
Original file line number Diff line number Diff line change 312
312
context 'given a String' do
313
313
let ( :range ) { '3' }
314
314
315
- it 'raises an error' do
316
- expect do
317
- subject
318
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
315
+ it "returns nil" do
316
+ is_expected . to be_nil
319
317
end
320
318
end
321
319
330
328
context "given a hash with no correct fields" do
331
329
let ( :range ) { { 'min^' => 1 , 'max^' => 5 , 'exclude_end^' => true } }
332
330
333
- it "raises an error" do
334
- expect do
335
- subject
336
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
331
+ it "returns nil" do
332
+ is_expected . to be_nil
337
333
end
338
334
end
339
335
Original file line number Diff line number Diff line change 163
163
164
164
context "when string is empty" do
165
165
166
- it "raises an error" do
167
- expect do
168
- Time . mongoize ( "" )
169
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
166
+ let ( :mongoized ) do
167
+ Time . mongoize ( "" )
168
+ end
169
+
170
+ it "returns nil" do
171
+ expect ( mongoized ) . to be_nil
170
172
end
171
173
end
172
174
191
193
192
194
context "when the string is an invalid time" do
193
195
194
- it "raises an error" do
195
- expect do
196
- Time . mongoize ( "time" )
197
- end . to raise_error ( Mongoid ::Errors ::InvalidValue )
196
+ let ( :mongoized ) do
197
+ Time . mongoize ( "time" )
198
+ end
199
+
200
+ it "returns nil" do
201
+ expect ( mongoized ) . to be_nil
198
202
end
199
203
end
200
204
You can’t perform that action at this time.
0 commit comments