From e614be2d803f9dceae3c4192a7b9f75834dab3ea Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 28 Jun 2017 21:17:06 +0900 Subject: Use `reload` in `test_find_first_after_reload` And use `assert_same` instead of `assert_equal` and tiny fix assert message s/#reload/#reset/. Follow up of #29511. --- .../cases/associations/has_many_associations_test.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 169e1a5449..b02653bbcc 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -745,35 +745,35 @@ class HasManyAssociationsTest < ActiveRecord::TestCase firm = Firm.all.merge!(order: "id").first collection = firm.clients - original_object_id = collection.first.object_id - assert_equal original_object_id, collection.first.object_id, "Expected second call to #first to cache the same object" + original_object = collection.first + assert_same original_object, collection.first, "Expected second call to #first to cache the same object" # It should return a different object, since the association has been reloaded - assert_not_equal original_object_id, firm.clients.first.object_id, "Expected #first to return a new object" + assert_not_same original_object, firm.clients.first, "Expected #first to return a new object" end def test_find_first_after_reset firm = Firm.all.merge!(order: "id").first collection = firm.clients - original_object_id = collection.first.object_id - assert_equal original_object_id, collection.first.object_id, "Expected second call to #first to cache the same object" + original_object = collection.first + assert_same original_object, collection.first, "Expected second call to #first to cache the same object" collection.reset # It should return a different object, since the association has been reloaded - assert_not_equal original_object_id, collection.first.object_id, "Expected #first after #reload to return a new object" + assert_not_same original_object, collection.first, "Expected #first after #reset to return a new object" end def test_find_first_after_reload firm = Firm.all.merge!(order: "id").first collection = firm.clients - original_object_id = collection.first.object_id - assert_equal original_object_id, collection.first.object_id, "Expected second call to #first to cache the same object" - collection.reset + original_object = collection.first + assert_same original_object, collection.first, "Expected second call to #first to cache the same object" + collection.reload # It should return a different object, since the association has been reloaded - assert_not_equal original_object_id, collection.first.object_id, "Expected #first after #reload to return a new object" + assert_not_same original_object, collection.first, "Expected #first after #reload to return a new object" end def test_find_all_with_include_and_conditions -- cgit v1.2.3