Skip to content
  • Aaron Patterson's avatar
    8f37ba81
    This test does not test anything that happens in the real world. If you · 8f37ba81
    Aaron Patterson authored
    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.
    8f37ba81
    This test does not test anything that happens in the real world. If you
    Aaron Patterson authored
    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.
Loading