mongoid 7.5.3 → 8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +3 -3
- data/lib/config/locales/en.yml +46 -30
- data/lib/mongoid/association/accessors.rb +32 -3
- data/lib/mongoid/association/bindable.rb +48 -0
- data/lib/mongoid/association/builders.rb +4 -2
- data/lib/mongoid/association/eager_loadable.rb +29 -7
- data/lib/mongoid/association/embedded/batchable.rb +28 -5
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
- data/lib/mongoid/association/embedded/embedded_in.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +40 -18
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +18 -4
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +21 -2
- data/lib/mongoid/association/macros.rb +2 -1
- data/lib/mongoid/association/many.rb +5 -0
- data/lib/mongoid/association/nested/many.rb +2 -1
- data/lib/mongoid/association/proxy.rb +12 -0
- data/lib/mongoid/association/referenced/auto_save.rb +3 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
- data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +8 -8
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +64 -11
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +4 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -18
- data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -9
- data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
- data/lib/mongoid/association/referenced/has_one/proxy.rb +8 -11
- data/lib/mongoid/association/referenced/syncable.rb +2 -2
- data/lib/mongoid/association/relatable.rb +38 -4
- data/lib/mongoid/attributes/processing.rb +9 -2
- data/lib/mongoid/attributes.rb +30 -27
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/changeable.rb +37 -2
- data/lib/mongoid/clients/options.rb +4 -0
- data/lib/mongoid/clients/sessions.rb +2 -14
- data/lib/mongoid/config.rb +15 -11
- data/lib/mongoid/contextual/aggregable/memory.rb +23 -15
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +2 -2
- data/lib/mongoid/contextual/memory.rb +55 -28
- data/lib/mongoid/contextual/mongo.rb +173 -262
- data/lib/mongoid/contextual/none.rb +33 -15
- data/lib/mongoid/copyable.rb +32 -8
- data/lib/mongoid/criteria/includable.rb +24 -20
- data/lib/mongoid/criteria/marshalable.rb +10 -2
- data/lib/mongoid/criteria/queryable/extensions/array.rb +2 -15
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +0 -16
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
- data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
- data/lib/mongoid/criteria/queryable/optional.rb +3 -9
- data/lib/mongoid/criteria/queryable/options.rb +1 -1
- data/lib/mongoid/criteria/queryable/selectable.rb +2 -24
- data/lib/mongoid/criteria/queryable/selector.rb +89 -4
- data/lib/mongoid/criteria/queryable/smash.rb +39 -6
- data/lib/mongoid/criteria/queryable.rb +11 -6
- data/lib/mongoid/criteria.rb +1 -28
- data/lib/mongoid/deprecable.rb +36 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +88 -33
- data/lib/mongoid/equality.rb +4 -4
- data/lib/mongoid/errors/document_not_found.rb +6 -2
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_field.rb +5 -1
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
- data/lib/mongoid/errors.rb +2 -2
- data/lib/mongoid/extensions/array.rb +8 -6
- data/lib/mongoid/extensions/big_decimal.rb +29 -10
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +8 -2
- data/lib/mongoid/extensions/date.rb +26 -20
- data/lib/mongoid/extensions/date_time.rb +1 -1
- data/lib/mongoid/extensions/float.rb +4 -5
- data/lib/mongoid/extensions/hash.rb +12 -5
- data/lib/mongoid/extensions/integer.rb +4 -5
- data/lib/mongoid/extensions/object.rb +2 -0
- data/lib/mongoid/extensions/range.rb +41 -10
- data/lib/mongoid/extensions/regexp.rb +11 -4
- data/lib/mongoid/extensions/set.rb +11 -4
- data/lib/mongoid/extensions/string.rb +2 -13
- data/lib/mongoid/extensions/symbol.rb +3 -14
- data/lib/mongoid/extensions/time.rb +27 -16
- data/lib/mongoid/extensions/time_with_zone.rb +1 -2
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/factory.rb +42 -7
- data/lib/mongoid/fields/foreign_key.rb +7 -0
- data/lib/mongoid/fields/validators/macro.rb +3 -9
- data/lib/mongoid/fields.rb +49 -7
- data/lib/mongoid/findable.rb +21 -16
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +4 -1
- data/lib/mongoid/interceptable.rb +69 -9
- data/lib/mongoid/persistable/creatable.rb +14 -5
- data/lib/mongoid/persistable/updatable.rb +12 -5
- data/lib/mongoid/persistence_context.rb +8 -42
- data/lib/mongoid/query_cache.rb +6 -258
- data/lib/mongoid/railties/controller_runtime.rb +1 -1
- data/lib/mongoid/reloadable.rb +7 -3
- data/lib/mongoid/scopable.rb +9 -11
- data/lib/mongoid/selectable.rb +1 -2
- data/lib/mongoid/shardable.rb +11 -35
- data/lib/mongoid/stateful.rb +27 -1
- data/lib/mongoid/timestamps/created.rb +1 -1
- data/lib/mongoid/timestamps/updated.rb +1 -1
- data/lib/mongoid/touchable.rb +2 -3
- data/lib/mongoid/traversable.rb +1 -0
- data/lib/mongoid/validatable/uniqueness.rb +2 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +3 -4
- data/lib/mongoid.rb +1 -0
- data/spec/config/mongoid.yml +16 -0
- data/spec/integration/app_spec.rb +8 -12
- data/spec/integration/associations/belongs_to_spec.rb +18 -0
- data/spec/integration/associations/embedded_spec.rb +15 -0
- data/spec/integration/associations/embeds_many_spec.rb +15 -2
- data/spec/integration/associations/embeds_one_spec.rb +18 -0
- data/spec/integration/associations/foreign_key_spec.rb +9 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_one_spec.rb +97 -1
- data/spec/integration/associations/scope_option_spec.rb +1 -1
- data/spec/integration/callbacks_models.rb +95 -1
- data/spec/integration/callbacks_spec.rb +226 -4
- data/spec/integration/criteria/range_spec.rb +95 -1
- data/spec/integration/discriminator_key_spec.rb +115 -76
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +1 -15
- data/spec/integration/matcher_examples_spec.rb +20 -13
- data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
- data/spec/integration/matcher_operator_spec.rb +3 -5
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/mongoid/association/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +9 -9
- data/spec/mongoid/association/eager_spec.rb +2 -1
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +69 -9
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +198 -8
- data/spec/mongoid/association/embedded/embeds_many_models.rb +36 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +15 -0
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +38 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2 -56
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +62 -13
- data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
- data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
- data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
- data/spec/mongoid/association/syncable_spec.rb +14 -0
- data/spec/mongoid/atomic/paths_spec.rb +0 -14
- data/spec/mongoid/attributes/nested_spec.rb +80 -11
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_spec.rb +1 -5
- data/spec/mongoid/attributes_spec.rb +480 -27
- data/spec/mongoid/cacheable_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +130 -13
- data/spec/mongoid/clients/factory_spec.rb +23 -30
- data/spec/mongoid/clients/sessions_spec.rb +0 -38
- data/spec/mongoid/clients_spec.rb +2 -2
- data/spec/mongoid/config_spec.rb +52 -14
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +396 -158
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
- data/spec/mongoid/contextual/memory_spec.rb +521 -14
- data/spec/mongoid/contextual/mongo_spec.rb +566 -416
- data/spec/mongoid/contextual/none_spec.rb +11 -19
- data/spec/mongoid/copyable_spec.rb +451 -1
- data/spec/mongoid/criteria/findable_spec.rb +86 -210
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +0 -484
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +50 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +77 -85
- data/spec/mongoid/criteria/queryable/selector_spec.rb +14 -2
- data/spec/mongoid/criteria_spec.rb +469 -1201
- data/spec/mongoid/document_fields_spec.rb +173 -24
- data/spec/mongoid/document_spec.rb +32 -41
- data/spec/mongoid/equality_spec.rb +12 -12
- data/spec/mongoid/errors/document_not_found_spec.rb +29 -2
- data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
- data/spec/mongoid/errors/no_environment_spec.rb +3 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
- data/spec/mongoid/extensions/array_spec.rb +16 -2
- data/spec/mongoid/extensions/big_decimal_spec.rb +697 -212
- data/spec/mongoid/extensions/binary_spec.rb +44 -9
- data/spec/mongoid/extensions/boolean_spec.rb +68 -82
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
- data/spec/mongoid/extensions/date_spec.rb +71 -1
- data/spec/mongoid/extensions/date_time_spec.rb +15 -9
- data/spec/mongoid/extensions/float_spec.rb +48 -76
- data/spec/mongoid/extensions/hash_spec.rb +30 -0
- data/spec/mongoid/extensions/integer_spec.rb +45 -66
- data/spec/mongoid/extensions/range_spec.rb +255 -54
- data/spec/mongoid/extensions/regexp_spec.rb +58 -33
- data/spec/mongoid/extensions/set_spec.rb +106 -0
- data/spec/mongoid/extensions/string_spec.rb +53 -25
- data/spec/mongoid/extensions/symbol_spec.rb +18 -25
- data/spec/mongoid/extensions/time_spec.rb +634 -66
- data/spec/mongoid/extensions/time_with_zone_spec.rb +17 -31
- data/spec/mongoid/factory_spec.rb +61 -1
- data/spec/mongoid/fields_spec.rb +321 -50
- data/spec/mongoid/findable_spec.rb +64 -29
- data/spec/mongoid/indexable/specification_spec.rb +2 -2
- data/spec/mongoid/indexable_spec.rb +16 -19
- data/spec/mongoid/interceptable_spec.rb +584 -5
- data/spec/mongoid/interceptable_spec_models.rb +235 -4
- data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +2 -2
- data/spec/mongoid/persistable/destroyable_spec.rb +2 -2
- data/spec/mongoid/persistable/upsertable_spec.rb +14 -0
- data/spec/mongoid/persistence_context_spec.rb +24 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
- data/spec/mongoid/query_cache_spec.rb +0 -154
- data/spec/mongoid/reloadable_spec.rb +35 -2
- data/spec/mongoid/scopable_spec.rb +36 -34
- data/spec/mongoid/shardable_models.rb +0 -14
- data/spec/mongoid/shardable_spec.rb +61 -153
- data/spec/mongoid/stateful_spec.rb +28 -0
- data/spec/mongoid/timestamps_spec.rb +390 -0
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +116 -0
- data/spec/mongoid/touchable_spec_models.rb +12 -8
- data/spec/mongoid/traversable_spec.rb +4 -11
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +60 -31
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +1 -7
- data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
- data/spec/rails/mongoid_spec.rb +4 -16
- data/spec/shared/lib/mrss/event_subscriber.rb +5 -15
- data/spec/shared/lib/mrss/lite_constraints.rb +0 -8
- data/spec/shared/shlib/server.sh +5 -5
- data/spec/support/constraints.rb +24 -0
- data/spec/support/macros.rb +30 -0
- data/spec/support/models/augmentation.rb +12 -0
- data/spec/support/models/band.rb +3 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/circus.rb +3 -0
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/support/models/implant.rb +9 -0
- data/spec/support/models/label.rb +2 -0
- data/spec/support/models/passport.rb +9 -0
- data/spec/support/models/person.rb +1 -0
- data/spec/support/models/player.rb +2 -0
- data/spec/support/models/powerup.rb +12 -0
- data/spec/support/models/registry.rb +1 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/shield.rb +18 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/weapon.rb +12 -0
- data.tar.gz.sig +0 -0
- metadata +669 -638
- metadata.gz.sig +0 -0
- data/lib/mongoid/errors/eager_load.rb +0 -23
- data/lib/mongoid/errors/invalid_value.rb +0 -17
- data/spec/mongoid/errors/eager_load_spec.rb +0 -31
@@ -8,401 +8,886 @@ describe Mongoid::Extensions::BigDecimal do
|
|
8
8
|
BigDecimal("123456.789")
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
context 'when map_big_decimal_to_decimal128 is false' do
|
12
|
+
config_override :map_big_decimal_to_decimal128, false
|
12
13
|
|
13
|
-
|
14
|
+
describe ".demongoize" do
|
14
15
|
|
15
|
-
let(:
|
16
|
-
|
16
|
+
let(:demongoized) do
|
17
|
+
BigDecimal.demongoize(value)
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
context "when the value is an empty String" do
|
21
|
+
|
22
|
+
let(:value) do
|
23
|
+
""
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an error" do
|
27
|
+
expect(demongoized).to be_nil
|
28
|
+
end
|
21
29
|
end
|
22
|
-
end
|
23
30
|
|
24
|
-
|
31
|
+
context "when the value is a numeric String" do
|
32
|
+
|
33
|
+
let(:value) do
|
34
|
+
"123456.789"
|
35
|
+
end
|
25
36
|
|
26
|
-
|
27
|
-
|
37
|
+
it "returns a BigDecimal" do
|
38
|
+
expect(demongoized).to eq(BigDecimal(value))
|
39
|
+
end
|
28
40
|
end
|
29
41
|
|
30
|
-
|
31
|
-
|
42
|
+
context "when the value is the numeric String zero" do
|
43
|
+
|
44
|
+
let(:value) do
|
45
|
+
"0.0"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns a BigDecimal" do
|
49
|
+
expect(demongoized).to eq(BigDecimal(value))
|
50
|
+
end
|
32
51
|
end
|
33
|
-
end
|
34
52
|
|
35
|
-
|
53
|
+
context "when the value is the numeric String negative zero" do
|
54
|
+
|
55
|
+
let(:value) do
|
56
|
+
"-0.0"
|
57
|
+
end
|
36
58
|
|
37
|
-
|
38
|
-
|
59
|
+
it "returns a BigDecimal" do
|
60
|
+
expect(demongoized).to eq(BigDecimal(value))
|
61
|
+
end
|
39
62
|
end
|
40
63
|
|
41
|
-
|
42
|
-
|
64
|
+
context "when the value is a non-numeric String" do
|
65
|
+
|
66
|
+
let(:value) do
|
67
|
+
"1a2"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns nil" do
|
71
|
+
expect(demongoized).to be_nil
|
72
|
+
end
|
43
73
|
end
|
44
|
-
end
|
45
74
|
|
46
|
-
|
75
|
+
context "when the value is nil" do
|
47
76
|
|
48
|
-
|
49
|
-
|
77
|
+
let(:value) do
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns nil" do
|
82
|
+
expect(demongoized).to be_nil
|
83
|
+
end
|
50
84
|
end
|
51
85
|
|
52
|
-
|
53
|
-
|
86
|
+
context "when the value is true" do
|
87
|
+
|
88
|
+
let(:value) do
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns nil" do
|
93
|
+
expect(demongoized).to be_nil
|
94
|
+
end
|
54
95
|
end
|
55
|
-
end
|
56
96
|
|
57
|
-
|
97
|
+
context "when the value is false" do
|
98
|
+
|
99
|
+
let(:value) do
|
100
|
+
false
|
101
|
+
end
|
58
102
|
|
59
|
-
|
60
|
-
|
103
|
+
it "returns nil" do
|
104
|
+
expect(demongoized).to be_nil
|
105
|
+
end
|
61
106
|
end
|
62
107
|
|
63
|
-
|
64
|
-
|
108
|
+
context "when the value is an Integer" do
|
109
|
+
|
110
|
+
let(:value) do
|
111
|
+
123456
|
112
|
+
end
|
113
|
+
|
114
|
+
it "returns an integer" do
|
115
|
+
expect(demongoized).to eq(value)
|
116
|
+
end
|
65
117
|
end
|
66
|
-
end
|
67
118
|
|
68
|
-
|
119
|
+
context "when the value is a Float" do
|
120
|
+
|
121
|
+
let(:value) do
|
122
|
+
123456.789
|
123
|
+
end
|
69
124
|
|
70
|
-
|
71
|
-
|
125
|
+
it "returns a float" do
|
126
|
+
expect(demongoized).to eq(value)
|
127
|
+
end
|
72
128
|
end
|
73
|
-
end
|
74
129
|
|
75
|
-
|
130
|
+
context "when the value is the String 'NaN'" do
|
131
|
+
|
132
|
+
let(:value) do
|
133
|
+
"NaN"
|
134
|
+
end
|
76
135
|
|
77
|
-
|
78
|
-
|
136
|
+
it "returns a BigDecimal" do
|
137
|
+
expect(demongoized).to be_a(BigDecimal)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "is a NaN BigDecimal" do
|
141
|
+
expect(demongoized).to be_nan
|
142
|
+
end
|
79
143
|
end
|
80
144
|
|
81
|
-
|
82
|
-
|
145
|
+
context "when the value is the String 'Infinity'" do
|
146
|
+
|
147
|
+
let(:value) do
|
148
|
+
"Infinity"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "returns a BigDecimal" do
|
152
|
+
expect(demongoized).to be_a(BigDecimal)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "is a infinity BigDecimal" do
|
156
|
+
expect(demongoized.infinite?).to eq 1
|
157
|
+
end
|
83
158
|
end
|
84
|
-
end
|
85
159
|
|
86
|
-
|
160
|
+
context "when the value is the String '-Infinity'" do
|
161
|
+
|
162
|
+
let(:value) do
|
163
|
+
"-Infinity"
|
164
|
+
end
|
87
165
|
|
88
|
-
|
89
|
-
|
166
|
+
it "returns a BigDecimal" do
|
167
|
+
expect(demongoized).to be_a(BigDecimal)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "is a negative infinity BigDecimal" do
|
171
|
+
expect(demongoized.infinite?).to eq -1
|
172
|
+
end
|
90
173
|
end
|
91
174
|
|
92
|
-
|
93
|
-
|
175
|
+
context "when the value is a BSON::Decimal128" do
|
176
|
+
|
177
|
+
let(:value) do
|
178
|
+
BSON::Decimal128.new("1.2")
|
179
|
+
end
|
180
|
+
|
181
|
+
it "does not raise an error" do
|
182
|
+
expect do
|
183
|
+
demongoized
|
184
|
+
end.to_not raise_error
|
185
|
+
end
|
186
|
+
|
187
|
+
it "returns a big decimal" do
|
188
|
+
expect(demongoized).to eq(value.to_big_decimal)
|
189
|
+
end
|
94
190
|
end
|
95
191
|
end
|
96
192
|
|
97
|
-
|
193
|
+
describe ".mongoize" do
|
98
194
|
|
99
|
-
let(:
|
100
|
-
|
195
|
+
let(:mongoized) do
|
196
|
+
BigDecimal.mongoize(value)
|
101
197
|
end
|
102
198
|
|
103
|
-
|
104
|
-
|
199
|
+
context "when the value is a BigDecimal" do
|
200
|
+
|
201
|
+
let(:value) do
|
202
|
+
big_decimal
|
203
|
+
end
|
204
|
+
|
205
|
+
it "returns a string" do
|
206
|
+
expect(mongoized).to eq(value.to_s)
|
207
|
+
end
|
105
208
|
end
|
106
|
-
end
|
107
209
|
|
108
|
-
|
210
|
+
context "when the value is the BigDecimal zero" do
|
211
|
+
|
212
|
+
let(:value) do
|
213
|
+
BigDecimal("0.0")
|
214
|
+
end
|
109
215
|
|
110
|
-
|
111
|
-
|
216
|
+
it "returns a string" do
|
217
|
+
expect(mongoized).to eq(value.to_s)
|
218
|
+
end
|
112
219
|
end
|
113
220
|
|
114
|
-
|
115
|
-
|
221
|
+
context "when the value is the BigDecimal negative zero" do
|
222
|
+
|
223
|
+
let(:value) do
|
224
|
+
BigDecimal("-0.0")
|
225
|
+
end
|
226
|
+
|
227
|
+
it "returns a string" do
|
228
|
+
expect(mongoized).to eq(value.to_s)
|
229
|
+
end
|
116
230
|
end
|
117
|
-
end
|
118
231
|
|
119
|
-
|
232
|
+
context "when the value is an empty String" do
|
233
|
+
|
234
|
+
let(:value) do
|
235
|
+
""
|
236
|
+
end
|
120
237
|
|
121
|
-
|
122
|
-
|
238
|
+
it "returns nil" do
|
239
|
+
expect(mongoized).to be_nil
|
240
|
+
end
|
123
241
|
end
|
124
242
|
|
125
|
-
|
126
|
-
|
243
|
+
context "when the value is an integer numeric String" do
|
244
|
+
|
245
|
+
let(:value) do
|
246
|
+
"123456"
|
247
|
+
end
|
248
|
+
|
249
|
+
it "returns the String" do
|
250
|
+
expect(mongoized).to eq(value)
|
251
|
+
end
|
127
252
|
end
|
128
253
|
|
129
|
-
|
130
|
-
|
254
|
+
context "when the value is a float numeric String" do
|
255
|
+
|
256
|
+
let(:value) do
|
257
|
+
"123456.789"
|
258
|
+
end
|
259
|
+
|
260
|
+
it "returns the String" do
|
261
|
+
expect(mongoized).to eq(value)
|
262
|
+
end
|
131
263
|
end
|
132
264
|
|
133
|
-
|
134
|
-
|
265
|
+
context "when the value is a non-numeric String" do
|
266
|
+
|
267
|
+
let(:value) do
|
268
|
+
"1a2"
|
269
|
+
end
|
270
|
+
|
271
|
+
it "returns nil" do
|
272
|
+
expect(mongoized).to be_nil
|
273
|
+
end
|
135
274
|
end
|
136
|
-
end
|
137
275
|
|
138
|
-
|
276
|
+
context "when the value is nil" do
|
139
277
|
|
140
|
-
|
141
|
-
|
278
|
+
let(:value) do
|
279
|
+
nil
|
280
|
+
end
|
281
|
+
|
282
|
+
it "returns nil" do
|
283
|
+
expect(mongoized).to be_nil
|
284
|
+
end
|
142
285
|
end
|
143
286
|
|
144
|
-
|
145
|
-
|
287
|
+
context "when the value is true" do
|
288
|
+
|
289
|
+
let(:value) do
|
290
|
+
true
|
291
|
+
end
|
292
|
+
|
293
|
+
it "returns nil" do
|
294
|
+
expect(mongoized).to be_nil
|
295
|
+
end
|
146
296
|
end
|
147
297
|
|
148
|
-
|
149
|
-
|
298
|
+
context "when the value is false" do
|
299
|
+
|
300
|
+
let(:value) do
|
301
|
+
false
|
302
|
+
end
|
303
|
+
|
304
|
+
it "returns nil" do
|
305
|
+
expect(mongoized).to be_nil
|
306
|
+
end
|
150
307
|
end
|
151
308
|
|
152
|
-
|
153
|
-
|
309
|
+
context "when the value is an Integer" do
|
310
|
+
let(:value) do
|
311
|
+
123456
|
312
|
+
end
|
313
|
+
|
314
|
+
it "returns a string" do
|
315
|
+
expect(mongoized).to eq(value.to_s)
|
316
|
+
end
|
154
317
|
end
|
155
|
-
end
|
156
318
|
|
157
|
-
|
319
|
+
context "when the value is a Float" do
|
320
|
+
|
321
|
+
let(:value) do
|
322
|
+
123456.789
|
323
|
+
end
|
158
324
|
|
159
|
-
|
160
|
-
|
325
|
+
it "returns a string" do
|
326
|
+
expect(mongoized).to eq(value.to_s)
|
327
|
+
end
|
161
328
|
end
|
162
329
|
|
163
|
-
|
164
|
-
|
330
|
+
context "when the value is String NaN" do
|
331
|
+
|
332
|
+
let(:value) do
|
333
|
+
"NaN"
|
334
|
+
end
|
335
|
+
|
336
|
+
it "returns a String" do
|
337
|
+
expect(mongoized).to eq("NaN")
|
338
|
+
end
|
165
339
|
end
|
166
340
|
|
167
|
-
|
168
|
-
|
341
|
+
context "when the value is String Infinity" do
|
342
|
+
|
343
|
+
let(:value) do
|
344
|
+
"Infinity"
|
345
|
+
end
|
346
|
+
|
347
|
+
it "returns a String" do
|
348
|
+
expect(mongoized).to eq("Infinity")
|
349
|
+
end
|
169
350
|
end
|
170
351
|
|
171
|
-
|
172
|
-
|
352
|
+
context "when the value is String negative Infinity" do
|
353
|
+
|
354
|
+
let(:value) do
|
355
|
+
"-Infinity"
|
356
|
+
end
|
357
|
+
|
358
|
+
it "returns a String" do
|
359
|
+
expect(mongoized).to eq("-Infinity")
|
360
|
+
end
|
173
361
|
end
|
174
|
-
end
|
175
|
-
end
|
176
362
|
|
177
|
-
|
363
|
+
context "when the value is BigDecimal NaN" do
|
178
364
|
|
179
|
-
|
365
|
+
let(:value) do
|
366
|
+
BigDecimal("NaN")
|
367
|
+
end
|
180
368
|
|
181
|
-
|
182
|
-
|
369
|
+
it "returns a String" do
|
370
|
+
expect(mongoized).to eq("NaN")
|
371
|
+
end
|
183
372
|
end
|
184
|
-
end
|
185
373
|
|
186
|
-
|
374
|
+
context "when the value is BigDecimal Infinity" do
|
187
375
|
|
188
|
-
|
189
|
-
|
376
|
+
let(:value) do
|
377
|
+
BigDecimal("Infinity")
|
378
|
+
end
|
379
|
+
|
380
|
+
it "returns a String" do
|
381
|
+
expect(mongoized).to eq("Infinity")
|
382
|
+
end
|
190
383
|
end
|
191
384
|
|
192
|
-
|
193
|
-
|
385
|
+
context "when the value is BigDecimal negative Infinity" do
|
386
|
+
|
387
|
+
let(:value) do
|
388
|
+
BigDecimal("-Infinity")
|
389
|
+
end
|
390
|
+
|
391
|
+
it "returns a String" do
|
392
|
+
expect(mongoized).to eq("-Infinity")
|
393
|
+
end
|
194
394
|
end
|
195
|
-
end
|
196
395
|
|
197
|
-
|
396
|
+
context "when the value is the constant Float::NAN" do
|
397
|
+
|
398
|
+
let(:value) do
|
399
|
+
Float::NAN
|
400
|
+
end
|
198
401
|
|
199
|
-
|
200
|
-
|
402
|
+
it "returns a String" do
|
403
|
+
expect(mongoized).to eq("NaN")
|
404
|
+
end
|
201
405
|
end
|
202
406
|
|
203
|
-
|
204
|
-
|
407
|
+
context "when the value is constant Float::INFINITY" do
|
408
|
+
|
409
|
+
let(:value) do
|
410
|
+
Float::INFINITY
|
411
|
+
end
|
412
|
+
|
413
|
+
it "returns a String" do
|
414
|
+
expect(mongoized).to eq("Infinity")
|
415
|
+
end
|
205
416
|
end
|
206
|
-
end
|
207
417
|
|
208
|
-
|
418
|
+
context "when the value is constant Float::INFINITY * -1" do
|
419
|
+
|
420
|
+
let(:value) do
|
421
|
+
Float::INFINITY * -1
|
422
|
+
end
|
209
423
|
|
210
|
-
|
211
|
-
|
424
|
+
it "returns a String" do
|
425
|
+
expect(mongoized).to eq("-Infinity")
|
426
|
+
end
|
212
427
|
end
|
213
428
|
|
214
|
-
|
215
|
-
|
429
|
+
context "when the value is a decimal128" do
|
430
|
+
let(:value) do
|
431
|
+
BSON::Decimal128.new("42")
|
432
|
+
end
|
433
|
+
|
434
|
+
it "returns a String" do
|
435
|
+
expect(mongoized).to eq("42")
|
436
|
+
end
|
216
437
|
end
|
217
438
|
end
|
218
439
|
|
219
|
-
|
440
|
+
describe "#mongoize" do
|
220
441
|
|
221
|
-
|
222
|
-
|
442
|
+
it "returns a string" do
|
443
|
+
expect(big_decimal.mongoize).to eq(big_decimal.to_s)
|
223
444
|
end
|
445
|
+
end
|
224
446
|
|
225
|
-
|
226
|
-
|
447
|
+
describe "#numeric?" do
|
448
|
+
|
449
|
+
it "returns true" do
|
450
|
+
expect(big_decimal.numeric?).to eq(true)
|
227
451
|
end
|
228
452
|
end
|
453
|
+
end
|
454
|
+
|
455
|
+
context 'when map_big_decimal_to_decimal128 is true' do
|
456
|
+
config_override :map_big_decimal_to_decimal128, true
|
229
457
|
|
230
|
-
|
458
|
+
describe ".demongoize" do
|
231
459
|
|
232
|
-
let(:
|
233
|
-
|
460
|
+
let(:demongoized) do
|
461
|
+
BigDecimal.demongoize(value)
|
234
462
|
end
|
235
463
|
|
236
|
-
|
237
|
-
|
464
|
+
context "when the value is an empty String" do
|
465
|
+
|
466
|
+
let(:value) do
|
467
|
+
""
|
468
|
+
end
|
469
|
+
|
470
|
+
it "raises an error" do
|
471
|
+
expect(demongoized).to eq(nil)
|
472
|
+
end
|
238
473
|
end
|
239
|
-
end
|
240
474
|
|
241
|
-
|
475
|
+
context "when the value is a numeric String" do
|
476
|
+
|
477
|
+
let(:value) do
|
478
|
+
"123456.789"
|
479
|
+
end
|
242
480
|
|
243
|
-
|
244
|
-
|
481
|
+
it "returns a BigDecimal" do
|
482
|
+
expect(demongoized).to eq(BigDecimal(value))
|
483
|
+
end
|
245
484
|
end
|
246
485
|
|
247
|
-
|
248
|
-
|
486
|
+
context "when the value is the numeric String zero" do
|
487
|
+
|
488
|
+
let(:value) do
|
489
|
+
"0.0"
|
490
|
+
end
|
491
|
+
|
492
|
+
it "returns a BigDecimal" do
|
493
|
+
expect(demongoized).to eq(BigDecimal(value))
|
494
|
+
end
|
249
495
|
end
|
250
|
-
end
|
251
496
|
|
252
|
-
|
497
|
+
context "when the value is the numeric String negative zero" do
|
253
498
|
|
254
|
-
|
255
|
-
|
499
|
+
let(:value) do
|
500
|
+
"-0.0"
|
501
|
+
end
|
502
|
+
|
503
|
+
it "returns a BigDecimal" do
|
504
|
+
expect(demongoized).to eq(BigDecimal(value))
|
505
|
+
end
|
256
506
|
end
|
257
|
-
end
|
258
507
|
|
259
|
-
|
508
|
+
context "when the value is a non-numeric String" do
|
509
|
+
|
510
|
+
let(:value) do
|
511
|
+
"1a2"
|
512
|
+
end
|
260
513
|
|
261
|
-
|
262
|
-
|
514
|
+
it "returns nil" do
|
515
|
+
expect(demongoized).to be_nil
|
516
|
+
end
|
263
517
|
end
|
264
518
|
|
265
|
-
|
266
|
-
|
519
|
+
context "when the value is nil" do
|
520
|
+
|
521
|
+
let(:value) do
|
522
|
+
nil
|
523
|
+
end
|
524
|
+
|
525
|
+
it "returns nil" do
|
526
|
+
expect(demongoized).to be_nil
|
527
|
+
end
|
267
528
|
end
|
268
|
-
end
|
269
529
|
|
270
|
-
|
530
|
+
context "when the value is an Integer" do
|
271
531
|
|
272
|
-
|
273
|
-
|
532
|
+
let(:value) do
|
533
|
+
123456
|
534
|
+
end
|
535
|
+
|
536
|
+
it "returns an integer" do
|
537
|
+
expect(demongoized).to eq(value)
|
538
|
+
end
|
274
539
|
end
|
275
540
|
|
276
|
-
|
277
|
-
|
541
|
+
context "when the value is a BSON::Decimal128 object" do
|
542
|
+
|
543
|
+
let(:value) do
|
544
|
+
BSON::Decimal128.new("123456")
|
545
|
+
end
|
546
|
+
|
547
|
+
it "returns a BigDecimal" do
|
548
|
+
expect(demongoized).to eq(value.to_big_decimal)
|
549
|
+
end
|
278
550
|
end
|
279
|
-
end
|
280
551
|
|
281
|
-
|
552
|
+
context "when the value is a Float" do
|
282
553
|
|
283
|
-
|
284
|
-
|
554
|
+
let(:value) do
|
555
|
+
123456.789
|
556
|
+
end
|
557
|
+
|
558
|
+
it "returns a float" do
|
559
|
+
expect(demongoized).to eq(value)
|
560
|
+
end
|
285
561
|
end
|
286
|
-
end
|
287
562
|
|
288
|
-
|
563
|
+
context "when the value is the String 'NaN'" do
|
289
564
|
|
290
|
-
|
291
|
-
|
565
|
+
let(:value) do
|
566
|
+
"NaN"
|
567
|
+
end
|
568
|
+
|
569
|
+
it "returns a BigDecimal" do
|
570
|
+
expect(demongoized).to be_a(BigDecimal)
|
571
|
+
end
|
572
|
+
|
573
|
+
it "is a NaN BigDecimal" do
|
574
|
+
expect(demongoized).to be_nan
|
575
|
+
end
|
292
576
|
end
|
293
|
-
end
|
294
577
|
|
295
|
-
|
578
|
+
context "when the value is the String 'Infinity'" do
|
579
|
+
|
580
|
+
let(:value) do
|
581
|
+
"Infinity"
|
582
|
+
end
|
296
583
|
|
297
|
-
|
298
|
-
|
584
|
+
it "returns a BigDecimal" do
|
585
|
+
expect(demongoized).to be_a(BigDecimal)
|
586
|
+
end
|
587
|
+
|
588
|
+
it "is a infinity BigDecimal" do
|
589
|
+
expect(demongoized.infinite?).to eq 1
|
590
|
+
end
|
299
591
|
end
|
300
592
|
|
301
|
-
|
302
|
-
|
593
|
+
context "when the value is the String '-Infinity'" do
|
594
|
+
|
595
|
+
let(:value) do
|
596
|
+
"-Infinity"
|
597
|
+
end
|
598
|
+
|
599
|
+
it "returns a BigDecimal" do
|
600
|
+
expect(demongoized).to be_a(BigDecimal)
|
601
|
+
end
|
602
|
+
|
603
|
+
it "is a negative infinity BigDecimal" do
|
604
|
+
expect(demongoized.infinite?).to eq -1
|
605
|
+
end
|
303
606
|
end
|
304
|
-
end
|
305
607
|
|
306
|
-
|
608
|
+
context "when the value is true" do
|
307
609
|
|
308
|
-
|
309
|
-
|
610
|
+
let(:value) do
|
611
|
+
true
|
612
|
+
end
|
613
|
+
|
614
|
+
it "returns nil" do
|
615
|
+
expect(demongoized).to be_nil
|
616
|
+
end
|
310
617
|
end
|
311
618
|
|
312
|
-
|
313
|
-
|
619
|
+
context "when the value is false" do
|
620
|
+
|
621
|
+
let(:value) do
|
622
|
+
false
|
623
|
+
end
|
624
|
+
|
625
|
+
it "returns nil" do
|
626
|
+
expect(demongoized).to be_nil
|
627
|
+
end
|
314
628
|
end
|
315
629
|
end
|
316
630
|
|
317
|
-
|
631
|
+
describe ".mongoize" do
|
318
632
|
|
319
|
-
let(:
|
320
|
-
|
633
|
+
let(:mongoized) do
|
634
|
+
BigDecimal.mongoize(value)
|
321
635
|
end
|
322
636
|
|
323
|
-
|
324
|
-
|
637
|
+
context "when the value is a BigDecimal" do
|
638
|
+
|
639
|
+
let(:value) do
|
640
|
+
big_decimal
|
641
|
+
end
|
642
|
+
|
643
|
+
it "returns a BSON::Decimal128" do
|
644
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
645
|
+
end
|
325
646
|
end
|
326
|
-
end
|
327
647
|
|
328
|
-
|
648
|
+
context "when the value is the BigDecimal zero" do
|
329
649
|
|
330
|
-
|
331
|
-
|
650
|
+
let(:value) do
|
651
|
+
BigDecimal("0.0")
|
652
|
+
end
|
653
|
+
|
654
|
+
it "returns a BSON::Decimal128" do
|
655
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
656
|
+
end
|
332
657
|
end
|
333
658
|
|
334
|
-
|
335
|
-
|
659
|
+
context "when the value is the BigDecimal negative zero" do
|
660
|
+
|
661
|
+
let(:value) do
|
662
|
+
BigDecimal("-0.0")
|
663
|
+
end
|
664
|
+
|
665
|
+
it "returns a BSON::Decimal128" do
|
666
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
667
|
+
end
|
336
668
|
end
|
337
|
-
end
|
338
669
|
|
339
|
-
|
670
|
+
context "when the value is an empty String" do
|
671
|
+
|
672
|
+
let(:value) do
|
673
|
+
""
|
674
|
+
end
|
340
675
|
|
341
|
-
|
342
|
-
|
676
|
+
it "returns nil" do
|
677
|
+
expect(mongoized).to be_nil
|
678
|
+
end
|
343
679
|
end
|
344
680
|
|
345
|
-
|
346
|
-
|
681
|
+
context "when the value is an integer numeric String" do
|
682
|
+
|
683
|
+
let(:value) do
|
684
|
+
"123456"
|
685
|
+
end
|
686
|
+
|
687
|
+
it "returns the BSON::Decimal128" do
|
688
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
689
|
+
end
|
347
690
|
end
|
348
|
-
end
|
349
691
|
|
350
|
-
|
692
|
+
context "when the value is a float numeric String" do
|
693
|
+
|
694
|
+
let(:value) do
|
695
|
+
"123456.789"
|
696
|
+
end
|
351
697
|
|
352
|
-
|
353
|
-
|
698
|
+
it "returns the BSON::Decimal128" do
|
699
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
700
|
+
end
|
354
701
|
end
|
355
702
|
|
356
|
-
|
357
|
-
|
703
|
+
context "when the value is a non-numeric String" do
|
704
|
+
|
705
|
+
let(:value) do
|
706
|
+
"1a2"
|
707
|
+
end
|
708
|
+
|
709
|
+
it "returns nil" do
|
710
|
+
expect(mongoized).to be_nil
|
711
|
+
end
|
358
712
|
end
|
359
|
-
end
|
360
713
|
|
361
|
-
|
714
|
+
context "when the value is nil" do
|
362
715
|
|
363
|
-
|
364
|
-
|
716
|
+
let(:value) do
|
717
|
+
nil
|
718
|
+
end
|
719
|
+
|
720
|
+
it "returns nil" do
|
721
|
+
expect(mongoized).to be_nil
|
722
|
+
end
|
365
723
|
end
|
366
724
|
|
367
|
-
|
368
|
-
|
725
|
+
context "when the value is true" do
|
726
|
+
|
727
|
+
let(:value) do
|
728
|
+
true
|
729
|
+
end
|
730
|
+
|
731
|
+
it "returns nil" do
|
732
|
+
expect(mongoized).to be_nil
|
733
|
+
end
|
369
734
|
end
|
370
|
-
end
|
371
735
|
|
372
|
-
|
736
|
+
context "when the value is false" do
|
737
|
+
|
738
|
+
let(:value) do
|
739
|
+
false
|
740
|
+
end
|
373
741
|
|
374
|
-
|
375
|
-
|
742
|
+
it "returns nil" do
|
743
|
+
expect(mongoized).to be_nil
|
744
|
+
end
|
376
745
|
end
|
377
746
|
|
378
|
-
|
379
|
-
|
747
|
+
context "when the value is an Integer" do
|
748
|
+
|
749
|
+
let(:value) do
|
750
|
+
123456
|
751
|
+
end
|
752
|
+
|
753
|
+
it "returns a BSON::Decimal128" do
|
754
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value.to_s))
|
755
|
+
end
|
380
756
|
end
|
381
|
-
end
|
382
757
|
|
383
|
-
|
758
|
+
context "when the value is a Float" do
|
759
|
+
|
760
|
+
let(:value) do
|
761
|
+
123456.789
|
762
|
+
end
|
763
|
+
|
764
|
+
it "returns a BSON::Decimal128" do
|
765
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value.to_s))
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
context "when the value is String NaN" do
|
770
|
+
|
771
|
+
let(:value) do
|
772
|
+
"NaN"
|
773
|
+
end
|
384
774
|
|
385
|
-
|
386
|
-
|
775
|
+
it "returns a BSON::Decimal128 representation of NaN" do
|
776
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
777
|
+
end
|
387
778
|
end
|
388
779
|
|
389
|
-
|
390
|
-
|
780
|
+
context "when the value is String Infinity" do
|
781
|
+
|
782
|
+
let(:value) do
|
783
|
+
"Infinity"
|
784
|
+
end
|
785
|
+
|
786
|
+
it "returns a BSON::Decimal128 representation of Infinity" do
|
787
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
788
|
+
end
|
789
|
+
end
|
790
|
+
|
791
|
+
context "when the value is String negative Infinity" do
|
792
|
+
|
793
|
+
let(:value) do
|
794
|
+
"-Infinity"
|
795
|
+
end
|
796
|
+
|
797
|
+
it "returns a BSON::Decimal128 representation of -Infinity" do
|
798
|
+
expect(mongoized).to eq(BSON::Decimal128.new(value))
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
context "when the value is BigDecimal NaN" do
|
803
|
+
|
804
|
+
let(:value) do
|
805
|
+
BigDecimal("NaN")
|
806
|
+
end
|
807
|
+
|
808
|
+
it "returns a BSON::Decimal128 representation of BigDecimal NaN" do
|
809
|
+
expect(mongoized).to eq(BSON::Decimal128.new("NaN"))
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
context "when the value is BigDecimal Infinity" do
|
814
|
+
|
815
|
+
let(:value) do
|
816
|
+
BigDecimal("Infinity")
|
817
|
+
end
|
818
|
+
|
819
|
+
it "returns a BSON::Decimal128 representation of BigDecimal Infinity" do
|
820
|
+
expect(mongoized).to eq(BSON::Decimal128.new("Infinity"))
|
821
|
+
end
|
822
|
+
end
|
823
|
+
|
824
|
+
context "when the value is BigDecimal negative Infinity" do
|
825
|
+
|
826
|
+
let(:value) do
|
827
|
+
BigDecimal("-Infinity")
|
828
|
+
end
|
829
|
+
|
830
|
+
it "returns a BSON::Decimal128 representation of BigDecimal negative Infinity" do
|
831
|
+
expect(mongoized).to eq(BSON::Decimal128.new("-Infinity"))
|
832
|
+
end
|
833
|
+
end
|
834
|
+
|
835
|
+
context "when the value is the constant Float::NAN" do
|
836
|
+
|
837
|
+
let(:value) do
|
838
|
+
Float::NAN
|
839
|
+
end
|
840
|
+
|
841
|
+
it "returns a BSON::Decimal128 representation of NaN" do
|
842
|
+
expect(mongoized).to eq(BSON::Decimal128.new("NaN"))
|
843
|
+
end
|
844
|
+
end
|
845
|
+
|
846
|
+
context "when the value is constant Float::INFINITY" do
|
847
|
+
|
848
|
+
let(:value) do
|
849
|
+
Float::INFINITY
|
850
|
+
end
|
851
|
+
|
852
|
+
it "returns a BSON::Decimal128 representation of Infinity" do
|
853
|
+
expect(mongoized).to eq(BSON::Decimal128.new("Infinity"))
|
854
|
+
end
|
855
|
+
end
|
856
|
+
|
857
|
+
context "when the value is constant Float::INFINITY * -1" do
|
858
|
+
|
859
|
+
let(:value) do
|
860
|
+
Float::INFINITY * -1
|
861
|
+
end
|
862
|
+
|
863
|
+
it "returns a BSON::Decimal128 representation of negative Infinity" do
|
864
|
+
expect(mongoized).to eq(BSON::Decimal128.new("-Infinity"))
|
865
|
+
end
|
866
|
+
end
|
867
|
+
|
868
|
+
context "when the value is a decimal128" do
|
869
|
+
let(:value) do
|
870
|
+
BSON::Decimal128.new("42")
|
871
|
+
end
|
872
|
+
|
873
|
+
it "returns a String" do
|
874
|
+
expect(mongoized).to eq(value)
|
875
|
+
end
|
391
876
|
end
|
392
877
|
end
|
393
|
-
end
|
394
878
|
|
395
|
-
|
879
|
+
describe "#mongoize" do
|
396
880
|
|
397
|
-
|
398
|
-
|
881
|
+
it "returns a BSON::Decimal128 representation of the BigDecimal" do
|
882
|
+
expect(big_decimal.mongoize).to eq(BSON::Decimal128.new(big_decimal))
|
883
|
+
end
|
399
884
|
end
|
400
|
-
end
|
401
885
|
|
402
|
-
|
886
|
+
describe "#numeric?" do
|
403
887
|
|
404
|
-
|
405
|
-
|
888
|
+
it "returns true" do
|
889
|
+
expect(big_decimal.numeric?).to eq(true)
|
890
|
+
end
|
406
891
|
end
|
407
892
|
end
|
408
893
|
end
|