mongoid 5.4.0 → 6.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +3 -3
- data/Rakefile +26 -0
- data/lib/config/locales/en.yml +40 -0
- data/lib/mongoid/atomic/modifiers.rb +2 -2
- data/lib/mongoid/atomic.rb +5 -5
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/attributes.rb +22 -21
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +36 -0
- data/lib/mongoid/clients/options.rb +55 -250
- data/lib/mongoid/clients/sessions.rb +113 -0
- data/lib/mongoid/clients/storage_options.rb +2 -69
- data/lib/mongoid/clients.rb +10 -63
- data/lib/mongoid/composable.rb +29 -2
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +4 -4
- data/lib/mongoid/contextual/map_reduce.rb +7 -3
- data/lib/mongoid/contextual/memory.rb +9 -4
- data/lib/mongoid/contextual/mongo.rb +65 -30
- data/lib/mongoid/contextual/none.rb +12 -0
- data/lib/mongoid/copyable.rb +13 -6
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +29 -3
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +273 -0
- data/lib/mongoid/criteria/queryable/optional.rb +429 -0
- data/lib/mongoid/criteria/queryable/options.rb +153 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +689 -0
- data/lib/mongoid/criteria/queryable/selector.rb +212 -0
- data/lib/mongoid/criteria/queryable/smash.rb +104 -0
- data/lib/mongoid/criteria/queryable.rb +87 -0
- data/lib/mongoid/criteria.rb +6 -2
- data/lib/mongoid/document.rb +34 -41
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -1
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/errors/invalid_session_use.rb +24 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/decimal128.rb +3 -3
- data/lib/mongoid/extensions/hash.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -0
- data/lib/mongoid/extensions/string.rb +6 -3
- data/lib/mongoid/extensions/time.rb +4 -1
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +2 -1
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +2 -2
- data/lib/mongoid/indexable.rb +16 -14
- data/lib/mongoid/interceptable.rb +9 -22
- data/lib/mongoid/matchable/all.rb +2 -2
- data/lib/mongoid/matchable/and.rb +3 -3
- data/lib/mongoid/matchable/default.rb +2 -2
- data/lib/mongoid/matchable/elem_match.rb +28 -0
- data/lib/mongoid/matchable/exists.rb +2 -2
- data/lib/mongoid/matchable/gt.rb +4 -2
- data/lib/mongoid/matchable/gte.rb +4 -2
- data/lib/mongoid/matchable/in.rb +2 -2
- data/lib/mongoid/matchable/lt.rb +4 -2
- data/lib/mongoid/matchable/lte.rb +4 -2
- data/lib/mongoid/matchable/ne.rb +2 -2
- data/lib/mongoid/matchable/nin.rb +2 -2
- data/lib/mongoid/matchable/nor.rb +37 -0
- data/lib/mongoid/matchable/or.rb +3 -3
- data/lib/mongoid/matchable/regexp.rb +3 -3
- data/lib/mongoid/matchable/size.rb +2 -2
- data/lib/mongoid/matchable.rb +16 -7
- data/lib/mongoid/persistable/creatable.rb +5 -3
- data/lib/mongoid/persistable/deletable.rb +5 -3
- data/lib/mongoid/persistable/destroyable.rb +1 -5
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +7 -14
- data/lib/mongoid/persistable/upsertable.rb +2 -1
- data/lib/mongoid/persistable.rb +4 -6
- data/lib/mongoid/persistence_context.rb +220 -0
- data/lib/mongoid/query_cache.rb +67 -23
- data/lib/mongoid/railtie.rb +17 -1
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/relations/accessors.rb +3 -0
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
- data/lib/mongoid/relations/counter_cache.rb +15 -5
- data/lib/mongoid/relations/eager/base.rb +3 -3
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +2 -2
- data/lib/mongoid/relations/eager/has_many.rb +1 -1
- data/lib/mongoid/relations/eager.rb +6 -11
- data/lib/mongoid/relations/embedded/batchable.rb +20 -18
- data/lib/mongoid/relations/embedded/in.rb +13 -1
- data/lib/mongoid/relations/embedded/many.rb +51 -10
- data/lib/mongoid/relations/embedded/one.rb +14 -1
- data/lib/mongoid/relations/macros.rb +9 -1
- data/lib/mongoid/relations/many.rb +4 -0
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +1 -31
- data/lib/mongoid/relations/referenced/in.rb +19 -10
- data/lib/mongoid/relations/referenced/many.rb +30 -26
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +15 -1
- data/lib/mongoid/relations/synchronization.rb +12 -12
- data/lib/mongoid/relations/targets/enumerable.rb +24 -4
- data/lib/mongoid/relations/touchable.rb +7 -4
- data/lib/mongoid/reloadable.rb +2 -2
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +1 -1
- data/lib/mongoid/stateful.rb +1 -0
- data/lib/mongoid/tasks/database.rb +3 -2
- data/lib/mongoid/threaded.rb +74 -0
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +6 -6
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +18 -3
- data/spec/app/models/agent.rb +2 -0
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/array_field.rb +7 -0
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +3 -0
- data/spec/app/models/book.rb +2 -1
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/app/models/dokument.rb +1 -0
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/page.rb +1 -1
- data/spec/app/models/person.rb +3 -3
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/subscription.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +15 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +3 -3
- data/spec/mongoid/atomic_spec.rb +5 -5
- data/spec/mongoid/attributes/nested_spec.rb +18 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +90 -5
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +80 -28
- data/spec/mongoid/clients/options_spec.rb +396 -95
- data/spec/mongoid/clients/sessions_spec.rb +334 -0
- data/spec/mongoid/clients_spec.rb +243 -101
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +67 -11
- data/spec/mongoid/contextual/atomic_spec.rb +3 -3
- data/spec/mongoid/contextual/geo_near_spec.rb +1 -0
- data/spec/mongoid/contextual/mongo_spec.rb +275 -22
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +13 -4
- data/spec/mongoid/criteria/modifiable_spec.rb +297 -16
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin → criteria/queryable/extensions}/regexp_raw_spec.rb +2 -2
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +90 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1799 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4242 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +844 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +156 -22
- data/spec/mongoid/document_spec.rb +100 -90
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +321 -19
- data/spec/mongoid/extensions/boolean_spec.rb +14 -0
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +1 -1
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/hash_spec.rb +15 -0
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/regexp_spec.rb +23 -0
- data/spec/mongoid/extensions/string_spec.rb +53 -4
- data/spec/mongoid/extensions/time_spec.rb +2 -6
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/factory_spec.rb +11 -0
- data/spec/mongoid/fields_spec.rb +1 -1
- data/spec/mongoid/findable_spec.rb +47 -2
- data/spec/mongoid/indexable_spec.rb +15 -3
- data/spec/mongoid/interceptable_spec.rb +85 -19
- data/spec/mongoid/matchable/all_spec.rb +4 -4
- data/spec/mongoid/matchable/and_spec.rb +10 -10
- data/spec/mongoid/matchable/default_spec.rb +12 -12
- data/spec/mongoid/matchable/elem_match_spec.rb +86 -0
- data/spec/mongoid/matchable/exists_spec.rb +5 -5
- data/spec/mongoid/matchable/gt_spec.rb +18 -7
- data/spec/mongoid/matchable/gte_spec.rb +17 -7
- data/spec/mongoid/matchable/in_spec.rb +5 -5
- data/spec/mongoid/matchable/lt_spec.rb +18 -7
- data/spec/mongoid/matchable/lte_spec.rb +18 -7
- data/spec/mongoid/matchable/ne_spec.rb +5 -5
- data/spec/mongoid/matchable/nin_spec.rb +5 -5
- data/spec/mongoid/matchable/nor_spec.rb +209 -0
- data/spec/mongoid/matchable/or_spec.rb +7 -7
- data/spec/mongoid/matchable/regexp_spec.rb +5 -5
- data/spec/mongoid/matchable/size_spec.rb +3 -3
- data/spec/mongoid/matchable_spec.rb +199 -54
- data/spec/mongoid/persistable/creatable_spec.rb +7 -2
- data/spec/mongoid/persistable/deletable_spec.rb +35 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +25 -2
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +34 -29
- data/spec/mongoid/persistable/settable_spec.rb +77 -27
- data/spec/mongoid/persistable/updatable_spec.rb +182 -3
- data/spec/mongoid/persistable_spec.rb +16 -16
- data/spec/mongoid/persistence_context_spec.rb +694 -0
- data/spec/mongoid/positional_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +170 -12
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -3
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +16 -0
- data/spec/mongoid/relations/eager_spec.rb +40 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +305 -59
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +415 -7
- data/spec/mongoid/relations/metadata_spec.rb +15 -1
- data/spec/mongoid/relations/proxy_spec.rb +27 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +35 -25
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +14 -26
- data/spec/mongoid/relations/synchronization_spec.rb +48 -2
- data/spec/mongoid/relations/targets/enumerable_spec.rb +108 -0
- data/spec/mongoid/relations/touchable_spec.rb +40 -0
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +18 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +101 -8
- data/spec/support/cluster_config.rb +158 -0
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/session_registry.rb +50 -0
- data/spec/support/spec_config.rb +42 -0
- data.tar.gz.sig +0 -0
- metadata +163 -61
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/railties/document.rb +0 -12
- data/spec/mongoid/railties/document_spec.rb +0 -24
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Errors::InvalidRelation do
|
4
|
+
|
5
|
+
describe "#message" do
|
6
|
+
|
7
|
+
module MyModule
|
8
|
+
def crazy_method; self; end
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
Object.send(:include, MyModule)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:error) do
|
16
|
+
described_class.new(Person, :crazy_method)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "contains the problem in the message" do
|
20
|
+
expect(error.message).to include(
|
21
|
+
"Defining a relation named 'crazy_method' is not allowed."
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "contains the summary in the message" do
|
26
|
+
expect(error.message).to include(
|
27
|
+
"Defining this relation would override the method 'crazy_method'"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "contains the resolution in the message" do
|
32
|
+
expect(error.message).to include(
|
33
|
+
"Use Mongoid.destructive_fields to see what names are not allowed"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -50,15 +50,18 @@ describe Mongoid::Errors::MongoidError do
|
|
50
50
|
describe "#to_json" do
|
51
51
|
|
52
52
|
it "has problem" do
|
53
|
-
|
53
|
+
# @todo: uncomment if https://github.com/rails/rails/pull/24628 is merged
|
54
|
+
#expect(error.to_json).to include('"problem":"message"')
|
54
55
|
end
|
55
56
|
|
56
57
|
it "has summary" do
|
57
|
-
|
58
|
+
# @todo: uncomment if https://github.com/rails/rails/pull/24628 is merged
|
59
|
+
#expect(error.to_json).to include('"summary":"summary"')
|
58
60
|
end
|
59
61
|
|
60
62
|
it "has resolution" do
|
61
|
-
|
63
|
+
# @todo: uncomment if https://github.com/rails/rails/pull/24628 is merged
|
64
|
+
#expect(error.to_json).to include('"resolution":"resolution"')
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
@@ -2,16 +2,64 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid::Extensions::BigDecimal do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
BigDecimal
|
5
|
+
let(:big_decimal) do
|
6
|
+
BigDecimal("123456.789")
|
7
7
|
end
|
8
8
|
|
9
9
|
describe ".demongoize" do
|
10
10
|
|
11
|
-
context "when the
|
11
|
+
context "when the value is an empty String" do
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
let(:string) do
|
14
|
+
""
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns nil" do
|
18
|
+
expect(BigDecimal.demongoize(string)).to be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when the value is a numeric String" do
|
23
|
+
|
24
|
+
let(:string) do
|
25
|
+
"123456.789"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a BigDecimal" do
|
29
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the value is the numeric String zero" do
|
34
|
+
|
35
|
+
let(:string) do
|
36
|
+
"0.0"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns a BigDecimal" do
|
40
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when the value is the numeric String negative zero" do
|
45
|
+
|
46
|
+
let(:string) do
|
47
|
+
"-0.0"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a BigDecimal" do
|
51
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the value is a non-numeric String" do
|
56
|
+
|
57
|
+
let(:string) do
|
58
|
+
"1a2"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns nil" do
|
62
|
+
expect(BigDecimal.demongoize(string)).to be_nil
|
15
63
|
end
|
16
64
|
end
|
17
65
|
|
@@ -22,18 +70,29 @@ describe Mongoid::Extensions::BigDecimal do
|
|
22
70
|
end
|
23
71
|
end
|
24
72
|
|
25
|
-
context "when the value is
|
73
|
+
context "when the value is true" do
|
26
74
|
|
27
|
-
let(:
|
28
|
-
|
75
|
+
let(:value) do
|
76
|
+
true
|
29
77
|
end
|
30
78
|
|
31
|
-
it "returns
|
32
|
-
expect(BigDecimal.demongoize(
|
79
|
+
it "returns nil" do
|
80
|
+
expect(BigDecimal.demongoize(value)).to be_nil
|
33
81
|
end
|
34
82
|
end
|
35
83
|
|
36
|
-
context "when the value is
|
84
|
+
context "when the value is false" do
|
85
|
+
|
86
|
+
let(:value) do
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns nil" do
|
91
|
+
expect(BigDecimal.demongoize(value)).to be_nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "when the value is an Integer" do
|
37
96
|
|
38
97
|
let(:integer) do
|
39
98
|
123456
|
@@ -44,7 +103,18 @@ describe Mongoid::Extensions::BigDecimal do
|
|
44
103
|
end
|
45
104
|
end
|
46
105
|
|
47
|
-
context "when the value is
|
106
|
+
context "when the value is a Float" do
|
107
|
+
|
108
|
+
let(:float) do
|
109
|
+
123456.789
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns a float" do
|
113
|
+
expect(BigDecimal.demongoize(float)).to eq(float)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when the value is the String 'NaN'" do
|
48
118
|
|
49
119
|
let(:nan) do
|
50
120
|
"NaN"
|
@@ -54,22 +124,126 @@ describe Mongoid::Extensions::BigDecimal do
|
|
54
124
|
BigDecimal.demongoize(nan)
|
55
125
|
end
|
56
126
|
|
57
|
-
it "returns a
|
127
|
+
it "returns a BigDecimal" do
|
58
128
|
expect(demongoized).to be_a(BigDecimal)
|
59
129
|
end
|
60
130
|
|
61
|
-
it "is a NaN
|
131
|
+
it "is a NaN BigDecimal" do
|
62
132
|
expect(demongoized).to be_nan
|
63
133
|
end
|
64
134
|
end
|
135
|
+
|
136
|
+
context "when the value is the String 'Infinity'" do
|
137
|
+
|
138
|
+
let(:infinity) do
|
139
|
+
"Infinity"
|
140
|
+
end
|
141
|
+
|
142
|
+
let(:demongoized) do
|
143
|
+
BigDecimal.demongoize(infinity)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "returns a BigDecimal" do
|
147
|
+
expect(demongoized).to be_a(BigDecimal)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "is a infinity BigDecimal" do
|
151
|
+
expect(demongoized.infinite?).to eq 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when the value is the String '-Infinity'" do
|
156
|
+
|
157
|
+
let(:neg_infinity) do
|
158
|
+
"-Infinity"
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:demongoized) do
|
162
|
+
BigDecimal.demongoize(neg_infinity)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "returns a BigDecimal" do
|
166
|
+
expect(demongoized).to be_a(BigDecimal)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "is a negative infinity BigDecimal" do
|
170
|
+
expect(demongoized.infinite?).to eq -1
|
171
|
+
end
|
172
|
+
end
|
65
173
|
end
|
66
174
|
|
67
175
|
describe ".mongoize" do
|
68
176
|
|
69
|
-
context "when the value is a
|
177
|
+
context "when the value is a BigDecimal" do
|
70
178
|
|
71
179
|
it "returns a string" do
|
72
|
-
expect(BigDecimal.mongoize(
|
180
|
+
expect(BigDecimal.mongoize(big_decimal)).to eq(big_decimal.to_s)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when the value is the BigDecimal zero" do
|
185
|
+
|
186
|
+
let(:big_decimal) do
|
187
|
+
BigDecimal("0.0")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "returns a BigDecimal" do
|
191
|
+
expect(BigDecimal.mongoize(big_decimal)).to eq(big_decimal.to_s)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "when the value is the BigDecimal negative zero" do
|
196
|
+
|
197
|
+
let(:big_decimal) do
|
198
|
+
BigDecimal("-0.0")
|
199
|
+
end
|
200
|
+
|
201
|
+
it "returns a BigDecimal" do
|
202
|
+
expect(BigDecimal.mongoize(big_decimal)).to eq(big_decimal.to_s)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "when the value is an empty String" do
|
207
|
+
|
208
|
+
let(:string) do
|
209
|
+
""
|
210
|
+
end
|
211
|
+
|
212
|
+
it "returns nil" do
|
213
|
+
expect(BigDecimal.mongoize(string)).to be_nil
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "when the value is an integer numeric String" do
|
218
|
+
|
219
|
+
let(:string) do
|
220
|
+
"123456"
|
221
|
+
end
|
222
|
+
|
223
|
+
it "returns the String" do
|
224
|
+
expect(BigDecimal.mongoize(string)).to eq string
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context "when the value is a float numeric String" do
|
229
|
+
|
230
|
+
let(:string) do
|
231
|
+
"123456.789"
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns the String" do
|
235
|
+
expect(BigDecimal.mongoize(string)).to eq string
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context "when the value is a non-numeric String" do
|
240
|
+
|
241
|
+
let(:string) do
|
242
|
+
"1a2"
|
243
|
+
end
|
244
|
+
|
245
|
+
it "returns nil" do
|
246
|
+
expect(BigDecimal.mongoize(string)).to be_nil
|
73
247
|
end
|
74
248
|
end
|
75
249
|
|
@@ -80,25 +254,153 @@ describe Mongoid::Extensions::BigDecimal do
|
|
80
254
|
end
|
81
255
|
end
|
82
256
|
|
83
|
-
context "when the value is
|
257
|
+
context "when the value is true" do
|
258
|
+
|
259
|
+
let(:value) do
|
260
|
+
true
|
261
|
+
end
|
262
|
+
|
263
|
+
it "returns nil" do
|
264
|
+
expect(BigDecimal.mongoize(value)).to be_nil
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "when the value is false" do
|
269
|
+
|
270
|
+
let(:value) do
|
271
|
+
false
|
272
|
+
end
|
273
|
+
|
274
|
+
it "returns nil" do
|
275
|
+
expect(BigDecimal.mongoize(value)).to be_nil
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context "when the value is an Integer" do
|
84
280
|
|
85
281
|
it "returns a string" do
|
86
282
|
expect(BigDecimal.mongoize(123456)).to eq("123456")
|
87
283
|
end
|
88
284
|
end
|
89
285
|
|
90
|
-
context "when the value is a
|
286
|
+
context "when the value is a Float" do
|
91
287
|
|
92
288
|
it "returns a string" do
|
93
289
|
expect(BigDecimal.mongoize(123456.789)).to eq("123456.789")
|
94
290
|
end
|
95
291
|
end
|
292
|
+
|
293
|
+
context "when the value is String NaN" do
|
294
|
+
|
295
|
+
let(:nan) do
|
296
|
+
"NaN"
|
297
|
+
end
|
298
|
+
|
299
|
+
it "returns a String" do
|
300
|
+
expect(BigDecimal.mongoize(nan)).to eq("NaN")
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "when the value is String Infinity" do
|
305
|
+
|
306
|
+
let(:infinity) do
|
307
|
+
"Infinity"
|
308
|
+
end
|
309
|
+
|
310
|
+
it "returns a String" do
|
311
|
+
expect(BigDecimal.mongoize(infinity)).to eq("Infinity")
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "when the value is String negative Infinity" do
|
316
|
+
|
317
|
+
let(:neg_infinity) do
|
318
|
+
"-Infinity"
|
319
|
+
end
|
320
|
+
|
321
|
+
it "returns a String" do
|
322
|
+
expect(BigDecimal.mongoize(neg_infinity)).to eq("-Infinity")
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context "when the value is BigDecimal NaN" do
|
327
|
+
|
328
|
+
let(:nan) do
|
329
|
+
BigDecimal("NaN")
|
330
|
+
end
|
331
|
+
|
332
|
+
it "returns a String" do
|
333
|
+
expect(BigDecimal.mongoize(nan)).to eq("NaN")
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
context "when the value is BigDecimal Infinity" do
|
338
|
+
|
339
|
+
let(:infinity) do
|
340
|
+
BigDecimal("Infinity")
|
341
|
+
end
|
342
|
+
|
343
|
+
it "returns a String" do
|
344
|
+
expect(BigDecimal.mongoize(infinity)).to eq("Infinity")
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context "when the value is BigDecimal negative Infinity" do
|
349
|
+
|
350
|
+
let(:neg_infinity) do
|
351
|
+
BigDecimal("-Infinity")
|
352
|
+
end
|
353
|
+
|
354
|
+
it "returns a String" do
|
355
|
+
expect(BigDecimal.mongoize(neg_infinity)).to eq("-Infinity")
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context "when the value is the constant Float::NAN" do
|
360
|
+
|
361
|
+
let(:nan) do
|
362
|
+
Float::NAN
|
363
|
+
end
|
364
|
+
|
365
|
+
it "returns a String" do
|
366
|
+
expect(BigDecimal.mongoize(nan)).to eq("NaN")
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context "when the value is constant Float::INFINITY" do
|
371
|
+
|
372
|
+
let(:infinity) do
|
373
|
+
Float::INFINITY
|
374
|
+
end
|
375
|
+
|
376
|
+
it "returns a String" do
|
377
|
+
expect(BigDecimal.mongoize(infinity)).to eq("Infinity")
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context "when the value is constant Float::INFINITY * -1" do
|
382
|
+
|
383
|
+
let(:neg_infinity) do
|
384
|
+
Float::INFINITY * -1
|
385
|
+
end
|
386
|
+
|
387
|
+
it "returns a String" do
|
388
|
+
expect(BigDecimal.mongoize(neg_infinity)).to eq("-Infinity")
|
389
|
+
end
|
390
|
+
end
|
96
391
|
end
|
97
392
|
|
98
393
|
describe "#mongoize" do
|
99
394
|
|
100
395
|
it "returns a string" do
|
101
|
-
expect(
|
396
|
+
expect(big_decimal.mongoize).to eq(big_decimal.to_s)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
describe "#numeric?" do
|
401
|
+
|
402
|
+
it "returns true" do
|
403
|
+
expect(big_decimal.numeric?).to eq(true)
|
102
404
|
end
|
103
405
|
end
|
104
406
|
end
|
@@ -82,6 +82,13 @@ describe Mongoid::Boolean do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
context "when provided on" do
|
86
|
+
|
87
|
+
it "returns true" do
|
88
|
+
expect(described_class.mongoize("on")).to eq(true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
85
92
|
context "when provided false" do
|
86
93
|
|
87
94
|
it "returns false" do
|
@@ -123,6 +130,13 @@ describe Mongoid::Boolean do
|
|
123
130
|
expect(described_class.mongoize("n")).to eq(false)
|
124
131
|
end
|
125
132
|
end
|
133
|
+
|
134
|
+
context "when provided off" do
|
135
|
+
|
136
|
+
it "returns true" do
|
137
|
+
expect(described_class.mongoize("off")).to eq(false)
|
138
|
+
end
|
139
|
+
end
|
126
140
|
end
|
127
141
|
end
|
128
142
|
|
@@ -135,12 +135,8 @@ describe Mongoid::Extensions::Date do
|
|
135
135
|
|
136
136
|
context "when the string is an invalid time" do
|
137
137
|
|
138
|
-
|
139
|
-
Date.
|
140
|
-
end
|
141
|
-
|
142
|
-
it "returns epoch" do
|
143
|
-
expect(Date.mongoize("time")).to eq(epoch)
|
138
|
+
it "returns nil" do
|
139
|
+
expect(Date.mongoize("time")).to eq(nil)
|
144
140
|
end
|
145
141
|
end
|
146
142
|
end
|
@@ -129,12 +129,8 @@ describe Mongoid::Extensions::DateTime do
|
|
129
129
|
|
130
130
|
context "when the string is an invalid time" do
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
it "returns epoch" do
|
137
|
-
expect(DateTime.mongoize("time")).to eq(epoch)
|
132
|
+
it "returns nil" do
|
133
|
+
expect(DateTime.mongoize("time")).to eq(nil)
|
138
134
|
end
|
139
135
|
end
|
140
136
|
end
|
@@ -23,7 +23,7 @@ describe Mongoid::Extensions::Float do
|
|
23
23
|
|
24
24
|
describe ".demongoize" do
|
25
25
|
|
26
|
-
context "when the
|
26
|
+
context "when the value is a float" do
|
27
27
|
|
28
28
|
it "returns a float" do
|
29
29
|
expect(Float.demongoize(number)).to eq(number)
|
@@ -144,4 +144,11 @@ describe Mongoid::Extensions::Float do
|
|
144
144
|
expect(number.mongoize).to eq(number)
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
describe "#numeric?" do
|
149
|
+
|
150
|
+
it "returns true" do
|
151
|
+
expect(number.numeric?).to eq(true)
|
152
|
+
end
|
153
|
+
end
|
147
154
|
end
|
@@ -247,6 +247,21 @@ describe Mongoid::Extensions::Hash do
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
+
context "when the parent key is not present" do
|
251
|
+
|
252
|
+
let(:hash) do
|
253
|
+
{ "101" => { "name" => "hundred and one" } }
|
254
|
+
end
|
255
|
+
|
256
|
+
let(:nested) do
|
257
|
+
hash.__nested__("100.name")
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return nil" do
|
261
|
+
expect(nested).to eq(nil)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
250
265
|
describe ".demongoize" do
|
251
266
|
|
252
267
|
let(:hash) do
|
@@ -23,7 +23,7 @@ describe Mongoid::Extensions::Integer do
|
|
23
23
|
|
24
24
|
describe ".demongoize" do
|
25
25
|
|
26
|
-
context "when the
|
26
|
+
context "when the value is an integer" do
|
27
27
|
|
28
28
|
it "returns a integer" do
|
29
29
|
expect(Integer.demongoize(number)).to eq(number)
|
@@ -133,4 +133,11 @@ describe Mongoid::Extensions::Integer do
|
|
133
133
|
expect(number.mongoize).to eq(number)
|
134
134
|
end
|
135
135
|
end
|
136
|
+
|
137
|
+
describe "#numeric?" do
|
138
|
+
|
139
|
+
it "returns true" do
|
140
|
+
expect(number.numeric?).to eq(true)
|
141
|
+
end
|
142
|
+
end
|
136
143
|
end
|
@@ -35,6 +35,29 @@ describe Mongoid::Extensions::Regexp do
|
|
35
35
|
it "returns the provided value as a regex" do
|
36
36
|
expect(value).to eq(/[^abc]/)
|
37
37
|
end
|
38
|
+
|
39
|
+
|
40
|
+
context "when the string is empty" do
|
41
|
+
|
42
|
+
let(:value) do
|
43
|
+
Regexp.mongoize("")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns an empty regex" do
|
47
|
+
expect(value).to eq(//)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the value is nil" do
|
53
|
+
|
54
|
+
let(:value) do
|
55
|
+
Regexp.mongoize(nil)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns the nil" do
|
59
|
+
expect(value).to be_nil
|
60
|
+
end
|
38
61
|
end
|
39
62
|
end
|
40
63
|
|