diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-06-25 18:07:06 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-06-25 18:07:06 +0200 |
commit | 27b38838467cf47f83caefbddcdb96aceca052ee (patch) | |
tree | 482bd8d1674bf561de15e0e361144cddcb6c121a /activerecord/test/cases/associations/has_many_associations_test.rb | |
parent | b0c65978ab0eff0eca8ac374046c26398f144a18 (diff) | |
download | rails-27b38838467cf47f83caefbddcdb96aceca052ee.tar.gz rails-27b38838467cf47f83caefbddcdb96aceca052ee.tar.bz2 rails-27b38838467cf47f83caefbddcdb96aceca052ee.zip |
Revert "Revert "Merge pull request #10901 from armstrjare/fix_query_null_foreign_key_on_new_record_collection_ids_reader""
This reverts commit 5009b078875e596a2fba7827336f7548aa6e35ac.
Also updated the CHANGELOG and adjusted the test-case to match the one on master.
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-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..d94f5d3207 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! + Contract.create! # another contract + 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 |