diff options
author | Jon Rowe <hello@jonrowe.co.uk> | 2013-03-24 12:32:11 +1300 |
---|---|---|
committer | Jon Rowe <hello@jonrowe.co.uk> | 2013-03-24 12:32:11 +1300 |
commit | 0c96169f590b1b5ca9c180b033e7899e322a0f99 (patch) | |
tree | 5d0141564eb86ba784ca3ff1d3ecc454828e22d0 /activerecord/test | |
parent | 69599b63de927091faf1d804b6457f65014080d6 (diff) | |
download | rails-0c96169f590b1b5ca9c180b033e7899e322a0f99.tar.gz rails-0c96169f590b1b5ca9c180b033e7899e322a0f99.tar.bz2 rails-0c96169f590b1b5ca9c180b033e7899e322a0f99.zip |
test case to assert that associations do not overwrite after create, fixes #9310
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index e6b881389b..bba1b2b66d 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -341,6 +341,19 @@ class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::Test assert_equal num_tagging + 1, Tagging.count end + def test_association_is_not_overwitten_on_autosave + firm_1 = Firm.create!(name: 'Apple') + firm_2 = Firm.create!(name: 'Microsoft') + client = Client.create!(firm: firm_1, name: 'Business') + assert_equal firm_1.id, client.client_of + + client.client_of = firm_2.id + assert client.save + + client.reload + assert_equal firm_2, client.firm + end + def test_build_and_then_save_parent_should_not_reload_target client = Client.find(:first) apple = client.build_firm(:name => "Apple") |