aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2016-11-22 13:49:09 +0100
committerGitHub <noreply@github.com>2016-11-22 13:49:09 +0100
commit44087d88325be9e7b2e532b16c615e8be4eef13e (patch)
tree82bdbe113138eb08dfe3ab7e72ef5f353ef8e7ae /activerecord/test/cases
parentb89ddd421feed0a8dc45fb6a9a26dde34e3b7b9e (diff)
parent0e9957135d9057f91fe30af01d4a70e30ee8a6b3 (diff)
downloadrails-44087d88325be9e7b2e532b16c615e8be4eef13e.tar.gz
rails-44087d88325be9e7b2e532b16c615e8be4eef13e.tar.bz2
rails-44087d88325be9e7b2e532b16c615e8be4eef13e.zip
Merge pull request #27133 from rails/reload_singular_associations
Introduce `reload_<association>` reader for singular associations.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb10
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb10
2 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 6b7e4fee56..72f1b3b125 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -291,6 +291,16 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert client.account.new_record?
end
+ def test_reloading_the_belonging_object
+ odegy_account = accounts(:odegy_account)
+
+ assert_equal "Odegy", odegy_account.firm.name
+ Company.where(id: odegy_account.firm_id).update_all(name: "ODEGY")
+ assert_equal "Odegy", odegy_account.firm.name
+
+ assert_equal "ODEGY", odegy_account.reload_firm.name
+ end
+
def test_natural_assignment_to_nil
client = Client.find(3)
client.firm = nil
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