diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/association_callbacks_test.rb | 14 | ||||
-rwxr-xr-x | activerecord/test/associations_test.rb | 4 |
2 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/test/association_callbacks_test.rb b/activerecord/test/association_callbacks_test.rb index 5ea1f541ed..1426fb71a9 100644 --- a/activerecord/test/association_callbacks_test.rb +++ b/activerecord/test/association_callbacks_test.rb @@ -83,6 +83,20 @@ class AssociationCallbacksTest < Test::Unit::TestCase assert_equal ["before_removing#{david.id}", "after_removing#{david.id}", "before_removing#{jamis.id}", "after_removing#{jamis.id}"], activerecord.developers_log end + + def test_has_and_belongs_to_many_remove_callback_on_clear + activerecord = projects(:active_record) + assert activerecord.developers_log.empty? + if activerecord.developers_with_callbacks.size == 0 + activerecord.developers << developers(:david) + activerecord.developers << developers(:jamis) + activerecord.reload + assert activerecord.developers_with_callbacks.size == 2 + end + log_array = activerecord.developers_with_callbacks.collect {|d| ["before_removing#{d.id}","after_removing#{d.id}"]}.flatten.sort + assert activerecord.developers_with_callbacks.clear + assert_equal log_array, activerecord.developers_log.sort + end def test_dont_add_if_before_callback_raises_exception assert !@david.unchangable_posts.include?(@authorless) diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index fc8d59e862..5cafa010f9 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -551,13 +551,15 @@ class HasManyAssociationsTest < Test::Unit::TestCase client_id = firm.exclusively_dependent_clients_of_firm.first.id assert_equal 1, firm.exclusively_dependent_clients_of_firm.size + assert_equal [], Client.destroyed_client_ids[firm.id] + # :exclusively_dependent means each client is deleted directly from # the database without looping through them calling destroy. firm.exclusively_dependent_clients_of_firm.clear assert_equal 0, firm.exclusively_dependent_clients_of_firm.size assert_equal 0, firm.exclusively_dependent_clients_of_firm(true).size - assert_equal [], Client.destroyed_client_ids[firm.id] + assert_equal [3], Client.destroyed_client_ids[firm.id] # Should be destroyed since the association is exclusively dependent. assert Client.find_by_id(client_id).nil? |