Skip to content

Commit

Permalink
Add regression test for setting inverse instances on normal & polymor…
Browse files Browse the repository at this point in the history
…phic relationships when building objects on new records
  • Loading branch information
fschwahn committed Apr 20, 2017
1 parent dc47c2b commit c212058
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions activerecord/test/cases/associations/has_many_associations_test.rb
Expand Up @@ -241,6 +241,13 @@ def test_create_from_association_with_nil_values_should_work
assert_equal "defaulty", bulb.name
end

def test_build_from_association_sets_inverse_instance
car = Car.new(name: "honda")

bulb = car.bulbs.build
assert_equal car, bulb.car
end

def test_do_not_call_callbacks_for_delete_all
car = Car.create(name: "honda")
car.funky_bulbs.create!
Expand Down Expand Up @@ -2146,6 +2153,13 @@ def test_build_with_polymorphic_has_many_does_not_allow_to_override_type_and_id
assert_equal "Post", tagging.taggable_type
end

def test_build_from_polymorphic_association_sets_inverse_instance
post = Post.new
tagging = post.taggings.build

assert_equal post, tagging.taggable
end

def test_dont_call_save_callbacks_twice_on_has_many
firm = companies(:first_firm)
contract = firm.contracts.create!
Expand Down

0 comments on commit c212058

Please sign in to comment.