class InversePolymorphicBelongsToTests
Public Instance Methods
test_inversed_instance_should_not_be_reloaded_after_stale_state_changed()
click to toggle source
# File activerecord/test/cases/associations/inverse_associations_test.rb, line 663 def test_inversed_instance_should_not_be_reloaded_after_stale_state_changed new_man = Man.new face = Face.new new_man.face = face old_inversed_man = face.man new_man.save! new_inversed_man = face.man assert_equal old_inversed_man.object_id, new_inversed_man.object_id end
test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many()
click to toggle source
# File activerecord/test/cases/associations/inverse_associations_test.rb, line 675 def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many i = interests(:llama_wrangling) m = i.polymorphic_man assert_not_nil m.polymorphic_interests iz = m.polymorphic_interests.detect { |_iz| _iz.id == i.id } assert_not_nil iz assert_equal i.topic, iz.topic, "Interest topics should be the same before changes to child" i.topic = "Eating cheese with a spoon" assert_not_equal i.topic, iz.topic, "Interest topics should not be the same after changes to child" iz.topic = "Cow tipping" assert_not_equal i.topic, iz.topic, "Interest topics should not be the same after changes to parent-owned instance" end
test_trying_to_access_inverses_that_dont_exist_shouldnt_raise_an_error()
click to toggle source
# File activerecord/test/cases/associations/inverse_associations_test.rb, line 688 def test_trying_to_access_inverses_that_dont_exist_shouldnt_raise_an_error # Ideally this would, if only for symmetry's sake with other association types assert_nothing_raised { Face.first.horrible_polymorphic_man } end
test_trying_to_set_polymorphic_inverses_that_dont_exist_at_all_should_raise_an_error()
click to toggle source
# File activerecord/test/cases/associations/inverse_associations_test.rb, line 693 def test_trying_to_set_polymorphic_inverses_that_dont_exist_at_all_should_raise_an_error # fails because no class has the correct inverse_of for horrible_polymorphic_man assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.horrible_polymorphic_man = Man.first } end
test_trying_to_set_polymorphic_inverses_that_dont_exist_on_the_instance_being_set_should_raise_an_error()
click to toggle source
# File activerecord/test/cases/associations/inverse_associations_test.rb, line 698 def test_trying_to_set_polymorphic_inverses_that_dont_exist_on_the_instance_being_set_should_raise_an_error # passes because Man does have the correct inverse_of assert_nothing_raised { Face.first.polymorphic_man = Man.first } # fails because Interest does have the correct inverse_of assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.polymorphic_man = Interest.first } end