aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-03-18 11:20:47 +0100
committerYves Senn <yves.senn@gmail.com>2015-03-18 11:20:47 +0100
commit08615a3bcbe57b99881f6f3f5b649ed413b9307b (patch)
tree47e67d2849eed62d520c0deccd24eefbe46f7305 /activerecord/test
parent848680015bca5704bb17be79948ce68d77e71f54 (diff)
parentc82cc222c793275f74fc5e8b6aa88edebe136929 (diff)
downloadrails-08615a3bcbe57b99881f6f3f5b649ed413b9307b.tar.gz
rails-08615a3bcbe57b99881f6f3f5b649ed413b9307b.tar.bz2
rails-08615a3bcbe57b99881f6f3f5b649ed413b9307b.zip
Merge pull request #19348 from Empact/null-scope
Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start. Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
1 files changed, 12 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 675bed9bfa..290b2a0d6b 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -532,9 +532,21 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_update_all_on_association_accessed_before_save
firm = Firm.new(name: 'Firm')
+ clients_proxy_id = firm.clients.object_id
firm.clients << Client.first
firm.save!
assert_equal firm.clients.count, firm.clients.update_all(description: 'Great!')
+ assert_not_equal clients_proxy_id, firm.clients.object_id
+ end
+
+ def test_update_all_on_association_accessed_before_save_with_explicit_foreign_key
+ # We can use the same cached proxy object because the id is available for the scope
+ firm = Firm.new(name: 'Firm', id: 100)
+ clients_proxy_id = firm.clients.object_id
+ firm.clients << Client.first
+ firm.save!
+ assert_equal firm.clients.count, firm.clients.update_all(description: 'Great!')
+ assert_equal clients_proxy_id, firm.clients.object_id
end
def test_belongs_to_sanity