According to the API docs, :dependent - if set to true, the associated object is destroyed when this object is. ItâÂÂs also destroyed if another association is assigned.
I added the following two test cases around test_dependence in associations_test.rb (around line 136) and the second case fails. The first dependent object is not destroyed.
def test_destroying_removes_dependent_from_db
tw = Firm.create("name" => "ThoughtWorks")
acct = tw.create_account("credit_limit" => 1000)
assert_nothing_raised { Account.find(acct.id) }
tw.destroy
assert_raises(ActiveRecord::RecordNotFound) {
Account.find(acct.id)
}
end
def test_reassignment_removes_old_dependent_from_db
tw = Firm.create("name" => "ThoughtWorks")
first_dependent = tw.create_account("credit_limit" => 1000)
second_dependent = tw.create_account("credit_limit" => 2000)
tw.save!
assert_raises(ActiveRecord::RecordNotFound) {
Account.find(first_dependent.id)
}
end
This is similar to the dependent association bug #2226 but the fix is completely different. I will try to work on a patch soon.