mongoid 8.0.9 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) 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 +18 -67
  6. data/lib/config/locales/en.yml +46 -14
  7. data/lib/mongoid/association/accessors.rb +3 -7
  8. data/lib/mongoid/association/builders.rb +1 -1
  9. data/lib/mongoid/association/eager_loadable.rb +0 -3
  10. data/lib/mongoid/association/embedded/batchable.rb +2 -2
  11. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
  12. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
  13. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
  14. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
  15. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
  16. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
  17. data/lib/mongoid/association/macros.rb +0 -6
  18. data/lib/mongoid/association/nested/one.rb +40 -2
  19. data/lib/mongoid/association/proxy.rb +1 -1
  20. data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
  21. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
  22. data/lib/mongoid/association/referenced/has_many/enumerable.rb +2 -2
  23. data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
  24. data/lib/mongoid/association/reflections.rb +2 -2
  25. data/lib/mongoid/atomic.rb +7 -16
  26. data/lib/mongoid/attributes/dynamic.rb +1 -1
  27. data/lib/mongoid/attributes/nested.rb +2 -2
  28. data/lib/mongoid/attributes/processing.rb +5 -29
  29. data/lib/mongoid/attributes/projector.rb +1 -1
  30. data/lib/mongoid/attributes/readonly.rb +1 -1
  31. data/lib/mongoid/attributes.rb +8 -2
  32. data/lib/mongoid/changeable.rb +107 -5
  33. data/lib/mongoid/clients/storage_options.rb +2 -5
  34. data/lib/mongoid/clients/validators/storage.rb +1 -13
  35. data/lib/mongoid/collection_configurable.rb +58 -0
  36. data/lib/mongoid/composable.rb +2 -0
  37. data/lib/mongoid/config/defaults.rb +60 -0
  38. data/lib/mongoid/config/options.rb +0 -3
  39. data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
  40. data/lib/mongoid/config/validators.rb +1 -0
  41. data/lib/mongoid/config.rb +88 -27
  42. data/lib/mongoid/contextual/atomic.rb +1 -1
  43. data/lib/mongoid/contextual/memory.rb +233 -33
  44. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  45. data/lib/mongoid/contextual/mongo.rb +370 -133
  46. data/lib/mongoid/contextual/none.rb +162 -7
  47. data/lib/mongoid/contextual.rb +12 -0
  48. data/lib/mongoid/criteria/findable.rb +2 -2
  49. data/lib/mongoid/criteria/includable.rb +4 -3
  50. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
  51. data/lib/mongoid/criteria/queryable/key.rb +1 -1
  52. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
  53. data/lib/mongoid/criteria/queryable/optional.rb +8 -8
  54. data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
  55. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  56. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  57. data/lib/mongoid/criteria.rb +6 -5
  58. data/lib/mongoid/deprecable.rb +1 -2
  59. data/lib/mongoid/deprecation.rb +3 -3
  60. data/lib/mongoid/document.rb +1 -8
  61. data/lib/mongoid/errors/create_collection_failure.rb +33 -0
  62. data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
  63. data/lib/mongoid/errors/immutable_attribute.rb +26 -0
  64. data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
  65. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
  66. data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
  67. data/lib/mongoid/errors.rb +4 -1
  68. data/lib/mongoid/extensions/hash.rb +2 -24
  69. data/lib/mongoid/extensions/object.rb +2 -2
  70. data/lib/mongoid/extensions/time.rb +2 -0
  71. data/lib/mongoid/fields/localized.rb +10 -0
  72. data/lib/mongoid/fields/standard.rb +10 -0
  73. data/lib/mongoid/fields.rb +59 -35
  74. data/lib/mongoid/findable.rb +27 -3
  75. data/lib/mongoid/interceptable.rb +6 -116
  76. data/lib/mongoid/matcher/eq_impl.rb +1 -1
  77. data/lib/mongoid/matcher/type.rb +1 -1
  78. data/lib/mongoid/persistable/creatable.rb +1 -0
  79. data/lib/mongoid/persistable/deletable.rb +1 -1
  80. data/lib/mongoid/persistable/savable.rb +13 -1
  81. data/lib/mongoid/persistable/unsettable.rb +2 -2
  82. data/lib/mongoid/persistable/updatable.rb +51 -1
  83. data/lib/mongoid/persistable/upsertable.rb +20 -1
  84. data/lib/mongoid/persistable.rb +3 -0
  85. data/lib/mongoid/query_cache.rb +5 -1
  86. data/lib/mongoid/railties/database.rake +7 -2
  87. data/lib/mongoid/reloadable.rb +5 -3
  88. data/lib/mongoid/stateful.rb +22 -1
  89. data/lib/mongoid/tasks/database.rake +12 -0
  90. data/lib/mongoid/tasks/database.rb +20 -0
  91. data/lib/mongoid/timestamps/created.rb +1 -8
  92. data/lib/mongoid/traversable.rb +0 -12
  93. data/lib/mongoid/utils.rb +22 -0
  94. data/lib/mongoid/validatable/associated.rb +17 -98
  95. data/lib/mongoid/validatable/macros.rb +5 -5
  96. data/lib/mongoid/validatable.rb +4 -9
  97. data/lib/mongoid/version.rb +1 -1
  98. data/lib/mongoid/warnings.rb +17 -1
  99. data/lib/mongoid.rb +16 -3
  100. data/spec/integration/app_spec.rb +2 -2
  101. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -40
  102. data/spec/integration/callbacks_spec.rb +99 -12
  103. data/spec/integration/discriminator_key_spec.rb +4 -5
  104. data/spec/integration/i18n_fallbacks_spec.rb +3 -2
  105. data/spec/mongoid/association/eager_spec.rb +2 -24
  106. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
  107. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
  108. data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
  109. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
  110. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
  111. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
  112. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +5 -27
  113. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
  114. data/spec/mongoid/association/syncable_spec.rb +1 -1
  115. data/spec/mongoid/association_spec.rb +0 -60
  116. data/spec/mongoid/attributes_spec.rb +3 -33
  117. data/spec/mongoid/changeable_spec.rb +299 -24
  118. data/spec/mongoid/clients_spec.rb +122 -13
  119. data/spec/mongoid/collection_configurable_spec.rb +158 -0
  120. data/spec/mongoid/config/defaults_spec.rb +160 -0
  121. data/spec/mongoid/config_spec.rb +154 -27
  122. data/spec/mongoid/contextual/memory_spec.rb +332 -76
  123. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
  124. data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
  125. data/spec/mongoid/contextual/none_spec.rb +49 -2
  126. data/spec/mongoid/copyable_spec.rb +2 -10
  127. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
  128. data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
  129. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
  130. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
  131. data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
  132. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  133. data/spec/mongoid/criteria_projection_spec.rb +1 -4
  134. data/spec/mongoid/criteria_spec.rb +5 -9
  135. data/spec/mongoid/document_spec.rb +0 -27
  136. data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
  137. data/spec/mongoid/extensions/hash_spec.rb +3 -3
  138. data/spec/mongoid/extensions/time_spec.rb +8 -43
  139. data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
  140. data/spec/mongoid/fields/localized_spec.rb +46 -28
  141. data/spec/mongoid/fields_spec.rb +136 -77
  142. data/spec/mongoid/findable_spec.rb +391 -34
  143. data/spec/mongoid/indexable_spec.rb +16 -10
  144. data/spec/mongoid/interceptable_spec.rb +153 -442
  145. data/spec/mongoid/interceptable_spec_models.rb +111 -51
  146. data/spec/mongoid/persistable/deletable_spec.rb +26 -6
  147. data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
  148. data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
  149. data/spec/mongoid/persistable/logical_spec.rb +37 -0
  150. data/spec/mongoid/persistable/poppable_spec.rb +36 -0
  151. data/spec/mongoid/persistable/pullable_spec.rb +72 -0
  152. data/spec/mongoid/persistable/pushable_spec.rb +72 -0
  153. data/spec/mongoid/persistable/renamable_spec.rb +36 -0
  154. data/spec/mongoid/persistable/savable_spec.rb +96 -0
  155. data/spec/mongoid/persistable/settable_spec.rb +37 -0
  156. data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
  157. data/spec/mongoid/persistable/updatable_spec.rb +20 -28
  158. data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
  159. data/spec/mongoid/persistence_context_spec.rb +7 -57
  160. data/spec/mongoid/query_cache_spec.rb +56 -61
  161. data/spec/mongoid/reloadable_spec.rb +24 -28
  162. data/spec/mongoid/scopable_spec.rb +70 -0
  163. data/spec/mongoid/serializable_spec.rb +23 -44
  164. data/spec/mongoid/stateful_spec.rb +122 -8
  165. data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
  166. data/spec/mongoid/tasks/database_spec.rb +127 -0
  167. data/spec/mongoid/timestamps/created_spec.rb +0 -23
  168. data/spec/mongoid/timestamps_spec.rb +9 -11
  169. data/spec/mongoid/touchable_spec.rb +277 -5
  170. data/spec/mongoid/touchable_spec_models.rb +3 -1
  171. data/spec/mongoid/traversable_spec.rb +9 -24
  172. data/spec/mongoid/validatable/associated_spec.rb +34 -27
  173. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
  174. data/spec/mongoid_spec.rb +36 -10
  175. data/spec/shared/LICENSE +20 -0
  176. data/spec/shared/bin/get-mongodb-download-url +17 -0
  177. data/spec/shared/bin/s3-copy +45 -0
  178. data/spec/shared/bin/s3-upload +69 -0
  179. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  180. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  181. data/spec/shared/lib/mrss/constraints.rb +378 -0
  182. data/spec/shared/lib/mrss/docker_runner.rb +298 -0
  183. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  184. data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
  185. data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
  186. data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
  187. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  188. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  189. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  190. data/spec/shared/lib/mrss/utils.rb +37 -0
  191. data/spec/shared/share/Dockerfile.erb +321 -0
  192. data/spec/shared/share/haproxy-1.conf +16 -0
  193. data/spec/shared/share/haproxy-2.conf +17 -0
  194. data/spec/shared/shlib/config.sh +27 -0
  195. data/spec/shared/shlib/distro.sh +74 -0
  196. data/spec/shared/shlib/server.sh +416 -0
  197. data/spec/shared/shlib/set_env.sh +169 -0
  198. data/spec/spec_helper.rb +5 -0
  199. data/spec/support/immutable_ids.rb +118 -0
  200. data/spec/support/macros.rb +47 -15
  201. data/spec/support/models/artist.rb +0 -1
  202. data/spec/support/models/band.rb +1 -0
  203. data/spec/support/models/book.rb +1 -0
  204. data/spec/support/models/building.rb +2 -0
  205. data/spec/support/models/cover.rb +10 -0
  206. data/spec/support/models/name.rb +0 -10
  207. data/spec/support/models/person.rb +0 -1
  208. data/spec/support/models/product.rb +1 -0
  209. data.tar.gz.sig +0 -0
  210. metadata +746 -636
  211. metadata.gz.sig +2 -0
  212. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
  213. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
  214. data/spec/support/models/purse.rb +0 -9
@@ -388,86 +388,6 @@ describe Mongoid::Interceptable do
388
388
  end
389
389
  end
390
390
  end
391
-
392
- context 'with embedded grandchildren' do
393
- IS = InterceptableSpec
394
-
395
- config_override :prevent_multiple_calls_of_embedded_callbacks, true
396
-
397
- context 'when creating' do
398
- let(:registry) { IS::CallbackRegistry.new(only: %i[ before_save ]) }
399
-
400
- let(:expected_calls) do
401
- [
402
- # the parent
403
- [ IS::CbParent, :before_save ],
404
-
405
- # the immediate child of the parent
406
- [ IS::CbCascadedNode, :before_save ],
407
-
408
- # the grandchild of the parent
409
- [ IS::CbCascadedNode, :before_save ],
410
- ]
411
- end
412
-
413
- let!(:parent) do
414
- parent = IS::CbParent.new(registry)
415
- child = IS::CbCascadedNode.new(registry)
416
- grandchild = IS::CbCascadedNode.new(registry)
417
-
418
- child.cb_cascaded_nodes = [ grandchild ]
419
- parent.cb_cascaded_nodes = [ child ]
420
-
421
- parent.tap(&:save)
422
- end
423
-
424
- it 'should cascade callbacks to grandchildren' do
425
- expect(registry.calls).to be == expected_calls
426
- end
427
- end
428
-
429
- context 'when updating' do
430
- let(:registry) { IS::CallbackRegistry.new(only: %i[ before_update ]) }
431
-
432
- let(:expected_calls) do
433
- [
434
- # the parent
435
- [ IS::CbParent, :before_update ],
436
-
437
- # the immediate child of the parent
438
- [ IS::CbCascadedNode, :before_update ],
439
-
440
- # the grandchild of the parent
441
- [ IS::CbCascadedNode, :before_update ],
442
- ]
443
- end
444
-
445
- let!(:parent) do
446
- parent = IS::CbParent.new(nil)
447
- child = IS::CbCascadedNode.new(nil)
448
- grandchild = IS::CbCascadedNode.new(nil)
449
-
450
- child.cb_cascaded_nodes = [ grandchild ]
451
- parent.cb_cascaded_nodes = [ child ]
452
-
453
- parent.save
454
-
455
- parent.callback_registry = registry
456
- child.callback_registry = registry
457
- grandchild.callback_registry = registry
458
-
459
- parent.name = 'updated'
460
- child.name = 'updated'
461
- grandchild.name = 'updated'
462
-
463
- parent.tap(&:save)
464
- end
465
-
466
- it 'should cascade callbacks to grandchildren' do
467
- expect(registry.calls).to be == expected_calls
468
- end
469
- end
470
- end
471
391
  end
472
392
 
473
393
  describe ".before_destroy" do
@@ -1863,80 +1783,40 @@ describe Mongoid::Interceptable do
1863
1783
  end
1864
1784
  end
1865
1785
 
1866
- context 'with around callbacks' do
1867
- 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],
1868
1793
 
1869
- let(:expected) do
1870
- [
1871
- [InterceptableSpec::CbCascadedChild, :before_validation],
1872
- [InterceptableSpec::CbCascadedChild, :after_validation],
1873
- [InterceptableSpec::CbParent, :before_validation],
1874
- [InterceptableSpec::CbCascadedChild, :before_validation],
1875
- [InterceptableSpec::CbCascadedChild, :after_validation],
1876
-
1877
- [InterceptableSpec::CbParent, :after_validation],
1878
- [InterceptableSpec::CbParent, :before_save],
1879
- [InterceptableSpec::CbParent, :around_save_open],
1880
- [InterceptableSpec::CbParent, :before_create],
1881
- [InterceptableSpec::CbParent, :around_create_open],
1882
-
1883
- [InterceptableSpec::CbCascadedChild, :before_save],
1884
- [InterceptableSpec::CbCascadedChild, :around_save_open],
1885
- [InterceptableSpec::CbCascadedChild, :before_create],
1886
- [InterceptableSpec::CbCascadedChild, :around_create_open],
1887
-
1888
- [InterceptableSpec::CbCascadedChild, :around_create_close],
1889
- [InterceptableSpec::CbCascadedChild, :after_create],
1890
- [InterceptableSpec::CbCascadedChild, :around_save_close],
1891
- [InterceptableSpec::CbCascadedChild, :after_save],
1892
-
1893
- [InterceptableSpec::CbParent, :around_create_close],
1894
- [InterceptableSpec::CbParent, :after_create],
1895
- [InterceptableSpec::CbParent, :around_save_close],
1896
- [InterceptableSpec::CbParent, :after_save]
1897
- ]
1898
- 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],
1899
1799
 
1900
- it 'calls callbacks in the right order' do
1901
- parent.save!
1902
- expect(registry.calls).to eq expected
1903
- end
1904
- end
1800
+ [InterceptableSpec::CbCascadedChild, :before_save],
1801
+ [InterceptableSpec::CbCascadedChild, :around_save_open],
1802
+ [InterceptableSpec::CbCascadedChild, :before_create],
1803
+ [InterceptableSpec::CbCascadedChild, :around_create_open],
1905
1804
 
1906
- context 'without around callbacks' do
1907
- 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],
1908
1809
 
1909
- let(:expected) do
1910
- [
1911
- [InterceptableSpec::CbCascadedChild, :before_validation],
1912
- [InterceptableSpec::CbCascadedChild, :after_validation],
1913
- [InterceptableSpec::CbParent, :before_validation],
1914
- [InterceptableSpec::CbCascadedChild, :before_validation],
1915
- [InterceptableSpec::CbCascadedChild, :after_validation],
1916
-
1917
- [InterceptableSpec::CbParent, :after_validation],
1918
- [InterceptableSpec::CbParent, :before_save],
1919
- [InterceptableSpec::CbParent, :around_save_open],
1920
- [InterceptableSpec::CbParent, :before_create],
1921
- [InterceptableSpec::CbParent, :around_create_open],
1922
-
1923
- [InterceptableSpec::CbCascadedChild, :before_save],
1924
- [InterceptableSpec::CbCascadedChild, :before_create],
1925
-
1926
- [InterceptableSpec::CbCascadedChild, :after_create],
1927
- [InterceptableSpec::CbCascadedChild, :after_save],
1928
-
1929
- [InterceptableSpec::CbParent, :around_create_close],
1930
- [InterceptableSpec::CbParent, :after_create],
1931
- [InterceptableSpec::CbParent, :around_save_close],
1932
- [InterceptableSpec::CbParent, :after_save]
1933
- ]
1934
- 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
1935
1816
 
1936
- it 'calls callbacks in the right order' do
1937
- parent.save!
1938
- expect(registry.calls).to eq expected
1939
- end
1817
+ it 'calls callbacks in the right order' do
1818
+ parent.save!
1819
+ expect(registry.calls).to eq expected
1940
1820
  end
1941
1821
  end
1942
1822
 
@@ -1999,180 +1879,89 @@ describe Mongoid::Interceptable do
1999
1879
  end
2000
1880
 
2001
1881
  context "create" do
2002
- context "with around callbacks" do
2003
- config_override :around_callbacks_for_embeds, true
2004
-
2005
- let(:expected) do
2006
- [
2007
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2008
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2009
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2010
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2011
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2012
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2013
-
2014
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2015
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2016
- [InterceptableSpec::CbEmbedsOneParent, :before_create],
2017
- [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
2018
-
2019
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2020
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2021
- [InterceptableSpec::CbEmbedsOneChild, :before_create],
2022
- [InterceptableSpec::CbEmbedsOneChild, :around_create_open],
2023
-
2024
- [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
2025
-
2026
- [InterceptableSpec::CbEmbedsOneChild, :around_create_close],
2027
- [InterceptableSpec::CbEmbedsOneChild, :after_create],
2028
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2029
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2030
-
2031
- [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
2032
- [InterceptableSpec::CbEmbedsOneParent, :after_create],
2033
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2034
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
2035
- ]
2036
- end
2037
-
2038
- it 'calls callbacks in the right order' do
2039
- parent.save!
2040
- expect(registry.calls).to eq expected
2041
- 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
+ ]
2042
1913
  end
2043
1914
 
2044
- context "without around callbacks" do
2045
- config_override :around_callbacks_for_embeds, false
2046
-
2047
- let(:expected) do
2048
- [
2049
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2050
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2051
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2052
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2053
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2054
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2055
-
2056
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2057
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2058
- [InterceptableSpec::CbEmbedsOneParent, :before_create],
2059
- [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
2060
-
2061
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2062
- [InterceptableSpec::CbEmbedsOneChild, :before_create],
2063
-
2064
- [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
2065
-
2066
- [InterceptableSpec::CbEmbedsOneChild, :after_create],
2067
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2068
-
2069
- [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
2070
- [InterceptableSpec::CbEmbedsOneParent, :after_create],
2071
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2072
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
2073
- ]
2074
- end
2075
-
2076
- it 'calls callbacks in the right order' do
2077
- parent.save!
2078
- expect(registry.calls).to eq expected
2079
- end
1915
+ it 'calls callbacks in the right order' do
1916
+ parent.save!
1917
+ expect(registry.calls).to eq expected
2080
1918
  end
2081
1919
  end
2082
1920
 
2083
1921
  context "update" do
2084
- context "with around callbacks" do
2085
- config_override :around_callbacks_for_embeds, true
2086
-
2087
- let(:expected) do
2088
- [
2089
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2090
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2091
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2092
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2093
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2094
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2095
-
2096
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2097
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2098
- [InterceptableSpec::CbEmbedsOneParent, :before_update],
2099
- [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2100
-
2101
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2102
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2103
- [InterceptableSpec::CbEmbedsOneChild, :before_update],
2104
- [InterceptableSpec::CbEmbedsOneChild, :around_update_open],
2105
-
2106
- [InterceptableSpec::CbEmbedsOneChild, :around_update_close],
2107
- [InterceptableSpec::CbEmbedsOneChild, :after_update],
2108
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2109
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2110
-
2111
- [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2112
- [InterceptableSpec::CbEmbedsOneParent, :after_update],
2113
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2114
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
2115
- ]
2116
- end
2117
-
2118
- it 'calls callbacks in the right order' do
2119
- parent.callback_registry = nil
2120
- parent.child.callback_registry = nil
2121
- parent.save!
2122
-
2123
- parent.callback_registry = registry
2124
- parent.child.callback_registry = registry
2125
- parent.name = "name"
2126
- parent.child.age = 10
2127
-
2128
- parent.save!
2129
- expect(registry.calls).to eq expected
2130
- 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
+ ]
2131
1951
  end
2132
1952
 
2133
- context "without around callbacks" do
2134
- config_override :around_callbacks_for_embeds, false
2135
-
2136
- let(:expected) do
2137
- [
2138
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2139
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2140
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2141
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2142
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2143
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2144
-
2145
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2146
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2147
- [InterceptableSpec::CbEmbedsOneParent, :before_update],
2148
- [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2149
-
2150
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2151
- [InterceptableSpec::CbEmbedsOneChild, :before_update],
2152
-
2153
- [InterceptableSpec::CbEmbedsOneChild, :after_update],
2154
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2155
-
2156
- [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2157
- [InterceptableSpec::CbEmbedsOneParent, :after_update],
2158
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2159
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
2160
- ]
2161
- end
2162
-
2163
- it 'calls callbacks in the right order' do
2164
- parent.callback_registry = nil
2165
- parent.child.callback_registry = nil
2166
- 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!
2167
1957
 
2168
- parent.callback_registry = registry
2169
- parent.child.callback_registry = registry
2170
- parent.name = "name"
2171
- parent.child.age = 10
1958
+ parent.callback_registry = registry
1959
+ parent.child.callback_registry = registry
1960
+ parent.name = "name"
1961
+ parent.child.age = 10
2172
1962
 
2173
- parent.save!
2174
- expect(registry.calls).to eq expected
2175
- end
1963
+ parent.save!
1964
+ expect(registry.calls).to eq expected
2176
1965
  end
2177
1966
  end
2178
1967
  end
@@ -2252,114 +2041,59 @@ describe Mongoid::Interceptable do
2252
2041
  end
2253
2042
  end
2254
2043
 
2255
- context "with around callbacks" do
2256
- config_override :around_callbacks_for_embeds, true
2257
-
2258
- let(:expected) do
2259
- [
2260
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2261
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2262
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2263
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2264
- [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2265
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2266
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2267
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2268
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2269
- [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2270
-
2271
- [InterceptableSpec::CbEmbedsManyParent, :before_save],
2272
- [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2273
- [InterceptableSpec::CbEmbedsManyParent, :before_create],
2274
- [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2275
-
2276
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2277
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2278
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2279
-
2280
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2281
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2282
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2283
-
2284
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2285
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2286
-
2287
- [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2288
-
2289
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2290
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2291
-
2292
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2293
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2294
-
2295
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2296
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2297
-
2298
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2299
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2300
-
2301
- [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2302
- [InterceptableSpec::CbEmbedsManyParent, :after_create],
2303
- [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2304
- [InterceptableSpec::CbEmbedsManyParent, :after_save]
2305
- ]
2306
- end
2307
-
2308
- it 'calls callbacks in the right order' do
2309
- parent.save!
2310
- expect(registry.calls).to eq expected
2311
- 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
+ ]
2312
2092
  end
2313
2093
 
2314
- context "without around callbacks" do
2315
- config_override :around_callbacks_for_embeds, false
2316
-
2317
- let(:expected) do
2318
- [
2319
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2320
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2321
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2322
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2323
- [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2324
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2325
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2326
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2327
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2328
- [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2329
-
2330
- [InterceptableSpec::CbEmbedsManyParent, :before_save],
2331
- [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2332
- [InterceptableSpec::CbEmbedsManyParent, :before_create],
2333
- [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2334
-
2335
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2336
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2337
-
2338
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2339
-
2340
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2341
-
2342
- [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2343
-
2344
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2345
-
2346
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2347
-
2348
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2349
-
2350
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2351
-
2352
- [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2353
- [InterceptableSpec::CbEmbedsManyParent, :after_create],
2354
- [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2355
- [InterceptableSpec::CbEmbedsManyParent, :after_save]
2356
- ]
2357
- end
2358
-
2359
- it 'calls callbacks in the right order' do
2360
- parent.save!
2361
- expect(registry.calls).to eq expected
2362
- end
2094
+ it 'calls callbacks in the right order' do
2095
+ parent.save!
2096
+ expect(registry.calls).to eq expected
2363
2097
  end
2364
2098
  end
2365
2099
  end
@@ -2648,27 +2382,4 @@ describe Mongoid::Interceptable do
2648
2382
  end.to_not raise_error(ActiveModel::MissingAttributeError)
2649
2383
  end
2650
2384
  end
2651
-
2652
- context "when around callbacks for embedded are disabled" do
2653
- config_override :around_callbacks_for_embeds, false
2654
-
2655
- context "when around callback is defined" do
2656
- let(:registry) { InterceptableSpec::CallbackRegistry.new }
2657
-
2658
- let(:parent) do
2659
- InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
2660
- parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
2661
- end
2662
- end
2663
-
2664
- before do
2665
- expect(Mongoid.logger).to receive(:warn).with(/Around callbacks are disabled for embedded documents/).twice.and_call_original
2666
- expect(Mongoid.logger).to receive(:warn).with(/To enable around callbacks for embedded documents/).twice.and_call_original
2667
- end
2668
-
2669
- it "logs a warning" do
2670
- parent.save!
2671
- end
2672
- end
2673
- end
2674
2385
  end