File tree Expand file tree Collapse file tree 3 files changed +32
-12
lines changed
lib/mongoid/criteria/queryable/extensions
criteria/queryable/extensions Expand file tree Collapse file tree 3 files changed +32
-12
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def evolve(object)
33
33
end
34
34
# Always return on string for backwards compatibility with querying
35
35
# string-backed BigDecimal fields.
36
- when BSON ::Decimal128 , String then obj
36
+ when BSON ::Decimal128 then obj
37
37
else
38
38
if obj . numeric?
39
39
if Mongoid . map_big_decimal_to_decimal128
Original file line number Diff line number Diff line change 142
142
end
143
143
144
144
context "when provided a numeric" do
145
- it "returns a string " do
145
+ it "returns a BSON::Decimal128 " do
146
146
expect ( described_class . evolve ( 1 ) ) . to eq ( BSON ::Decimal128 . new ( '1' ) )
147
147
end
148
148
end
149
149
150
- context "when provided a bogus value " do
151
- it "returns the value " do
152
- expect ( described_class . evolve ( :bogus ) ) . to eq ( :bogus )
150
+ context "when provided a valid string " do
151
+ it "returns a BSON::Decimal128 " do
152
+ expect ( described_class . evolve ( '1' ) ) . to eq ( BSON :: Decimal128 . new ( '1' ) )
153
153
end
154
154
end
155
155
159
159
end
160
160
end
161
161
162
- context "when provided a valid string " do
163
- it "returns the string " do
164
- expect ( described_class . evolve ( "1" ) ) . to eq ( "1" )
162
+ context "when provided a bogus value " do
163
+ it "returns the value " do
164
+ expect ( described_class . evolve ( :bogus ) ) . to eq ( :bogus )
165
165
end
166
166
end
167
167
end
Original file line number Diff line number Diff line change @@ -2756,13 +2756,33 @@ def self.ages; self; end
2756
2756
Band . create! ( name : "Boards of Canada" , sales : sales )
2757
2757
end
2758
2758
2759
- let ( :from_db ) do
2759
+ it "cannot find values when querying using a BigDecimal value" do
2760
2760
Mongoid . map_big_decimal_to_decimal128 = true
2761
- Band . where ( sales : sales . to_s ) . first
2761
+ from_db = Band . where ( sales : sales ) . first
2762
+ expect ( from_db ) . to eq ( nil )
2762
2763
end
2763
2764
2764
- it "finds the document by the big decimal value" do
2765
- expect ( from_db ) . to eq ( band )
2765
+ it "cannot find values when querying using a string value" do
2766
+ Mongoid . map_big_decimal_to_decimal128 = true
2767
+ from_db = Band . where ( sales : sales . to_s ) . first
2768
+ expect ( from_db ) . to eq ( nil )
2769
+ end
2770
+
2771
+ context "after converting value" do
2772
+ before do
2773
+ Mongoid . map_big_decimal_to_decimal128 = true
2774
+ band . set ( sales : band . sales )
2775
+ end
2776
+
2777
+ it "can find values when querying using a BigDecimal value" do
2778
+ from_db = Band . where ( sales : sales ) . first
2779
+ expect ( from_db ) . to eq ( band )
2780
+ end
2781
+
2782
+ it "can find values when querying using a string value" do
2783
+ from_db = Band . where ( sales : sales . to_s ) . first
2784
+ expect ( from_db ) . to eq ( band )
2785
+ end
2766
2786
end
2767
2787
end
2768
2788
end
You can’t perform that action at this time.
0 commit comments