diff options
author | Jared Armstrong <jared.armstrong@gmail.com> | 2013-06-10 15:45:58 +1200 |
---|---|---|
committer | Jared Armstrong <jared.armstrong@gmail.com> | 2013-06-21 13:03:54 +1200 |
commit | c2377f72d2c7df1103eac73b0eb3781c02ef2e18 (patch) | |
tree | a752e2d1c313d2c797e85b4408d62db5e5031a91 /activerecord/test/cases | |
parent | f42e0fd3f4d3e2f4b806b001b6ed88c8da8cd833 (diff) | |
download | rails-c2377f72d2c7df1103eac73b0eb3781c02ef2e18.tar.gz rails-c2377f72d2c7df1103eac73b0eb3781c02ef2e18.tar.bz2 rails-c2377f72d2c7df1103eac73b0eb3781c02ef2e18.zip |
Fixes CollectionAssociation#ids_reader returning incorrect ids for new records
Diffstat (limited to 'activerecord/test/cases')
-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 a75d064ac0..55b57bc2f2 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1311,6 +1311,33 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert !company.clients.loaded? 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_get_ids_ignores_include_option assert_equal [readers(:michael_welcome).id], posts(:welcome).readers_with_person_ids end |