mongoid 8.0.8 → 8.1.0
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/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 +7 -16
- 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/associated.rb +18 -96
- data/lib/mongoid/validatable/macros.rb +5 -5
- data/lib/mongoid/validatable.rb +4 -9
- 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/associations/has_and_belongs_to_many_spec.rb +0 -40
- 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/associated_spec.rb +30 -13
- 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/name.rb +0 -10
- data/spec/support/models/person.rb +0 -1
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +698 -664
- 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
@@ -578,6 +578,26 @@ describe Mongoid::Interceptable do
|
|
578
578
|
band.notes.push(note)
|
579
579
|
record.notes.push(note)
|
580
580
|
end
|
581
|
+
|
582
|
+
context "when saving the root" do
|
583
|
+
context 'with prevent_multiple_calls_of_embedded_callbacks enabled' do
|
584
|
+
config_override :prevent_multiple_calls_of_embedded_callbacks, true
|
585
|
+
|
586
|
+
it "executes the callbacks only once for each document" do
|
587
|
+
expect(note).to receive(:update_saved).once
|
588
|
+
band.save!
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
context 'with prevent_multiple_calls_of_embedded_callbacks disabled' do
|
593
|
+
config_override :prevent_multiple_calls_of_embedded_callbacks, false
|
594
|
+
|
595
|
+
it "executes the callbacks once for each ember" do
|
596
|
+
expect(note).to receive(:update_saved).twice
|
597
|
+
band.save!
|
598
|
+
end
|
599
|
+
end
|
600
|
+
end
|
581
601
|
end
|
582
602
|
end
|
583
603
|
|
@@ -1763,80 +1783,40 @@ describe Mongoid::Interceptable do
|
|
1763
1783
|
end
|
1764
1784
|
end
|
1765
1785
|
|
1766
|
-
|
1767
|
-
|
1786
|
+
let(:expected) do
|
1787
|
+
[
|
1788
|
+
[InterceptableSpec::CbCascadedChild, :before_validation],
|
1789
|
+
[InterceptableSpec::CbCascadedChild, :after_validation],
|
1790
|
+
[InterceptableSpec::CbParent, :before_validation],
|
1791
|
+
[InterceptableSpec::CbCascadedChild, :before_validation],
|
1792
|
+
[InterceptableSpec::CbCascadedChild, :after_validation],
|
1768
1793
|
|
1769
|
-
|
1770
|
-
[
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
[InterceptableSpec::CbCascadedChild, :before_validation],
|
1775
|
-
[InterceptableSpec::CbCascadedChild, :after_validation],
|
1776
|
-
|
1777
|
-
[InterceptableSpec::CbParent, :after_validation],
|
1778
|
-
[InterceptableSpec::CbParent, :before_save],
|
1779
|
-
[InterceptableSpec::CbParent, :around_save_open],
|
1780
|
-
[InterceptableSpec::CbParent, :before_create],
|
1781
|
-
[InterceptableSpec::CbParent, :around_create_open],
|
1782
|
-
|
1783
|
-
[InterceptableSpec::CbCascadedChild, :before_save],
|
1784
|
-
[InterceptableSpec::CbCascadedChild, :around_save_open],
|
1785
|
-
[InterceptableSpec::CbCascadedChild, :before_create],
|
1786
|
-
[InterceptableSpec::CbCascadedChild, :around_create_open],
|
1787
|
-
|
1788
|
-
[InterceptableSpec::CbCascadedChild, :around_create_close],
|
1789
|
-
[InterceptableSpec::CbCascadedChild, :after_create],
|
1790
|
-
[InterceptableSpec::CbCascadedChild, :around_save_close],
|
1791
|
-
[InterceptableSpec::CbCascadedChild, :after_save],
|
1792
|
-
|
1793
|
-
[InterceptableSpec::CbParent, :around_create_close],
|
1794
|
-
[InterceptableSpec::CbParent, :after_create],
|
1795
|
-
[InterceptableSpec::CbParent, :around_save_close],
|
1796
|
-
[InterceptableSpec::CbParent, :after_save]
|
1797
|
-
]
|
1798
|
-
end
|
1794
|
+
[InterceptableSpec::CbParent, :after_validation],
|
1795
|
+
[InterceptableSpec::CbParent, :before_save],
|
1796
|
+
[InterceptableSpec::CbParent, :around_save_open],
|
1797
|
+
[InterceptableSpec::CbParent, :before_create],
|
1798
|
+
[InterceptableSpec::CbParent, :around_create_open],
|
1799
1799
|
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
end
|
1800
|
+
[InterceptableSpec::CbCascadedChild, :before_save],
|
1801
|
+
[InterceptableSpec::CbCascadedChild, :around_save_open],
|
1802
|
+
[InterceptableSpec::CbCascadedChild, :before_create],
|
1803
|
+
[InterceptableSpec::CbCascadedChild, :around_create_open],
|
1805
1804
|
|
1806
|
-
|
1807
|
-
|
1805
|
+
[InterceptableSpec::CbCascadedChild, :around_create_close],
|
1806
|
+
[InterceptableSpec::CbCascadedChild, :after_create],
|
1807
|
+
[InterceptableSpec::CbCascadedChild, :around_save_close],
|
1808
|
+
[InterceptableSpec::CbCascadedChild, :after_save],
|
1808
1809
|
|
1809
|
-
|
1810
|
-
[
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
[InterceptableSpec::CbCascadedChild, :after_validation],
|
1816
|
-
|
1817
|
-
[InterceptableSpec::CbParent, :after_validation],
|
1818
|
-
[InterceptableSpec::CbParent, :before_save],
|
1819
|
-
[InterceptableSpec::CbParent, :around_save_open],
|
1820
|
-
[InterceptableSpec::CbParent, :before_create],
|
1821
|
-
[InterceptableSpec::CbParent, :around_create_open],
|
1822
|
-
|
1823
|
-
[InterceptableSpec::CbCascadedChild, :before_save],
|
1824
|
-
[InterceptableSpec::CbCascadedChild, :before_create],
|
1825
|
-
|
1826
|
-
[InterceptableSpec::CbCascadedChild, :after_create],
|
1827
|
-
[InterceptableSpec::CbCascadedChild, :after_save],
|
1828
|
-
|
1829
|
-
[InterceptableSpec::CbParent, :around_create_close],
|
1830
|
-
[InterceptableSpec::CbParent, :after_create],
|
1831
|
-
[InterceptableSpec::CbParent, :around_save_close],
|
1832
|
-
[InterceptableSpec::CbParent, :after_save]
|
1833
|
-
]
|
1834
|
-
end
|
1810
|
+
[InterceptableSpec::CbParent, :around_create_close],
|
1811
|
+
[InterceptableSpec::CbParent, :after_create],
|
1812
|
+
[InterceptableSpec::CbParent, :around_save_close],
|
1813
|
+
[InterceptableSpec::CbParent, :after_save]
|
1814
|
+
]
|
1815
|
+
end
|
1835
1816
|
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
end
|
1817
|
+
it 'calls callbacks in the right order' do
|
1818
|
+
parent.save!
|
1819
|
+
expect(registry.calls).to eq expected
|
1840
1820
|
end
|
1841
1821
|
end
|
1842
1822
|
|
@@ -1899,180 +1879,89 @@ describe Mongoid::Interceptable do
|
|
1899
1879
|
end
|
1900
1880
|
|
1901
1881
|
context "create" do
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
[
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
1934
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
1935
|
-
]
|
1936
|
-
end
|
1937
|
-
|
1938
|
-
it 'calls callbacks in the right order' do
|
1939
|
-
parent.save!
|
1940
|
-
expect(registry.calls).to eq expected
|
1941
|
-
end
|
1882
|
+
let(:expected) do
|
1883
|
+
[
|
1884
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
1885
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
1886
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
1887
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
1888
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
1889
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
1890
|
+
|
1891
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
1892
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
1893
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_create],
|
1894
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_create_open],
|
1895
|
+
|
1896
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
1897
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_open],
|
1898
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_create],
|
1899
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_create_open],
|
1900
|
+
|
1901
|
+
[InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
|
1902
|
+
|
1903
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_create_close],
|
1904
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_create],
|
1905
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_close],
|
1906
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
1907
|
+
|
1908
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_create_close],
|
1909
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_create],
|
1910
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
1911
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
1912
|
+
]
|
1942
1913
|
end
|
1943
1914
|
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
let(:expected) do
|
1948
|
-
[
|
1949
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
1950
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
1951
|
-
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
1952
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
1953
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
1954
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
1955
|
-
|
1956
|
-
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
1957
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
1958
|
-
[InterceptableSpec::CbEmbedsOneParent, :before_create],
|
1959
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_create_open],
|
1960
|
-
|
1961
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
1962
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_create],
|
1963
|
-
|
1964
|
-
[InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
|
1965
|
-
|
1966
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_create],
|
1967
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
1968
|
-
|
1969
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_create_close],
|
1970
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_create],
|
1971
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
1972
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
1973
|
-
]
|
1974
|
-
end
|
1975
|
-
|
1976
|
-
it 'calls callbacks in the right order' do
|
1977
|
-
parent.save!
|
1978
|
-
expect(registry.calls).to eq expected
|
1979
|
-
end
|
1915
|
+
it 'calls callbacks in the right order' do
|
1916
|
+
parent.save!
|
1917
|
+
expect(registry.calls).to eq expected
|
1980
1918
|
end
|
1981
1919
|
end
|
1982
1920
|
|
1983
1921
|
context "update" do
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
[
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
2014
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
2015
|
-
]
|
2016
|
-
end
|
2017
|
-
|
2018
|
-
it 'calls callbacks in the right order' do
|
2019
|
-
parent.callback_registry = nil
|
2020
|
-
parent.child.callback_registry = nil
|
2021
|
-
parent.save!
|
2022
|
-
|
2023
|
-
parent.callback_registry = registry
|
2024
|
-
parent.child.callback_registry = registry
|
2025
|
-
parent.name = "name"
|
2026
|
-
parent.child.age = 10
|
2027
|
-
|
2028
|
-
parent.save!
|
2029
|
-
expect(registry.calls).to eq expected
|
2030
|
-
end
|
1922
|
+
let(:expected) do
|
1923
|
+
[
|
1924
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
1925
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
1926
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
1927
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
1928
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
1929
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
1930
|
+
|
1931
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
1932
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
1933
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_update],
|
1934
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_update_open],
|
1935
|
+
|
1936
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
1937
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_open],
|
1938
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_update],
|
1939
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_update_open],
|
1940
|
+
|
1941
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_update_close],
|
1942
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_update],
|
1943
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_close],
|
1944
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
1945
|
+
|
1946
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_update_close],
|
1947
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_update],
|
1948
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
1949
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
1950
|
+
]
|
2031
1951
|
end
|
2032
1952
|
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
[
|
2038
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
2039
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
2040
|
-
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
2041
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
2042
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
2043
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
2044
|
-
|
2045
|
-
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
2046
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
2047
|
-
[InterceptableSpec::CbEmbedsOneParent, :before_update],
|
2048
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_update_open],
|
2049
|
-
|
2050
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
2051
|
-
[InterceptableSpec::CbEmbedsOneChild, :before_update],
|
2052
|
-
|
2053
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_update],
|
2054
|
-
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
2055
|
-
|
2056
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_update_close],
|
2057
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_update],
|
2058
|
-
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
2059
|
-
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
2060
|
-
]
|
2061
|
-
end
|
2062
|
-
|
2063
|
-
it 'calls callbacks in the right order' do
|
2064
|
-
parent.callback_registry = nil
|
2065
|
-
parent.child.callback_registry = nil
|
2066
|
-
parent.save!
|
1953
|
+
it 'calls callbacks in the right order' do
|
1954
|
+
parent.callback_registry = nil
|
1955
|
+
parent.child.callback_registry = nil
|
1956
|
+
parent.save!
|
2067
1957
|
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
1958
|
+
parent.callback_registry = registry
|
1959
|
+
parent.child.callback_registry = registry
|
1960
|
+
parent.name = "name"
|
1961
|
+
parent.child.age = 10
|
2072
1962
|
|
2073
|
-
|
2074
|
-
|
2075
|
-
end
|
1963
|
+
parent.save!
|
1964
|
+
expect(registry.calls).to eq expected
|
2076
1965
|
end
|
2077
1966
|
end
|
2078
1967
|
end
|
@@ -2152,114 +2041,59 @@ describe Mongoid::Interceptable do
|
|
2152
2041
|
end
|
2153
2042
|
end
|
2154
2043
|
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
[
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
[InterceptableSpec::CbEmbedsManyParent, :around_save_close],
|
2204
|
-
[InterceptableSpec::CbEmbedsManyParent, :after_save]
|
2205
|
-
]
|
2206
|
-
end
|
2207
|
-
|
2208
|
-
it 'calls callbacks in the right order' do
|
2209
|
-
parent.save!
|
2210
|
-
expect(registry.calls).to eq expected
|
2211
|
-
end
|
2044
|
+
let(:expected) do
|
2045
|
+
[
|
2046
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2047
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2048
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2049
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2050
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_validation],
|
2051
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2052
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2053
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2054
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2055
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_validation],
|
2056
|
+
|
2057
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_save],
|
2058
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_save_open],
|
2059
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_create],
|
2060
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_create_open],
|
2061
|
+
|
2062
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
2063
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_open],
|
2064
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
2065
|
+
|
2066
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_open],
|
2067
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
2068
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_open],
|
2069
|
+
|
2070
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
2071
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_open],
|
2072
|
+
|
2073
|
+
[InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
|
2074
|
+
|
2075
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_close],
|
2076
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
2077
|
+
|
2078
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_close],
|
2079
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
2080
|
+
|
2081
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_close],
|
2082
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
2083
|
+
|
2084
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_close],
|
2085
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
2086
|
+
|
2087
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_create_close],
|
2088
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_create],
|
2089
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_save_close],
|
2090
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_save]
|
2091
|
+
]
|
2212
2092
|
end
|
2213
2093
|
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
let(:expected) do
|
2218
|
-
[
|
2219
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2220
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2221
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2222
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2223
|
-
[InterceptableSpec::CbEmbedsManyParent, :before_validation],
|
2224
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2225
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2226
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
2227
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
2228
|
-
[InterceptableSpec::CbEmbedsManyParent, :after_validation],
|
2229
|
-
|
2230
|
-
[InterceptableSpec::CbEmbedsManyParent, :before_save],
|
2231
|
-
[InterceptableSpec::CbEmbedsManyParent, :around_save_open],
|
2232
|
-
[InterceptableSpec::CbEmbedsManyParent, :before_create],
|
2233
|
-
[InterceptableSpec::CbEmbedsManyParent, :around_create_open],
|
2234
|
-
|
2235
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
2236
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
2237
|
-
|
2238
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
2239
|
-
|
2240
|
-
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
2241
|
-
|
2242
|
-
[InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
|
2243
|
-
|
2244
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
2245
|
-
|
2246
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
2247
|
-
|
2248
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
2249
|
-
|
2250
|
-
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
2251
|
-
|
2252
|
-
[InterceptableSpec::CbEmbedsManyParent, :around_create_close],
|
2253
|
-
[InterceptableSpec::CbEmbedsManyParent, :after_create],
|
2254
|
-
[InterceptableSpec::CbEmbedsManyParent, :around_save_close],
|
2255
|
-
[InterceptableSpec::CbEmbedsManyParent, :after_save]
|
2256
|
-
]
|
2257
|
-
end
|
2258
|
-
|
2259
|
-
it 'calls callbacks in the right order' do
|
2260
|
-
parent.save!
|
2261
|
-
expect(registry.calls).to eq expected
|
2262
|
-
end
|
2094
|
+
it 'calls callbacks in the right order' do
|
2095
|
+
parent.save!
|
2096
|
+
expect(registry.calls).to eq expected
|
2263
2097
|
end
|
2264
2098
|
end
|
2265
2099
|
end
|
@@ -2548,27 +2382,4 @@ describe Mongoid::Interceptable do
|
|
2548
2382
|
end.to_not raise_error(ActiveModel::MissingAttributeError)
|
2549
2383
|
end
|
2550
2384
|
end
|
2551
|
-
|
2552
|
-
context "when around callbacks for embedded are disabled" do
|
2553
|
-
config_override :around_callbacks_for_embeds, false
|
2554
|
-
|
2555
|
-
context "when around callback is defined" do
|
2556
|
-
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
2557
|
-
|
2558
|
-
let(:parent) do
|
2559
|
-
InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
|
2560
|
-
parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
|
2561
|
-
end
|
2562
|
-
end
|
2563
|
-
|
2564
|
-
before do
|
2565
|
-
expect(Mongoid.logger).to receive(:warn).with(/Around callbacks are disabled for embedded documents/).twice.and_call_original
|
2566
|
-
expect(Mongoid.logger).to receive(:warn).with(/To enable around callbacks for embedded documents/).twice.and_call_original
|
2567
|
-
end
|
2568
|
-
|
2569
|
-
it "logs a warning" do
|
2570
|
-
parent.save!
|
2571
|
-
end
|
2572
|
-
end
|
2573
|
-
end
|
2574
2385
|
end
|
@@ -12,14 +12,34 @@ describe Mongoid::Persistable::Deletable do
|
|
12
12
|
|
13
13
|
context "when deleting a readonly document" do
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
context "when legacy_attributes is true" do
|
16
|
+
config_override :legacy_readonly, true
|
17
|
+
|
18
|
+
let(:from_db) do
|
19
|
+
Person.only(:_id).first
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an error" do
|
23
|
+
expect(from_db.readonly?).to be true
|
24
|
+
expect {
|
25
|
+
from_db.delete
|
26
|
+
}.to raise_error(Mongoid::Errors::ReadonlyDocument)
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
30
|
+
context "when legacy_attributes is false" do
|
31
|
+
config_override :legacy_readonly, false
|
32
|
+
|
33
|
+
let(:from_db) do
|
34
|
+
Person.first.tap(&:readonly!)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises an error" do
|
38
|
+
expect(from_db.readonly?).to be true
|
39
|
+
expect {
|
40
|
+
from_db.delete
|
41
|
+
}.to raise_error(Mongoid::Errors::ReadonlyDocument)
|
42
|
+
end
|
23
43
|
end
|
24
44
|
end
|
25
45
|
|