@@ -314,6 +314,17 @@ def test_callbacks_on_child_when_parent_autosaves_child
314
314
assert_equal 1 , eye . iris . after_save_callbacks_counter
315
315
end
316
316
317
+ def test_callbacks_on_child_when_parent_autosaves_child_twice
318
+ eye = Eye . create! ( iris : Iris . new )
319
+ eye . update! ( iris : Iris . new )
320
+ assert_equal 1 , eye . iris . before_validation_callbacks_counter
321
+ assert_equal 1 , eye . iris . before_create_callbacks_counter
322
+ assert_equal 1 , eye . iris . before_save_callbacks_counter
323
+ assert_equal 1 , eye . iris . after_validation_callbacks_counter
324
+ assert_equal 1 , eye . iris . after_create_callbacks_counter
325
+ assert_equal 1 , eye . iris . after_save_callbacks_counter
326
+ end
327
+
317
328
def test_callbacks_on_child_when_parent_autosaves_polymorphic_child_with_inverse_of
318
329
drink_designer = DrinkDesigner . create! ( chef : ChefWithPolymorphicInverseOf . new )
319
330
assert_equal 1 , drink_designer . chef . before_validation_callbacks_counter
@@ -334,6 +345,17 @@ def test_callbacks_on_child_when_child_autosaves_parent
334
345
assert_equal 1 , iris . after_save_callbacks_counter
335
346
end
336
347
348
+ def test_callbacks_on_child_when_child_autosaves_parent_twice
349
+ iris = Iris . create! ( eye : Eye . new )
350
+ iris . update! ( eye : Eye . new )
351
+ assert_equal 2 , iris . before_validation_callbacks_counter
352
+ assert_equal 1 , iris . before_create_callbacks_counter
353
+ assert_equal 2 , iris . before_save_callbacks_counter
354
+ assert_equal 2 , iris . after_validation_callbacks_counter
355
+ assert_equal 1 , iris . after_create_callbacks_counter
356
+ assert_equal 2 , iris . after_save_callbacks_counter
357
+ end
358
+
337
359
def test_callbacks_on_child_when_polymorphic_child_with_inverse_of_autosaves_parent
338
360
chef = ChefWithPolymorphicInverseOf . create! ( employable : DrinkDesigner . new )
339
361
assert_equal 1 , chef . before_validation_callbacks_counter
@@ -1812,6 +1834,12 @@ def test_should_save_with_non_nullable_foreign_keys
1812
1834
child . save!
1813
1835
assert_equal child . reload . post , parent . reload
1814
1836
end
1837
+
1838
+ def test_should_save_if_previously_saved
1839
+ ship = Ship . create ( name : "Nights Dirty Lightning" , pirate : Pirate . new ( catchphrase : "Arrrr" ) )
1840
+ ship . create_pirate ( catchphrase : "Savvy?" )
1841
+ assert_equal "Savvy?" , ship . reload . pirate . catchphrase
1842
+ end
1815
1843
end
1816
1844
1817
1845
module AutosaveAssociationOnACollectionAssociationTests
0 commit comments