diff options
author | Jared Armstrong <jared.armstrong@gmail.com> | 2013-06-24 08:52:08 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-06-24 08:52:08 +0200 |
commit | f6cdc2282ff4a34e4d0230b80d945f9c898d6973 (patch) | |
tree | e96a68e621d9087d05968e55373ddb0a91ab14a5 | |
parent | c0714a969d85ca8ffb2371c34e770ea1b61eb2ec (diff) | |
download | rails-f6cdc2282ff4a34e4d0230b80d945f9c898d6973.tar.gz rails-f6cdc2282ff4a34e4d0230b80d945f9c898d6973.tar.bz2 rails-f6cdc2282ff4a34e4d0230b80d945f9c898d6973.zip |
test-case to prevent regressions described in #10901.
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index d3704474a3..acb92bdbd0 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1336,6 +1336,33 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [companies(:second_client).id, companies(:first_client).id], companies(:first_firm).clients_ordered_by_name_ids end + def test_get_ids_for_association_on_new_record_does_not_try_to_find_records + Company.columns # Load schema information so we don't query below + Contract.columns # if running just this test. + + company = Company.new + assert_queries(0) do + company.contract_ids + end + + assert_equal [], company.contract_ids + end + + def test_set_ids_for_association_on_new_record_applies_association_correctly + contract_a = Contract.create! + contract_b = Contract.create! + another_contract = Contract.create! + company = Company.new(:name => "Some Company") + + company.contract_ids = [contract_a.id, contract_b.id] + assert_equal [contract_a.id, contract_b.id], company.contract_ids + assert_equal [contract_a, contract_b], company.contracts + + company.save! + assert_equal company, contract_a.reload.company + assert_equal company, contract_b.reload.company + end + def test_assign_ids_ignoring_blanks firm = Firm.create!(:name => 'Apple') firm.client_ids = [companies(:first_client).id, nil, companies(:second_client).id, ''] |