mongoid 8.0.6 → 8.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,7 +90,7 @@ describe Mongoid::Copyable do
90
90
  end
91
91
 
92
92
  it 'calls constructor with explicitly declared attributes only' do
93
- expect(Mongoid::Factory).to receive(:build).with(cls, 'name' => 'test').and_call_original
93
+ expect(Mongoid::Factory).to receive(:build).with(cls, { 'name' => 'test' }).and_call_original
94
94
  cloned
95
95
  end
96
96
  end
@@ -578,14 +578,6 @@ 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
-
584
- it "only executes the callbacks once for each embed" do
585
- expect(note).to receive(:update_saved).twice
586
- band.save!
587
- end
588
- end
589
581
  end
590
582
  end
591
583
 
@@ -1771,40 +1763,80 @@ describe Mongoid::Interceptable do
1771
1763
  end
1772
1764
  end
1773
1765
 
1774
- let(:expected) do
1775
- [
1776
- [InterceptableSpec::CbCascadedChild, :before_validation],
1777
- [InterceptableSpec::CbCascadedChild, :after_validation],
1778
- [InterceptableSpec::CbParent, :before_validation],
1779
- [InterceptableSpec::CbCascadedChild, :before_validation],
1780
- [InterceptableSpec::CbCascadedChild, :after_validation],
1766
+ context 'with around callbacks' do
1767
+ config_override :around_callbacks_for_embeds, true
1781
1768
 
1782
- [InterceptableSpec::CbParent, :after_validation],
1783
- [InterceptableSpec::CbParent, :before_save],
1784
- [InterceptableSpec::CbParent, :around_save_open],
1785
- [InterceptableSpec::CbParent, :before_create],
1786
- [InterceptableSpec::CbParent, :around_create_open],
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
1787
1799
 
1788
- [InterceptableSpec::CbCascadedChild, :before_save],
1789
- [InterceptableSpec::CbCascadedChild, :around_save_open],
1790
- [InterceptableSpec::CbCascadedChild, :before_create],
1791
- [InterceptableSpec::CbCascadedChild, :around_create_open],
1800
+ it 'calls callbacks in the right order' do
1801
+ parent.save!
1802
+ expect(registry.calls).to eq expected
1803
+ end
1804
+ end
1792
1805
 
1793
- [InterceptableSpec::CbCascadedChild, :around_create_close],
1794
- [InterceptableSpec::CbCascadedChild, :after_create],
1795
- [InterceptableSpec::CbCascadedChild, :around_save_close],
1796
- [InterceptableSpec::CbCascadedChild, :after_save],
1806
+ context 'without around callbacks' do
1807
+ config_override :around_callbacks_for_embeds, false
1797
1808
 
1798
- [InterceptableSpec::CbParent, :around_create_close],
1799
- [InterceptableSpec::CbParent, :after_create],
1800
- [InterceptableSpec::CbParent, :around_save_close],
1801
- [InterceptableSpec::CbParent, :after_save]
1802
- ]
1803
- end
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
1804
1835
 
1805
- it 'calls callbacks in the right order' do
1806
- parent.save!
1807
- expect(registry.calls).to eq expected
1836
+ it 'calls callbacks in the right order' do
1837
+ parent.save!
1838
+ expect(registry.calls).to eq expected
1839
+ end
1808
1840
  end
1809
1841
  end
1810
1842
 
@@ -1867,89 +1899,180 @@ describe Mongoid::Interceptable do
1867
1899
  end
1868
1900
 
1869
1901
  context "create" do
1870
- let(:expected) do
1871
- [
1872
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1873
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1874
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
1875
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1876
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1877
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
1878
-
1879
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
1880
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
1881
- [InterceptableSpec::CbEmbedsOneParent, :before_create],
1882
- [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
1883
-
1884
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
1885
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
1886
- [InterceptableSpec::CbEmbedsOneChild, :before_create],
1887
- [InterceptableSpec::CbEmbedsOneChild, :around_create_open],
1888
-
1889
- [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
1890
-
1891
- [InterceptableSpec::CbEmbedsOneChild, :around_create_close],
1892
- [InterceptableSpec::CbEmbedsOneChild, :after_create],
1893
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
1894
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
1895
-
1896
- [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
1897
- [InterceptableSpec::CbEmbedsOneParent, :after_create],
1898
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
1899
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
1900
- ]
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
1901
1942
  end
1902
1943
 
1903
- it 'calls callbacks in the right order' do
1904
- parent.save!
1905
- expect(registry.calls).to eq expected
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
1906
1980
  end
1907
1981
  end
1908
1982
 
1909
1983
  context "update" do
1910
- let(:expected) do
1911
- [
1912
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1913
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1914
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
1915
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
1916
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
1917
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
1918
-
1919
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
1920
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
1921
- [InterceptableSpec::CbEmbedsOneParent, :before_update],
1922
- [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
1923
-
1924
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
1925
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
1926
- [InterceptableSpec::CbEmbedsOneChild, :before_update],
1927
- [InterceptableSpec::CbEmbedsOneChild, :around_update_open],
1928
-
1929
- [InterceptableSpec::CbEmbedsOneChild, :around_update_close],
1930
- [InterceptableSpec::CbEmbedsOneChild, :after_update],
1931
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
1932
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
1933
-
1934
- [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
1935
- [InterceptableSpec::CbEmbedsOneParent, :after_update],
1936
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
1937
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
1938
- ]
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
1939
2031
  end
1940
2032
 
1941
- it 'calls callbacks in the right order' do
1942
- parent.callback_registry = nil
1943
- parent.child.callback_registry = nil
1944
- parent.save!
2033
+ context "without around callbacks" do
2034
+ config_override :around_callbacks_for_embeds, false
1945
2035
 
1946
- parent.callback_registry = registry
1947
- parent.child.callback_registry = registry
1948
- parent.name = "name"
1949
- parent.child.age = 10
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],
1950
2044
 
1951
- parent.save!
1952
- expect(registry.calls).to eq expected
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!
2067
+
2068
+ parent.callback_registry = registry
2069
+ parent.child.callback_registry = registry
2070
+ parent.name = "name"
2071
+ parent.child.age = 10
2072
+
2073
+ parent.save!
2074
+ expect(registry.calls).to eq expected
2075
+ end
1953
2076
  end
1954
2077
  end
1955
2078
  end
@@ -2029,59 +2152,114 @@ describe Mongoid::Interceptable do
2029
2152
  end
2030
2153
  end
2031
2154
 
2032
- let(:expected) do
2033
- [
2034
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2035
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2036
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2037
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2038
- [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2039
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2040
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2041
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2042
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2043
- [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2044
-
2045
- [InterceptableSpec::CbEmbedsManyParent, :before_save],
2046
- [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2047
- [InterceptableSpec::CbEmbedsManyParent, :before_create],
2048
- [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2049
-
2050
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2051
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2052
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2053
-
2054
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2055
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2056
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2057
-
2058
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2059
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2060
-
2061
- [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2062
-
2063
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2064
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2065
-
2066
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2067
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2068
-
2069
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2070
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2071
-
2072
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2073
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2074
-
2075
- [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2076
- [InterceptableSpec::CbEmbedsManyParent, :after_create],
2077
- [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2078
- [InterceptableSpec::CbEmbedsManyParent, :after_save]
2079
- ]
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
2080
2212
  end
2081
2213
 
2082
- it 'calls callbacks in the right order' do
2083
- parent.save!
2084
- expect(registry.calls).to eq expected
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
2085
2263
  end
2086
2264
  end
2087
2265
  end
@@ -2370,4 +2548,27 @@ describe Mongoid::Interceptable do
2370
2548
  end.to_not raise_error(ActiveModel::MissingAttributeError)
2371
2549
  end
2372
2550
  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
2373
2574
  end