From fed6ac9c66e87d120098b3a4ffb15699d0ee6863 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 26 Sep 2013 14:55:10 -0400 Subject: fix inverse_of when find_or_initialize_by_* inverse_of relation was not being set when calling find_or_initialize_by_ and the entry was found on the db. --- .../test/cases/associations/has_many_associations_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index eec78f95c5..53cce33698 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -662,6 +662,17 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end end + def test_inverse_after_find_or_initialize + firm = companies(:first_firm) + client = firm.clients_of_firm.find_or_initialize_by_client_of(firm.id) + assert_no_queries do + assert_equal firm, client.firm + end + + firm.name = "A new firm" + assert_equal firm.name, client.firm.name + end + def test_new_aliased_to_build company = companies(:first_firm) new_client = assert_no_queries { company.clients_of_firm.new("name" => "Another Client") } -- cgit v1.2.3