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
@@ -2934,16 +2934,16 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2934
2934
|
it "applies the criteria to the documents" do
|
2935
2935
|
expect(posts).to eq([ post_one ])
|
2936
2936
|
end
|
2937
|
-
end
|
2938
2937
|
|
2939
|
-
|
2938
|
+
context 'when providing a collation', if: collation_supported? do
|
2940
2939
|
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2940
|
+
let(:posts) do
|
2941
|
+
person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
|
2942
|
+
end
|
2944
2943
|
|
2945
|
-
|
2946
|
-
|
2944
|
+
it "applies the collation option to the query" do
|
2945
|
+
expect(posts).to eq([ post_one ])
|
2946
|
+
end
|
2947
2947
|
end
|
2948
2948
|
end
|
2949
2949
|
|
@@ -3504,12 +3504,10 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3504
3504
|
|
3505
3505
|
before do
|
3506
3506
|
expect(artist).to receive(:before_add_album).and_raise
|
3507
|
+
begin; artist.albums << album; rescue; end
|
3507
3508
|
end
|
3508
3509
|
|
3509
3510
|
it "does not add the document to the relation" do
|
3510
|
-
expect {
|
3511
|
-
artist.albums << album
|
3512
|
-
}.to raise_error
|
3513
3511
|
expect(artist.albums).to be_empty
|
3514
3512
|
end
|
3515
3513
|
end
|
@@ -3534,12 +3532,10 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3534
3532
|
|
3535
3533
|
before do
|
3536
3534
|
expect(artist).to receive(:after_add_album).and_raise
|
3535
|
+
begin; artist.albums << album; rescue; end
|
3537
3536
|
end
|
3538
3537
|
|
3539
3538
|
it "adds the document to the relation" do
|
3540
|
-
expect {
|
3541
|
-
artist.albums << album
|
3542
|
-
}.to raise_error
|
3543
3539
|
expect(artist.albums).to eq([ album ])
|
3544
3540
|
end
|
3545
3541
|
end
|
@@ -3618,9 +3614,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3618
3614
|
describe "#delete" do
|
3619
3615
|
|
3620
3616
|
before do
|
3621
|
-
|
3622
|
-
artist.albums.delete album
|
3623
|
-
}.to raise_error
|
3617
|
+
begin; artist.albums.delete(album); rescue; end
|
3624
3618
|
end
|
3625
3619
|
|
3626
3620
|
it "does not remove the document from the relation" do
|
@@ -3631,9 +3625,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3631
3625
|
describe "#clear" do
|
3632
3626
|
|
3633
3627
|
before do
|
3634
|
-
|
3635
|
-
artist.albums.clear
|
3636
|
-
}.to raise_error
|
3628
|
+
begin; artist.albums.clear; rescue; end
|
3637
3629
|
end
|
3638
3630
|
|
3639
3631
|
it "does not clear the relation" do
|
@@ -3693,9 +3685,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3693
3685
|
describe "#delete" do
|
3694
3686
|
|
3695
3687
|
before do
|
3696
|
-
|
3697
|
-
artist.albums.delete album
|
3698
|
-
}.to raise_error
|
3688
|
+
begin; artist.albums.delete(album); rescue; end
|
3699
3689
|
end
|
3700
3690
|
|
3701
3691
|
it "removes the documents from the relation" do
|
@@ -3706,9 +3696,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3706
3696
|
describe "#clear" do
|
3707
3697
|
|
3708
3698
|
before do
|
3709
|
-
|
3710
|
-
artist.albums.clear
|
3711
|
-
}.to raise_error
|
3699
|
+
begin; artist.albums.clear; rescue; end
|
3712
3700
|
end
|
3713
3701
|
|
3714
3702
|
it "removes the documents from the relation" do
|
@@ -3803,4 +3791,26 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3803
3791
|
expect(agent.save).to be(true)
|
3804
3792
|
end
|
3805
3793
|
end
|
3794
|
+
|
3795
|
+
context 'when the two models use the same name to refer to the relation' do
|
3796
|
+
|
3797
|
+
let(:agent) do
|
3798
|
+
Agent.new
|
3799
|
+
end
|
3800
|
+
|
3801
|
+
let(:band) do
|
3802
|
+
Band.new
|
3803
|
+
end
|
3804
|
+
|
3805
|
+
before do
|
3806
|
+
agent.same_name = band
|
3807
|
+
agent.save
|
3808
|
+
band.save
|
3809
|
+
band.reload
|
3810
|
+
end
|
3811
|
+
|
3812
|
+
it 'constructs the correct criteria' do
|
3813
|
+
expect(band.same_name).to eq([agent])
|
3814
|
+
end
|
3815
|
+
end
|
3806
3816
|
end
|
@@ -5,7 +5,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
5
5
|
before(:all) do
|
6
6
|
Mongoid.raise_not_found_error = true
|
7
7
|
Person.autosave(Person.relations["preferences"].merge!(autosave: true))
|
8
|
-
Person.
|
8
|
+
Person._synced(Person.relations["preferences"])
|
9
9
|
end
|
10
10
|
|
11
11
|
after(:all) do
|
@@ -516,12 +516,10 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
516
516
|
|
517
517
|
before do
|
518
518
|
expect(post).to receive(:before_add_tag).and_raise
|
519
|
+
begin; post.tags.send(method, tag); rescue; end;
|
519
520
|
end
|
520
521
|
|
521
522
|
it "does not add the document to the relation" do
|
522
|
-
expect {
|
523
|
-
post.tags.send(method, tag)
|
524
|
-
}.to raise_error
|
525
523
|
expect(post.tags).to be_empty
|
526
524
|
end
|
527
525
|
end
|
@@ -538,12 +536,10 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
538
536
|
|
539
537
|
before do
|
540
538
|
expect(post).to receive(:after_add_tag).and_raise
|
539
|
+
begin; post.tags.send(method, tag); rescue; end
|
541
540
|
end
|
542
541
|
|
543
542
|
it "adds the document to the relation" do
|
544
|
-
expect {
|
545
|
-
post.tags.send(method, tag)
|
546
|
-
}.to raise_error
|
547
543
|
expect(post.tags).to eq([ tag ])
|
548
544
|
end
|
549
545
|
end
|
@@ -1186,12 +1182,10 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
1186
1182
|
|
1187
1183
|
before do
|
1188
1184
|
expect(post).to receive(:before_remove_tag).and_raise
|
1185
|
+
begin; post.tags.clear; rescue; end
|
1189
1186
|
end
|
1190
1187
|
|
1191
1188
|
it "does not remove the document from the relation" do
|
1192
|
-
expect {
|
1193
|
-
post.tags.clear
|
1194
|
-
}.to raise_error
|
1195
1189
|
expect(post.tags).to eq([ tag ])
|
1196
1190
|
end
|
1197
1191
|
end
|
@@ -1218,12 +1212,10 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
1218
1212
|
|
1219
1213
|
before do
|
1220
1214
|
expect(post).to receive(:after_remove_tag).and_raise
|
1215
|
+
begin; post.tags.clear; rescue; end
|
1221
1216
|
end
|
1222
1217
|
|
1223
1218
|
it "removes the document from the relation" do
|
1224
|
-
expect {
|
1225
|
-
post.tags.clear
|
1226
|
-
}.to raise_error
|
1227
1219
|
expect(post.tags).to be_empty
|
1228
1220
|
end
|
1229
1221
|
end
|
@@ -2120,12 +2112,10 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
2120
2112
|
|
2121
2113
|
before do
|
2122
2114
|
expect(post).to receive(:before_remove_tag).and_raise
|
2115
|
+
begin; post.tags.delete(tag); rescue; end
|
2123
2116
|
end
|
2124
2117
|
|
2125
2118
|
it "does not remove the document from the relation" do
|
2126
|
-
expect {
|
2127
|
-
post.tags.delete tag
|
2128
|
-
}.to raise_error
|
2129
2119
|
expect(post.tags).to eq([ tag ])
|
2130
2120
|
end
|
2131
2121
|
end
|
@@ -2152,12 +2142,10 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
2152
2142
|
|
2153
2143
|
before do
|
2154
2144
|
expect(post).to receive(:after_remove_tag).and_raise
|
2145
|
+
begin; post.tags.delete(tag); rescue; end
|
2155
2146
|
end
|
2156
2147
|
|
2157
2148
|
it "removes the document from the relation" do
|
2158
|
-
expect {
|
2159
|
-
post.tags.delete(tag)
|
2160
|
-
}.to raise_error
|
2161
2149
|
expect(post.tags).to be_empty
|
2162
2150
|
end
|
2163
2151
|
end
|
@@ -2652,16 +2640,16 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
2652
2640
|
it "applies the criteria to the documents" do
|
2653
2641
|
expect(preferences).to eq([ preference_one ])
|
2654
2642
|
end
|
2655
|
-
end
|
2656
2643
|
|
2657
|
-
|
2644
|
+
context 'when providing a collation', if: collation_supported? do
|
2658
2645
|
|
2659
|
-
|
2660
|
-
|
2661
|
-
|
2646
|
+
let(:preferences) do
|
2647
|
+
person.preferences.where(name: "FIRST").collation(locale: 'en_US', strength: 2).to_a
|
2648
|
+
end
|
2662
2649
|
|
2663
|
-
|
2664
|
-
|
2650
|
+
it "applies the collation option to the query" do
|
2651
|
+
expect(preferences).to eq([ preference_one ])
|
2652
|
+
end
|
2665
2653
|
end
|
2666
2654
|
end
|
2667
2655
|
|
@@ -4,7 +4,7 @@ describe Mongoid::Relations::Synchronization do
|
|
4
4
|
|
5
5
|
before(:all) do
|
6
6
|
Mongoid.raise_not_found_error = true
|
7
|
-
Person.
|
7
|
+
Person._synced(Person.relations["preferences"])
|
8
8
|
end
|
9
9
|
|
10
10
|
after(:all) do
|
@@ -12,6 +12,52 @@ describe Mongoid::Relations::Synchronization do
|
|
12
12
|
Person.reset_callbacks(:destroy)
|
13
13
|
end
|
14
14
|
|
15
|
+
describe 'Model loading' do
|
16
|
+
|
17
|
+
let(:model_synced) do
|
18
|
+
class TestModel
|
19
|
+
include Mongoid::Document
|
20
|
+
field :_synced
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:model_synced?) do
|
25
|
+
class TestModel
|
26
|
+
include Mongoid::Document
|
27
|
+
field :_synced?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:model_syncable?) do
|
32
|
+
class TestModel
|
33
|
+
include Mongoid::Document
|
34
|
+
field :_syncable?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
Object.send(:remove_const, :TestModel)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'prohibits the use of :_sycned as an attribute' do
|
43
|
+
expect {
|
44
|
+
model_synced
|
45
|
+
}.to raise_exception(Mongoid::Errors::InvalidField)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'prohibits the use of :_synced? as an attribute' do
|
49
|
+
expect {
|
50
|
+
model_synced?
|
51
|
+
}.to raise_exception(Mongoid::Errors::InvalidField)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'prohibits the use of :_syncable? as an attribute' do
|
55
|
+
expect {
|
56
|
+
model_syncable?
|
57
|
+
}.to raise_exception(Mongoid::Errors::InvalidField)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
15
61
|
describe ".update_inverse_keys" do
|
16
62
|
|
17
63
|
let(:agent) do
|
@@ -119,7 +165,7 @@ describe Mongoid::Relations::Synchronization do
|
|
119
165
|
end
|
120
166
|
|
121
167
|
it "resets the synced flag" do
|
122
|
-
expect(person.
|
168
|
+
expect(person._synced["preference_ids"]).to be false
|
123
169
|
end
|
124
170
|
|
125
171
|
context "when subsequently setting with keys" do
|
@@ -928,6 +928,60 @@ describe Mongoid::Relations::Targets::Enumerable do
|
|
928
928
|
end
|
929
929
|
end
|
930
930
|
end
|
931
|
+
|
932
|
+
context 'when the id_sort option is none' do
|
933
|
+
|
934
|
+
let(:person) do
|
935
|
+
Person.create
|
936
|
+
end
|
937
|
+
|
938
|
+
let(:criteria) do
|
939
|
+
Post.where(person_id: person.id)
|
940
|
+
end
|
941
|
+
|
942
|
+
let(:enumerable) do
|
943
|
+
described_class.new(criteria)
|
944
|
+
end
|
945
|
+
|
946
|
+
let!(:first_post) do
|
947
|
+
person.posts.create(title: "One")
|
948
|
+
end
|
949
|
+
|
950
|
+
let!(:second_post) do
|
951
|
+
person.posts.create(title: "Two")
|
952
|
+
end
|
953
|
+
|
954
|
+
it 'does not use the sort on id' do
|
955
|
+
expect(enumerable.first(id_sort: :none)).to eq(first_post)
|
956
|
+
end
|
957
|
+
end
|
958
|
+
|
959
|
+
context 'when the id_sort option is not provided' do
|
960
|
+
|
961
|
+
let(:person) do
|
962
|
+
Person.create
|
963
|
+
end
|
964
|
+
|
965
|
+
let(:criteria) do
|
966
|
+
Post.where(person_id: person.id)
|
967
|
+
end
|
968
|
+
|
969
|
+
let(:enumerable) do
|
970
|
+
described_class.new(criteria)
|
971
|
+
end
|
972
|
+
|
973
|
+
let!(:first_post) do
|
974
|
+
person.posts.create(title: "One")
|
975
|
+
end
|
976
|
+
|
977
|
+
let!(:second_post) do
|
978
|
+
person.posts.create(title: "Two")
|
979
|
+
end
|
980
|
+
|
981
|
+
it 'uses the sort on id' do
|
982
|
+
expect(enumerable.first).to eq(first_post)
|
983
|
+
end
|
984
|
+
end
|
931
985
|
end
|
932
986
|
|
933
987
|
describe "#include?" do
|
@@ -1344,6 +1398,60 @@ describe Mongoid::Relations::Targets::Enumerable do
|
|
1344
1398
|
end
|
1345
1399
|
end
|
1346
1400
|
end
|
1401
|
+
|
1402
|
+
context 'when the id_sort option is none' do
|
1403
|
+
|
1404
|
+
let(:person) do
|
1405
|
+
Person.create
|
1406
|
+
end
|
1407
|
+
|
1408
|
+
let(:criteria) do
|
1409
|
+
Post.where(person_id: person.id)
|
1410
|
+
end
|
1411
|
+
|
1412
|
+
let(:enumerable) do
|
1413
|
+
described_class.new(criteria)
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
let!(:first_post) do
|
1417
|
+
person.posts.create(title: "One")
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
let!(:second_post) do
|
1421
|
+
person.posts.create(title: "Two")
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
it 'does not use the sort on id' do
|
1425
|
+
expect(enumerable.last(id_sort: :none)).to eq(first_post)
|
1426
|
+
end
|
1427
|
+
end
|
1428
|
+
|
1429
|
+
context 'when the id_sort option is not provided' do
|
1430
|
+
|
1431
|
+
let(:person) do
|
1432
|
+
Person.create
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
let(:criteria) do
|
1436
|
+
Post.where(person_id: person.id)
|
1437
|
+
end
|
1438
|
+
|
1439
|
+
let(:enumerable) do
|
1440
|
+
described_class.new(criteria)
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
let!(:first_post) do
|
1444
|
+
person.posts.create(title: "One")
|
1445
|
+
end
|
1446
|
+
|
1447
|
+
let!(:second_post) do
|
1448
|
+
person.posts.create(title: "Two")
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
it 'uses the sort on id' do
|
1452
|
+
expect(enumerable.last).to eq(second_post)
|
1453
|
+
end
|
1454
|
+
end
|
1347
1455
|
end
|
1348
1456
|
|
1349
1457
|
describe "#kind_of?" do
|
@@ -227,6 +227,44 @@ describe Mongoid::Relations::Touchable do
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
230
|
+
context "when the parent of embedded doc has cascade callbacks" do
|
231
|
+
|
232
|
+
let!(:book) do
|
233
|
+
Book.new
|
234
|
+
end
|
235
|
+
|
236
|
+
before do
|
237
|
+
book.pages.new
|
238
|
+
book.save
|
239
|
+
book.unset(:updated_at)
|
240
|
+
book.pages.first.touch
|
241
|
+
end
|
242
|
+
|
243
|
+
it "touches the parent document" do
|
244
|
+
expect(book.updated_at).to be_within(5).of(Time.now)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context "when multiple embedded docs with cascade callbacks" do
|
249
|
+
|
250
|
+
let!(:book) do
|
251
|
+
Book.new
|
252
|
+
end
|
253
|
+
|
254
|
+
before do
|
255
|
+
2.times { book.pages.new }
|
256
|
+
book.save
|
257
|
+
book.unset(:updated_at)
|
258
|
+
book.pages.first.content = "foo"
|
259
|
+
book.pages.second.content = "bar"
|
260
|
+
book.pages.first.touch
|
261
|
+
end
|
262
|
+
|
263
|
+
it "touches the parent document" do
|
264
|
+
expect(book.updated_at).to be_within(5).of(Time.now)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
230
268
|
context "when the relation is nil" do
|
231
269
|
|
232
270
|
let!(:agent) do
|
@@ -343,6 +381,7 @@ describe Mongoid::Relations::Touchable do
|
|
343
381
|
end
|
344
382
|
|
345
383
|
it "does not persist other attribute changes" do
|
384
|
+
expect(band.name).to eq('Nocebo')
|
346
385
|
expect(band.reload.name).not_to eq('Nocebo')
|
347
386
|
end
|
348
387
|
end
|
@@ -354,6 +393,7 @@ describe Mongoid::Relations::Touchable do
|
|
354
393
|
end
|
355
394
|
|
356
395
|
it "does not persist other attribute changes" do
|
396
|
+
expect(band.name).to eq('Nocebo')
|
357
397
|
expect(band.reload.name).not_to eq('Nocebo')
|
358
398
|
end
|
359
399
|
end
|
@@ -4,6 +4,25 @@ describe Mongoid::Reloadable do
|
|
4
4
|
|
5
5
|
describe "#reload" do
|
6
6
|
|
7
|
+
context 'when persistence options are set' do
|
8
|
+
|
9
|
+
let(:person) do
|
10
|
+
Person.with(collection: 'other') do |person_class|
|
11
|
+
person_class.create
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:reloaded) do
|
16
|
+
Person.with(collection: 'other') do |person_class|
|
17
|
+
person_class.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'applies the persistence options' do
|
22
|
+
expect(person).to eq(reloaded)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
7
26
|
context "when using bson ids" do
|
8
27
|
|
9
28
|
let(:person) do
|
@@ -106,6 +125,38 @@ describe Mongoid::Reloadable do
|
|
106
125
|
|
107
126
|
context "when embedded a single level" do
|
108
127
|
|
128
|
+
context 'when persistence options are set' do
|
129
|
+
|
130
|
+
let(:person) do
|
131
|
+
Person.with(collection: 'other') do |person_class|
|
132
|
+
person_class.create
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
let!(:address) do
|
137
|
+
person.with(collection: 'other') do |person_object|
|
138
|
+
person_object.addresses.create(street: "Abbey Road", number: 4)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
before do
|
143
|
+
Person.mongo_client[:other].find(
|
144
|
+
{ "_id" => person.id }
|
145
|
+
).update_one({ "$set" => { "addresses.0.number" => 3 }})
|
146
|
+
end
|
147
|
+
|
148
|
+
let!(:reloaded) do
|
149
|
+
person.with(collection: 'other') do |person_class|
|
150
|
+
person.addresses.first.reload
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "reloads the embedded document attributes" do
|
155
|
+
expect(reloaded.number).to eq(3)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
109
160
|
context "when the relation is an embeds many" do
|
110
161
|
|
111
162
|
let!(:address) do
|
@@ -1130,6 +1130,19 @@ describe Mongoid::Scopable do
|
|
1130
1130
|
it "sets the threading options" do
|
1131
1131
|
Band.without_default_scope do
|
1132
1132
|
expect(Mongoid::Threaded).to be_executing(:without_default_scope)
|
1133
|
+
expect(Mongoid::Threaded.without_default_scope?(Band)).to be(true)
|
1134
|
+
end
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
it "suppresses default scope on the given model within the given block" do
|
1138
|
+
Appointment.without_default_scope do
|
1139
|
+
expect(Appointment.all.selector).to be_empty
|
1140
|
+
end
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
it "does not affect other models' default scopes within the given block" do
|
1144
|
+
Appointment.without_default_scope do
|
1145
|
+
expect(Audio.all.selector).not_to be_empty
|
1133
1146
|
end
|
1134
1147
|
end
|
1135
1148
|
end
|
@@ -829,54 +829,4 @@ describe Mongoid::Serializable do
|
|
829
829
|
end
|
830
830
|
end
|
831
831
|
end
|
832
|
-
|
833
|
-
describe "#to_xml" do
|
834
|
-
|
835
|
-
context "BSON::ObjectId" do
|
836
|
-
|
837
|
-
let(:person) do
|
838
|
-
Person.new
|
839
|
-
end
|
840
|
-
|
841
|
-
it "serializes as string" do
|
842
|
-
expect(person.to_xml).to include("<_id>#{person.id}</_id>")
|
843
|
-
end
|
844
|
-
end
|
845
|
-
|
846
|
-
context "when an Array field is defined" do
|
847
|
-
|
848
|
-
let(:person) do
|
849
|
-
Person.new(
|
850
|
-
aliases: [ "Kelly", "Machine Gun" ]
|
851
|
-
)
|
852
|
-
end
|
853
|
-
|
854
|
-
it "properly types the array" do
|
855
|
-
expect(person.to_xml).to include("<aliases type=\"array\">")
|
856
|
-
end
|
857
|
-
|
858
|
-
it "serializes the array" do
|
859
|
-
expect(person.to_xml).to include("<alias>Kelly</alias>")
|
860
|
-
expect(person.to_xml).to include("<alias>Machine Gun</alias>")
|
861
|
-
end
|
862
|
-
end
|
863
|
-
|
864
|
-
context "when a Hash field is defined" do
|
865
|
-
|
866
|
-
let(:person) do
|
867
|
-
Person.new(
|
868
|
-
map: { lat: 24.5, long: 22.1 }
|
869
|
-
)
|
870
|
-
end
|
871
|
-
|
872
|
-
it "properly types the hash" do
|
873
|
-
expect(person.to_xml).to include("<map>")
|
874
|
-
end
|
875
|
-
|
876
|
-
it "serializes the hash" do
|
877
|
-
expect(person.to_xml).to include("<lat type=\"float\">24.5</lat>")
|
878
|
-
expect(person.to_xml).to include("<long type=\"float\">22.1</long>")
|
879
|
-
end
|
880
|
-
end
|
881
|
-
end
|
882
832
|
end
|
@@ -233,4 +233,72 @@ describe Mongoid::Threaded do
|
|
233
233
|
end
|
234
234
|
end
|
235
235
|
end
|
236
|
+
|
237
|
+
describe "#begin_without_default_scope" do
|
238
|
+
|
239
|
+
let(:klass) do
|
240
|
+
Appointment
|
241
|
+
end
|
242
|
+
|
243
|
+
after do
|
244
|
+
described_class.exit_without_default_scope(klass)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "adds the given class to the without_default_scope stack" do
|
248
|
+
described_class.begin_without_default_scope(klass)
|
249
|
+
|
250
|
+
expect(described_class.stack(:without_default_scope)).to include(klass)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "#exit_without_default_scope" do
|
255
|
+
|
256
|
+
let(:klass) do
|
257
|
+
Appointment
|
258
|
+
end
|
259
|
+
|
260
|
+
before do
|
261
|
+
described_class.begin_without_default_scope(klass)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "removes the given class from the without_default_scope stack" do
|
265
|
+
described_class.exit_without_default_scope(klass)
|
266
|
+
|
267
|
+
expect(described_class.stack(:without_default_scope)).not_to include(klass)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe "#without_default_scope?" do
|
272
|
+
|
273
|
+
let(:klass) do
|
274
|
+
Appointment
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when klass has begun without_default_scope" do
|
278
|
+
|
279
|
+
before do
|
280
|
+
described_class.begin_without_default_scope(klass)
|
281
|
+
end
|
282
|
+
|
283
|
+
after do
|
284
|
+
described_class.exit_without_default_scope(klass)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "returns true" do
|
288
|
+
expect(described_class.without_default_scope?(klass)).to be(true)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context "when klass has exited without_default_scope" do
|
293
|
+
|
294
|
+
before do
|
295
|
+
described_class.begin_without_default_scope(klass)
|
296
|
+
described_class.exit_without_default_scope(klass)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "returns false" do
|
300
|
+
expect(described_class.without_default_scope?(klass)).to be(false)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
236
304
|
end
|