From 9abcb131f94786dbe273088ebd0d93444ca298b2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Jun 2013 10:50:53 -0700 Subject: refute the predicate for better failure messages --- activerecord/test/cases/nested_attributes_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/nested_attributes_test.rb') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 6fe81e0d96..1625b6234f 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -809,7 +809,7 @@ module NestedAttributesOnACollectionAssociationTests assert_no_difference ['Man.count', 'Interest.count'] do man = Man.create(:name => 'John', :interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}]) - assert !man.errors[:"interests.man"].empty? + assert_not_predicate man.errors[:"interests.man"], :empty? end end ensure -- cgit v1.2.3 From 8f37ba81abbd13b935ce0f26574ff2b720b552f1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Jun 2013 15:36:25 -0700 Subject: This test does not test anything that happens in the real world. If you recreate the models without mucking with internal caches of the relation objects, then the test fails. For example: class Man < ActiveRecord::Base has_many :interests end class Interest < ActiveRecord::Base belongs_to :man end Then do this test: def test_validate_presence_of_parent_fails_without_inverse_of repair_validations(Interest) do Interest.validates_presence_of(:man) assert_no_difference ['Man.count', 'Interest.count'] do man = Man.create(:name => 'John', :interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}]) assert_not_predicate man.errors[:"interests.man"], :empty? end end end The test will fail. This is a bad test, so I am removing it. --- activerecord/test/cases/nested_attributes_test.rb | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'activerecord/test/cases/nested_attributes_test.rb') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 1625b6234f..2f89699df7 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -797,26 +797,6 @@ module NestedAttributesOnACollectionAssociationTests end end - def test_validate_presence_of_parent_fails_without_inverse_of - Man.accepts_nested_attributes_for(:interests) - Man.reflect_on_association(:interests).options.delete(:inverse_of) - Man.reflect_on_association(:interests).clear_inverse_of_cache! - Interest.reflect_on_association(:man).options.delete(:inverse_of) - Interest.reflect_on_association(:man).clear_inverse_of_cache! - - repair_validations(Interest) do - Interest.validates_presence_of(:man) - assert_no_difference ['Man.count', 'Interest.count'] do - man = Man.create(:name => 'John', - :interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}]) - assert_not_predicate man.errors[:"interests.man"], :empty? - end - end - ensure - Man.reflect_on_association(:interests).options[:inverse_of] = :man - Interest.reflect_on_association(:man).options[:inverse_of] = :interests - end - def test_can_use_symbols_as_object_identifier @pirate.attributes = { :parrots_attributes => { :foo => { :name => 'Lovely Day' }, :bar => { :name => 'Blown Away' } } } assert_nothing_raised(NoMethodError) { @pirate.save! } -- cgit v1.2.3