@@ -403,6 +403,32 @@ def localized?
403
403
end
404
404
end
405
405
end
406
+
407
+ context "when providing a Mongoid::RawValue" do
408
+
409
+ context "and raw_value is a string" do
410
+
411
+ before do
412
+ selector . send ( method , "key" , Mongoid ::RawValue ( "Foo" ) )
413
+ end
414
+
415
+ it "serializes the raw_value" do
416
+ expect ( selector [ "key" ] ) . to eq ( "Foo" )
417
+ end
418
+ end
419
+
420
+ context "and raw_value is a complex type" do
421
+ config_override :map_big_decimal_to_decimal128 , true
422
+
423
+ before do
424
+ selector . send ( method , "key" , Mongoid ::RawValue ( [ { foo : 1 , "Bar" => [ /baz/ , BigDecimal ( '2' ) , 4 ..5 ] } , 3 ] ) )
425
+ end
426
+
427
+ it "serializes the raw_value" do
428
+ expect ( selector [ "key" ] ) . to eq ( [ { foo : 1 , "Bar" => [ /baz/ , BSON ::Decimal128 . new ( '2' ) , { "$gte" => 4 , "$lte" => 5 } ] } , 3 ] )
429
+ end
430
+ end
431
+ end
406
432
end
407
433
408
434
context "when serializers are provided" do
@@ -603,6 +629,53 @@ def localized?
603
629
end
604
630
end
605
631
end
632
+
633
+ context "when the criterion is a Mongoid::RawValue" do
634
+
635
+ context "and raw_value is a serializable string" do
636
+
637
+ before do
638
+ selector . send ( method , "key" , Mongoid ::RawValue ( "1" ) )
639
+ end
640
+
641
+ it "serializes the value" do
642
+ expect ( selector [ "key" ] ) . to eq ( "1" )
643
+ end
644
+ end
645
+
646
+ context "and raw_value is a serializable type" do
647
+
648
+ before do
649
+ selector . send ( method , "key" , Mongoid ::RawValue ( BigDecimal ( '2' ) ) )
650
+ end
651
+
652
+ it "serializes the value" do
653
+ expect ( selector [ "key" ] ) . to eq ( BSON ::Decimal128 . new ( '2' ) )
654
+ end
655
+ end
656
+
657
+ context "and raw_value is a non-serializable string" do
658
+
659
+ before do
660
+ selector . send ( method , "key" , Mongoid ::RawValue ( "Foo" ) )
661
+ end
662
+
663
+ it "serializes the value" do
664
+ expect ( selector [ "key" ] ) . to eq ( "Foo" )
665
+ end
666
+ end
667
+
668
+ context "and raw_value is a complex type" do
669
+
670
+ before do
671
+ selector . send ( method , "key" , Mongoid ::RawValue ( [ { foo : "1" , "Bar" => [ /baz/ , BigDecimal ( '2' ) , 4 ..5 ] } , 3 ] ) )
672
+ end
673
+
674
+ it "serializes the raw_value" do
675
+ expect ( selector [ "key" ] ) . to eq ( [ { foo : "1" , "Bar" => [ /baz/ , BSON ::Decimal128 . new ( '2' ) , { "$gte" => 4 , "$lte" => 5 } ] } , 3 ] )
676
+ end
677
+ end
678
+ end
606
679
end
607
680
end
608
681
end
0 commit comments