Skip to content

Commit

Permalink
Don't remove the target if it has already been destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltrix committed May 11, 2011
1 parent b3f4519 commit 0fde84c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -10,7 +10,7 @@ def replace(record, save = true)


reflection.klass.transaction do reflection.klass.transaction do
if target && target != record if target && target != record
remove_target!(options[:dependent]) remove_target!(options[:dependent]) unless target.destroyed?
end end


if record if record
Expand Down
Expand Up @@ -95,6 +95,15 @@ def test_nullification_on_association_change
assert_nil Account.find(old_account_id).firm_id assert_nil Account.find(old_account_id).firm_id
end end


def test_natural_assignment_to_nil_after_destroy
firm = companies(:rails_core)
old_account_id = firm.account.id
firm.account.destroy
firm.account = nil
assert_nil companies(:rails_core).account
assert_raise(ActiveRecord::RecordNotFound) { Account.find(old_account_id) }
end

def test_association_change_calls_delete def test_association_change_calls_delete
companies(:first_firm).deletable_account = Account.new(:credit_limit => 5) companies(:first_firm).deletable_account = Account.new(:credit_limit => 5)
assert_equal [], Account.destroyed_account_ids[companies(:first_firm).id] assert_equal [], Account.destroyed_account_ids[companies(:first_firm).id]
Expand Down

0 comments on commit 0fde84c

Please sign in to comment.