Skip to content

Instantly share code, notes, and snippets.

@miloops
Created May 9, 2011 20:20
Show Gist options
  • Save miloops/963301 to your computer and use it in GitHub Desktop.
Save miloops/963301 to your computer and use it in GitHub Desktop.
def test_does_not_delete_association_if_it_was_removed
author_address = AuthorAddress.first
author = author_address.author
author.author_address_id = nil
assert author.save
author.destroy
assert AuthorAddress.find(author_address.id)
assert_raise(ActiveRecord::RecordNotFound) { Author.find(author.id) }
end
def test_does_not_delete_association_if_it_was_removed_on_has_many
firm = Firm.first
client = firm.clients.build :name => "Dharma Initiative"
assert client.save
client.firm_id = nil
assert client.save
assert Firm.find(firm.id)
same_client = Client.find(client.id)
assert_nil same_client.firm
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment