aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_one_associations_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2016-11-21 17:19:23 +0100
committerYves Senn <yves.senn@gmail.com>2016-11-22 12:37:42 +0100
commit0e9957135d9057f91fe30af01d4a70e30ee8a6b3 (patch)
tree82bdbe113138eb08dfe3ab7e72ef5f353ef8e7ae /activerecord/test/cases/associations/has_one_associations_test.rb
parentb89ddd421feed0a8dc45fb6a9a26dde34e3b7b9e (diff)
downloadrails-0e9957135d9057f91fe30af01d4a70e30ee8a6b3.tar.gz
rails-0e9957135d9057f91fe30af01d4a70e30ee8a6b3.tar.bz2
rails-0e9957135d9057f91fe30af01d4a70e30ee8a6b3.zip
Introduce `reload_<association>` reader for singular associations.
This patch brings back the functionality of passing true to the association proxy. The behavior was deprecated with #20888 and scheduled for removal in Rails 5.1. The deprecation mentioned that instead of `Article.category(true)` one should use `article#reload.category`. Unfortunately the alternative does not expose the same behavior as passing true to the reader did. Specifically reloading the parent record throws unsaved changes and other caches away. Passing true only affected the association. This is problematic and there is no easy workaround. I propose to bring back the old functionality by introducing this new reader method for singular associations.
Diffstat (limited to 'activerecord/test/cases/associations/has_one_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index 862f33a1a0..48fbc5990c 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -326,6 +326,16 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_reload_association
+ odegy = companies(:odegy)
+
+ assert_equal 53, odegy.account.credit_limit
+ Account.where(id: odegy.account.id).update_all(credit_limit: 80)
+ assert_equal 53, odegy.account.credit_limit
+
+ assert_equal 80, odegy.reload_account.credit_limit
+ end
+
def test_build
firm = Firm.new("name" => "GlobalMegaCorp")
firm.save