mongoid 8.0.7 → 8.1.0
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/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/Rakefile +0 -25
- data/lib/config/locales/en.yml +46 -14
- data/lib/mongoid/association/accessors.rb +2 -2
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/embedded/batchable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
- data/lib/mongoid/association/macros.rb +0 -6
- data/lib/mongoid/association/nested/one.rb +40 -2
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/atomic.rb +0 -7
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/processing.rb +5 -29
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +1 -1
- data/lib/mongoid/attributes.rb +8 -2
- data/lib/mongoid/changeable.rb +107 -5
- data/lib/mongoid/clients/storage_options.rb +2 -5
- data/lib/mongoid/clients/validators/storage.rb +1 -13
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +2 -0
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/options.rb +0 -3
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +99 -28
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +233 -33
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +370 -133
- data/lib/mongoid/contextual/none.rb +162 -7
- data/lib/mongoid/contextual.rb +12 -0
- data/lib/mongoid/criteria/findable.rb +2 -2
- data/lib/mongoid/criteria/includable.rb +4 -3
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria.rb +6 -5
- data/lib/mongoid/deprecable.rb +1 -2
- data/lib/mongoid/deprecation.rb +3 -3
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -24
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +53 -24
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +10 -118
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/persistable/creatable.rb +1 -0
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +13 -1
- data/lib/mongoid/persistable/unsettable.rb +2 -2
- data/lib/mongoid/persistable/updatable.rb +51 -1
- data/lib/mongoid/persistable/upsertable.rb +20 -1
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/query_cache.rb +5 -1
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/reloadable.rb +5 -3
- data/lib/mongoid/stateful.rb +22 -1
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +20 -0
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/macros.rb +5 -5
- data/lib/mongoid/validatable.rb +4 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +17 -1
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -2
- data/spec/integration/callbacks_models.rb +37 -0
- data/spec/integration/callbacks_spec.rb +126 -12
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +5 -27
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +3 -33
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients_spec.rb +122 -13
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config_spec.rb +154 -27
- data/spec/mongoid/contextual/memory_spec.rb +332 -76
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +2 -10
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
- data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -9
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/hash_spec.rb +3 -3
- data/spec/mongoid/extensions/time_spec.rb +8 -43
- data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
- data/spec/mongoid/fields/localized_spec.rb +46 -28
- data/spec/mongoid/fields_spec.rb +136 -77
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +173 -362
- data/spec/mongoid/persistable/deletable_spec.rb +26 -6
- data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
- data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
- data/spec/mongoid/persistable/logical_spec.rb +37 -0
- data/spec/mongoid/persistable/poppable_spec.rb +36 -0
- data/spec/mongoid/persistable/pullable_spec.rb +72 -0
- data/spec/mongoid/persistable/pushable_spec.rb +72 -0
- data/spec/mongoid/persistable/renamable_spec.rb +36 -0
- data/spec/mongoid/persistable/savable_spec.rb +96 -0
- data/spec/mongoid/persistable/settable_spec.rb +37 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
- data/spec/mongoid/persistable/updatable_spec.rb +20 -28
- data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
- data/spec/mongoid/persistence_context_spec.rb +7 -57
- data/spec/mongoid/query_cache_spec.rb +56 -61
- data/spec/mongoid/reloadable_spec.rb +24 -28
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +9 -30
- data/spec/mongoid/stateful_spec.rb +122 -8
- data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
- data/spec/mongoid/tasks/database_spec.rb +127 -0
- data/spec/mongoid/timestamps_spec.rb +9 -11
- data/spec/mongoid/touchable_spec.rb +277 -5
- data/spec/mongoid/touchable_spec_models.rb +3 -1
- data/spec/mongoid/traversable_spec.rb +9 -24
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +36 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +47 -15
- data/spec/support/models/artist.rb +0 -1
- data/spec/support/models/band.rb +1 -0
- data/spec/support/models/book.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/person.rb +0 -1
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +685 -651
- metadata.gz.sig +0 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
- data/spec/support/models/purse.rb +0 -9
data/spec/mongoid/fields_spec.rb
CHANGED
|
@@ -14,18 +14,15 @@ describe Mongoid::Fields do
|
|
|
14
14
|
context "when the field is localized" do
|
|
15
15
|
|
|
16
16
|
context "when translations exist" do
|
|
17
|
+
with_default_i18n_configs
|
|
17
18
|
|
|
18
19
|
before do
|
|
20
|
+
I18n.locale = :en
|
|
19
21
|
product.description = "test"
|
|
20
|
-
I18n.
|
|
21
|
-
::I18n.locale = :de
|
|
22
|
+
I18n.locale = :de
|
|
22
23
|
product.description = "The best"
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
after do
|
|
26
|
-
::I18n.locale = :en
|
|
27
|
-
end
|
|
28
|
-
|
|
29
26
|
let(:translations) do
|
|
30
27
|
product.description_translations
|
|
31
28
|
end
|
|
@@ -527,16 +524,13 @@ describe Mongoid::Fields do
|
|
|
527
524
|
end
|
|
528
525
|
|
|
529
526
|
context "when a single locale is set" do
|
|
527
|
+
with_default_i18n_configs
|
|
530
528
|
|
|
531
529
|
before do
|
|
532
|
-
|
|
530
|
+
I18n.locale = :de
|
|
533
531
|
product.description = "The best"
|
|
534
532
|
end
|
|
535
533
|
|
|
536
|
-
after do
|
|
537
|
-
::I18n.locale = :en
|
|
538
|
-
end
|
|
539
|
-
|
|
540
534
|
let(:description) do
|
|
541
535
|
product.description
|
|
542
536
|
end
|
|
@@ -547,17 +541,15 @@ describe Mongoid::Fields do
|
|
|
547
541
|
end
|
|
548
542
|
|
|
549
543
|
context "when multiple locales are set" do
|
|
544
|
+
with_default_i18n_configs
|
|
550
545
|
|
|
551
546
|
before do
|
|
547
|
+
I18n.locale = :end
|
|
552
548
|
product.description = "Cheap drinks"
|
|
553
|
-
|
|
549
|
+
I18n.locale = :de
|
|
554
550
|
product.description = "Cheaper drinks"
|
|
555
551
|
end
|
|
556
552
|
|
|
557
|
-
after do
|
|
558
|
-
::I18n.locale = :en
|
|
559
|
-
end
|
|
560
|
-
|
|
561
553
|
let(:description) do
|
|
562
554
|
product.description
|
|
563
555
|
end
|
|
@@ -567,49 +559,6 @@ describe Mongoid::Fields do
|
|
|
567
559
|
end
|
|
568
560
|
end
|
|
569
561
|
end
|
|
570
|
-
|
|
571
|
-
context 'when the field is declared as BSON::Decimal128' do
|
|
572
|
-
let(:document) { Mop.create!(decimal128_field: BSON::Decimal128.new(Math::PI.to_s)).reload }
|
|
573
|
-
|
|
574
|
-
shared_context 'BSON::Decimal128 is BigDecimal' do
|
|
575
|
-
it 'should return a BigDecimal' do
|
|
576
|
-
expect(document.decimal128_field).to be_a BigDecimal
|
|
577
|
-
end
|
|
578
|
-
end
|
|
579
|
-
|
|
580
|
-
shared_context 'BSON::Decimal128 is BSON::Decimal128' do
|
|
581
|
-
it 'should return a BSON::Decimal128' do
|
|
582
|
-
expect(document.decimal128_field).to be_a BSON::Decimal128
|
|
583
|
-
end
|
|
584
|
-
end
|
|
585
|
-
|
|
586
|
-
it 'is declared as BSON::Decimal128' do
|
|
587
|
-
expect(Mop.fields['decimal128_field'].type).to be == BSON::Decimal128
|
|
588
|
-
end
|
|
589
|
-
|
|
590
|
-
context 'when BSON version <= 4' do
|
|
591
|
-
max_bson_version '4.99.99'
|
|
592
|
-
it_behaves_like 'BSON::Decimal128 is BSON::Decimal128'
|
|
593
|
-
end
|
|
594
|
-
|
|
595
|
-
context 'when BSON version >= 5' do
|
|
596
|
-
min_bson_version '5.0.0'
|
|
597
|
-
|
|
598
|
-
context 'when allow_bson5_decimal128 is false' do
|
|
599
|
-
config_override :allow_bson5_decimal128, false
|
|
600
|
-
it_behaves_like 'BSON::Decimal128 is BigDecimal'
|
|
601
|
-
end
|
|
602
|
-
|
|
603
|
-
context 'when allow_bson5_decimal128 is true' do
|
|
604
|
-
config_override :allow_bson5_decimal128, true
|
|
605
|
-
it_behaves_like 'BSON::Decimal128 is BSON::Decimal128'
|
|
606
|
-
end
|
|
607
|
-
|
|
608
|
-
context 'when allow_bson5_decimal128 is default' do
|
|
609
|
-
it_behaves_like 'BSON::Decimal128 is BigDecimal'
|
|
610
|
-
end
|
|
611
|
-
end
|
|
612
|
-
end
|
|
613
562
|
end
|
|
614
563
|
|
|
615
564
|
describe "#getter_before_type_cast" do
|
|
@@ -878,16 +827,13 @@ describe Mongoid::Fields do
|
|
|
878
827
|
end
|
|
879
828
|
|
|
880
829
|
context "when a locale is set" do
|
|
830
|
+
with_default_i18n_configs
|
|
881
831
|
|
|
882
832
|
before do
|
|
883
|
-
|
|
833
|
+
I18n.locale = :de
|
|
884
834
|
product.description = "Cheaper drinks"
|
|
885
835
|
end
|
|
886
836
|
|
|
887
|
-
after do
|
|
888
|
-
::I18n.locale = :en
|
|
889
|
-
end
|
|
890
|
-
|
|
891
837
|
let(:description) do
|
|
892
838
|
product.attributes["description"]
|
|
893
839
|
end
|
|
@@ -898,17 +844,15 @@ describe Mongoid::Fields do
|
|
|
898
844
|
end
|
|
899
845
|
|
|
900
846
|
context "when having multiple locales" do
|
|
847
|
+
with_default_i18n_configs
|
|
901
848
|
|
|
902
849
|
before do
|
|
850
|
+
I18n.locale = :en
|
|
903
851
|
product.description = "Cheap drinks"
|
|
904
|
-
|
|
852
|
+
I18n.locale = :de
|
|
905
853
|
product.description = "Cheaper drinks"
|
|
906
854
|
end
|
|
907
855
|
|
|
908
|
-
after do
|
|
909
|
-
::I18n.locale = :en
|
|
910
|
-
end
|
|
911
|
-
|
|
912
856
|
let(:description) do
|
|
913
857
|
product.attributes["description"]
|
|
914
858
|
end
|
|
@@ -1110,14 +1054,7 @@ describe Mongoid::Fields do
|
|
|
1110
1054
|
end
|
|
1111
1055
|
|
|
1112
1056
|
context "when reading the field" do
|
|
1113
|
-
|
|
1114
|
-
before do
|
|
1115
|
-
Time.zone = "Berlin"
|
|
1116
|
-
end
|
|
1117
|
-
|
|
1118
|
-
after do
|
|
1119
|
-
Time.zone = nil
|
|
1120
|
-
end
|
|
1057
|
+
time_zone_override "Berlin"
|
|
1121
1058
|
|
|
1122
1059
|
it "performs the necessary time conversions" do
|
|
1123
1060
|
expect(person.lunch_time.to_s).to eq(time.getlocal.to_s)
|
|
@@ -2007,4 +1944,126 @@ describe Mongoid::Fields do
|
|
|
2007
1944
|
end
|
|
2008
1945
|
end
|
|
2009
1946
|
end
|
|
1947
|
+
|
|
1948
|
+
describe "localize: :present" do
|
|
1949
|
+
|
|
1950
|
+
let(:product) do
|
|
1951
|
+
Product.new
|
|
1952
|
+
end
|
|
1953
|
+
|
|
1954
|
+
context "when assigning a non blank value" do
|
|
1955
|
+
|
|
1956
|
+
before do
|
|
1957
|
+
product.title = "hello"
|
|
1958
|
+
end
|
|
1959
|
+
|
|
1960
|
+
it "assigns the value" do
|
|
1961
|
+
expect(product.title).to eq("hello")
|
|
1962
|
+
end
|
|
1963
|
+
|
|
1964
|
+
it "populates the translations hash" do
|
|
1965
|
+
expect(product.title_translations).to eq({ "en" => "hello" })
|
|
1966
|
+
end
|
|
1967
|
+
end
|
|
1968
|
+
|
|
1969
|
+
context "when assigning an empty string" do
|
|
1970
|
+
with_default_i18n_configs
|
|
1971
|
+
|
|
1972
|
+
before do
|
|
1973
|
+
I18n.locale = :en
|
|
1974
|
+
product.title = "hello"
|
|
1975
|
+
I18n.locale = :de
|
|
1976
|
+
product.title = "hello there!"
|
|
1977
|
+
product.title = ""
|
|
1978
|
+
end
|
|
1979
|
+
|
|
1980
|
+
it "assigns the value" do
|
|
1981
|
+
expect(product.title).to eq(nil)
|
|
1982
|
+
end
|
|
1983
|
+
|
|
1984
|
+
it "populates the translations hash" do
|
|
1985
|
+
expect(product.title_translations).to eq({ "en" => "hello" })
|
|
1986
|
+
end
|
|
1987
|
+
end
|
|
1988
|
+
|
|
1989
|
+
context "when assigning nil" do
|
|
1990
|
+
with_default_i18n_configs
|
|
1991
|
+
|
|
1992
|
+
before do
|
|
1993
|
+
I18n.locale = :en
|
|
1994
|
+
product.title = "hello"
|
|
1995
|
+
I18n.locale = :de
|
|
1996
|
+
product.title = "hello there!"
|
|
1997
|
+
product.title = nil
|
|
1998
|
+
end
|
|
1999
|
+
|
|
2000
|
+
it "assigns the value" do
|
|
2001
|
+
expect(product.title).to eq(nil)
|
|
2002
|
+
end
|
|
2003
|
+
|
|
2004
|
+
it "populates the translations hash" do
|
|
2005
|
+
expect(product.title_translations).to eq({ "en" => "hello" })
|
|
2006
|
+
end
|
|
2007
|
+
end
|
|
2008
|
+
|
|
2009
|
+
context "when assigning an empty array" do
|
|
2010
|
+
with_default_i18n_configs
|
|
2011
|
+
|
|
2012
|
+
before do
|
|
2013
|
+
I18n.locale = :en
|
|
2014
|
+
product.title = "hello"
|
|
2015
|
+
I18n.locale = :de
|
|
2016
|
+
product.title = "hello there!"
|
|
2017
|
+
product.title = []
|
|
2018
|
+
end
|
|
2019
|
+
|
|
2020
|
+
it "assigns the value" do
|
|
2021
|
+
expect(product.title).to eq(nil)
|
|
2022
|
+
end
|
|
2023
|
+
|
|
2024
|
+
it "populates the translations hash" do
|
|
2025
|
+
expect(product.title_translations).to eq({ "en" => "hello" })
|
|
2026
|
+
end
|
|
2027
|
+
end
|
|
2028
|
+
|
|
2029
|
+
context "when assigning an empty string first" do
|
|
2030
|
+
with_default_i18n_configs
|
|
2031
|
+
|
|
2032
|
+
before do
|
|
2033
|
+
product.title = ""
|
|
2034
|
+
end
|
|
2035
|
+
|
|
2036
|
+
it "assigns the value" do
|
|
2037
|
+
expect(product.title).to eq(nil)
|
|
2038
|
+
end
|
|
2039
|
+
|
|
2040
|
+
it "populates the translations hash" do
|
|
2041
|
+
expect(product.title_translations).to eq({})
|
|
2042
|
+
end
|
|
2043
|
+
end
|
|
2044
|
+
|
|
2045
|
+
context "when assigning an empty string with only one translation" do
|
|
2046
|
+
with_default_i18n_configs
|
|
2047
|
+
|
|
2048
|
+
before do
|
|
2049
|
+
product.title = "Hello"
|
|
2050
|
+
product.title = ""
|
|
2051
|
+
product.save!
|
|
2052
|
+
end
|
|
2053
|
+
|
|
2054
|
+
let(:from_db) { Product.first }
|
|
2055
|
+
|
|
2056
|
+
it "assigns the value" do
|
|
2057
|
+
expect(product.title).to eq(nil)
|
|
2058
|
+
end
|
|
2059
|
+
|
|
2060
|
+
it "populates the translations hash" do
|
|
2061
|
+
expect(product.title_translations).to eq({})
|
|
2062
|
+
end
|
|
2063
|
+
|
|
2064
|
+
it "round trips an empty hash" do
|
|
2065
|
+
expect(from_db.title_translations).to eq({})
|
|
2066
|
+
end
|
|
2067
|
+
end
|
|
2068
|
+
end
|
|
2010
2069
|
end
|