mongoid 8.0.8 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +3 -3
  4. data/README.md +3 -3
  5. data/Rakefile +0 -25
  6. data/lib/config/locales/en.yml +46 -14
  7. data/lib/mongoid/association/accessors.rb +2 -2
  8. data/lib/mongoid/association/builders.rb +1 -1
  9. data/lib/mongoid/association/embedded/batchable.rb +2 -2
  10. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
  11. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
  12. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
  13. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
  14. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
  15. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
  16. data/lib/mongoid/association/macros.rb +0 -6
  17. data/lib/mongoid/association/nested/one.rb +40 -2
  18. data/lib/mongoid/association/proxy.rb +1 -1
  19. data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
  20. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
  21. data/lib/mongoid/association/referenced/has_many/enumerable.rb +2 -2
  22. data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
  23. data/lib/mongoid/association/reflections.rb +2 -2
  24. data/lib/mongoid/atomic.rb +7 -16
  25. data/lib/mongoid/attributes/dynamic.rb +1 -1
  26. data/lib/mongoid/attributes/nested.rb +2 -2
  27. data/lib/mongoid/attributes/processing.rb +5 -29
  28. data/lib/mongoid/attributes/projector.rb +1 -1
  29. data/lib/mongoid/attributes/readonly.rb +1 -1
  30. data/lib/mongoid/attributes.rb +8 -2
  31. data/lib/mongoid/changeable.rb +107 -5
  32. data/lib/mongoid/clients/storage_options.rb +2 -5
  33. data/lib/mongoid/clients/validators/storage.rb +1 -13
  34. data/lib/mongoid/collection_configurable.rb +58 -0
  35. data/lib/mongoid/composable.rb +2 -0
  36. data/lib/mongoid/config/defaults.rb +60 -0
  37. data/lib/mongoid/config/options.rb +0 -3
  38. data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
  39. data/lib/mongoid/config/validators.rb +1 -0
  40. data/lib/mongoid/config.rb +99 -28
  41. data/lib/mongoid/contextual/atomic.rb +1 -1
  42. data/lib/mongoid/contextual/memory.rb +233 -33
  43. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  44. data/lib/mongoid/contextual/mongo.rb +370 -133
  45. data/lib/mongoid/contextual/none.rb +162 -7
  46. data/lib/mongoid/contextual.rb +12 -0
  47. data/lib/mongoid/criteria/findable.rb +2 -2
  48. data/lib/mongoid/criteria/includable.rb +4 -3
  49. data/lib/mongoid/criteria/queryable/key.rb +1 -1
  50. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
  51. data/lib/mongoid/criteria/queryable/optional.rb +8 -8
  52. data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
  53. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  54. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  55. data/lib/mongoid/criteria.rb +6 -5
  56. data/lib/mongoid/deprecable.rb +1 -2
  57. data/lib/mongoid/deprecation.rb +3 -3
  58. data/lib/mongoid/errors/create_collection_failure.rb +33 -0
  59. data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
  60. data/lib/mongoid/errors/immutable_attribute.rb +26 -0
  61. data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
  62. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
  63. data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
  64. data/lib/mongoid/errors.rb +4 -1
  65. data/lib/mongoid/extensions/hash.rb +2 -24
  66. data/lib/mongoid/extensions/object.rb +2 -2
  67. data/lib/mongoid/extensions/time.rb +2 -0
  68. data/lib/mongoid/fields/localized.rb +10 -0
  69. data/lib/mongoid/fields/standard.rb +10 -0
  70. data/lib/mongoid/fields.rb +53 -24
  71. data/lib/mongoid/findable.rb +27 -3
  72. data/lib/mongoid/interceptable.rb +10 -118
  73. data/lib/mongoid/matcher/eq_impl.rb +1 -1
  74. data/lib/mongoid/matcher/type.rb +1 -1
  75. data/lib/mongoid/persistable/creatable.rb +1 -0
  76. data/lib/mongoid/persistable/deletable.rb +1 -1
  77. data/lib/mongoid/persistable/savable.rb +13 -1
  78. data/lib/mongoid/persistable/unsettable.rb +2 -2
  79. data/lib/mongoid/persistable/updatable.rb +51 -1
  80. data/lib/mongoid/persistable/upsertable.rb +20 -1
  81. data/lib/mongoid/persistable.rb +3 -0
  82. data/lib/mongoid/query_cache.rb +5 -1
  83. data/lib/mongoid/railties/database.rake +7 -2
  84. data/lib/mongoid/reloadable.rb +5 -3
  85. data/lib/mongoid/stateful.rb +22 -1
  86. data/lib/mongoid/tasks/database.rake +12 -0
  87. data/lib/mongoid/tasks/database.rb +20 -0
  88. data/lib/mongoid/utils.rb +22 -0
  89. data/lib/mongoid/validatable/associated.rb +18 -96
  90. data/lib/mongoid/validatable/macros.rb +5 -5
  91. data/lib/mongoid/validatable.rb +4 -9
  92. data/lib/mongoid/version.rb +1 -1
  93. data/lib/mongoid/warnings.rb +17 -1
  94. data/lib/mongoid.rb +16 -3
  95. data/spec/integration/app_spec.rb +2 -2
  96. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -40
  97. data/spec/integration/callbacks_models.rb +37 -0
  98. data/spec/integration/callbacks_spec.rb +126 -12
  99. data/spec/integration/discriminator_key_spec.rb +4 -5
  100. data/spec/integration/i18n_fallbacks_spec.rb +3 -2
  101. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
  102. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
  103. data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
  104. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
  105. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
  106. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +5 -27
  107. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
  108. data/spec/mongoid/association/syncable_spec.rb +1 -1
  109. data/spec/mongoid/attributes_spec.rb +3 -33
  110. data/spec/mongoid/changeable_spec.rb +299 -24
  111. data/spec/mongoid/clients_spec.rb +122 -13
  112. data/spec/mongoid/collection_configurable_spec.rb +158 -0
  113. data/spec/mongoid/config/defaults_spec.rb +160 -0
  114. data/spec/mongoid/config_spec.rb +154 -27
  115. data/spec/mongoid/contextual/memory_spec.rb +332 -76
  116. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
  117. data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
  118. data/spec/mongoid/contextual/none_spec.rb +49 -2
  119. data/spec/mongoid/copyable_spec.rb +2 -10
  120. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
  121. data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
  122. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
  123. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
  124. data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
  125. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  126. data/spec/mongoid/criteria_projection_spec.rb +1 -4
  127. data/spec/mongoid/criteria_spec.rb +5 -9
  128. data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
  129. data/spec/mongoid/extensions/hash_spec.rb +3 -3
  130. data/spec/mongoid/extensions/time_spec.rb +8 -43
  131. data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
  132. data/spec/mongoid/fields/localized_spec.rb +46 -28
  133. data/spec/mongoid/fields_spec.rb +136 -77
  134. data/spec/mongoid/findable_spec.rb +391 -34
  135. data/spec/mongoid/indexable_spec.rb +16 -10
  136. data/spec/mongoid/interceptable_spec.rb +173 -362
  137. data/spec/mongoid/persistable/deletable_spec.rb +26 -6
  138. data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
  139. data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
  140. data/spec/mongoid/persistable/logical_spec.rb +37 -0
  141. data/spec/mongoid/persistable/poppable_spec.rb +36 -0
  142. data/spec/mongoid/persistable/pullable_spec.rb +72 -0
  143. data/spec/mongoid/persistable/pushable_spec.rb +72 -0
  144. data/spec/mongoid/persistable/renamable_spec.rb +36 -0
  145. data/spec/mongoid/persistable/savable_spec.rb +96 -0
  146. data/spec/mongoid/persistable/settable_spec.rb +37 -0
  147. data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
  148. data/spec/mongoid/persistable/updatable_spec.rb +20 -28
  149. data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
  150. data/spec/mongoid/persistence_context_spec.rb +7 -57
  151. data/spec/mongoid/query_cache_spec.rb +56 -61
  152. data/spec/mongoid/reloadable_spec.rb +24 -28
  153. data/spec/mongoid/scopable_spec.rb +70 -0
  154. data/spec/mongoid/serializable_spec.rb +9 -30
  155. data/spec/mongoid/stateful_spec.rb +122 -8
  156. data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
  157. data/spec/mongoid/tasks/database_spec.rb +127 -0
  158. data/spec/mongoid/timestamps_spec.rb +9 -11
  159. data/spec/mongoid/touchable_spec.rb +277 -5
  160. data/spec/mongoid/touchable_spec_models.rb +3 -1
  161. data/spec/mongoid/traversable_spec.rb +9 -24
  162. data/spec/mongoid/validatable/associated_spec.rb +30 -13
  163. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
  164. data/spec/mongoid_spec.rb +36 -10
  165. data/spec/spec_helper.rb +5 -0
  166. data/spec/support/immutable_ids.rb +118 -0
  167. data/spec/support/macros.rb +47 -15
  168. data/spec/support/models/artist.rb +0 -1
  169. data/spec/support/models/band.rb +1 -0
  170. data/spec/support/models/book.rb +1 -0
  171. data/spec/support/models/building.rb +2 -0
  172. data/spec/support/models/cover.rb +10 -0
  173. data/spec/support/models/name.rb +0 -10
  174. data/spec/support/models/person.rb +0 -1
  175. data/spec/support/models/product.rb +1 -0
  176. data.tar.gz.sig +0 -0
  177. metadata +698 -664
  178. metadata.gz.sig +0 -0
  179. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
  180. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
  181. 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
- context 'with around callbacks' do
1767
- config_override :around_callbacks_for_embeds, true
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
- let(:expected) do
1770
- [
1771
- [InterceptableSpec::CbCascadedChild, :before_validation],
1772
- [InterceptableSpec::CbCascadedChild, :after_validation],
1773
- [InterceptableSpec::CbParent, :before_validation],
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
- it 'calls callbacks in the right order' do
1801
- parent.save!
1802
- expect(registry.calls).to eq expected
1803
- end
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
- context 'without around callbacks' do
1807
- config_override :around_callbacks_for_embeds, false
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
- let(:expected) do
1810
- [
1811
- [InterceptableSpec::CbCascadedChild, :before_validation],
1812
- [InterceptableSpec::CbCascadedChild, :after_validation],
1813
- [InterceptableSpec::CbParent, :before_validation],
1814
- [InterceptableSpec::CbCascadedChild, :before_validation],
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
- it 'calls callbacks in the right order' do
1837
- parent.save!
1838
- expect(registry.calls).to eq expected
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
- context "with around callbacks" do
1903
- config_override :around_callbacks_for_embeds, true
1904
-
1905
- let(:expected) do
1906
- [
1907
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1908
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1909
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
1910
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1911
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1912
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
1913
-
1914
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
1915
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
1916
- [InterceptableSpec::CbEmbedsOneParent, :before_create],
1917
- [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
1918
-
1919
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
1920
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
1921
- [InterceptableSpec::CbEmbedsOneChild, :before_create],
1922
- [InterceptableSpec::CbEmbedsOneChild, :around_create_open],
1923
-
1924
- [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
1925
-
1926
- [InterceptableSpec::CbEmbedsOneChild, :around_create_close],
1927
- [InterceptableSpec::CbEmbedsOneChild, :after_create],
1928
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
1929
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
1930
-
1931
- [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
1932
- [InterceptableSpec::CbEmbedsOneParent, :after_create],
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
- context "without around callbacks" do
1945
- config_override :around_callbacks_for_embeds, false
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
- context "with around callbacks" do
1985
- config_override :around_callbacks_for_embeds, true
1986
-
1987
- let(:expected) do
1988
- [
1989
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1990
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1991
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
1992
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1993
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1994
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
1995
-
1996
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
1997
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
1998
- [InterceptableSpec::CbEmbedsOneParent, :before_update],
1999
- [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2000
-
2001
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2002
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2003
- [InterceptableSpec::CbEmbedsOneChild, :before_update],
2004
- [InterceptableSpec::CbEmbedsOneChild, :around_update_open],
2005
-
2006
- [InterceptableSpec::CbEmbedsOneChild, :around_update_close],
2007
- [InterceptableSpec::CbEmbedsOneChild, :after_update],
2008
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2009
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2010
-
2011
- [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2012
- [InterceptableSpec::CbEmbedsOneParent, :after_update],
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
- context "without around callbacks" do
2034
- config_override :around_callbacks_for_embeds, false
2035
-
2036
- let(:expected) do
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
- parent.callback_registry = registry
2069
- parent.child.callback_registry = registry
2070
- parent.name = "name"
2071
- parent.child.age = 10
1958
+ parent.callback_registry = registry
1959
+ parent.child.callback_registry = registry
1960
+ parent.name = "name"
1961
+ parent.child.age = 10
2072
1962
 
2073
- parent.save!
2074
- expect(registry.calls).to eq expected
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
- context "with around callbacks" do
2156
- config_override :around_callbacks_for_embeds, true
2157
-
2158
- let(:expected) do
2159
- [
2160
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2161
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2162
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2163
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2164
- [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2165
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2166
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2167
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2168
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2169
- [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2170
-
2171
- [InterceptableSpec::CbEmbedsManyParent, :before_save],
2172
- [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2173
- [InterceptableSpec::CbEmbedsManyParent, :before_create],
2174
- [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2175
-
2176
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2177
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2178
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2179
-
2180
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2181
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2182
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2183
-
2184
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2185
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2186
-
2187
- [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2188
-
2189
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2190
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2191
-
2192
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2193
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2194
-
2195
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2196
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2197
-
2198
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2199
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2200
-
2201
- [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2202
- [InterceptableSpec::CbEmbedsManyParent, :after_create],
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
- context "without around callbacks" do
2215
- config_override :around_callbacks_for_embeds, false
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
- let(:from_db) do
16
- Person.only(:_id).first
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
- it "raises an error" do
20
- expect {
21
- from_db.delete
22
- }.to raise_error(Mongoid::Errors::ReadonlyDocument)
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