aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@garaio.com>2012-11-21 09:48:48 +0100
committerYves Senn <yves.senn@garaio.com>2012-11-22 08:58:00 +0100
commit053bfa2304517fd2eb4e8e7dcb4eb9897f121271 (patch)
treeb95f4ac2bb19b24eae1dc7abe722146cbfffbdf1 /activerecord/test/cases/associations/has_many_associations_test.rb
parent293c121feeb93544c1f9594bd1bee3ce046301d5 (diff)
downloadrails-053bfa2304517fd2eb4e8e7dcb4eb9897f121271.tar.gz
rails-053bfa2304517fd2eb4e8e7dcb4eb9897f121271.tar.bz2
rails-053bfa2304517fd2eb4e8e7dcb4eb9897f121271.zip
prevent mass assignment of polymorphic type when using `build`
Closes #8265
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 01afa087be..989d08b3e9 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1579,6 +1579,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [tagging], post.taggings
end
+ def test_build_with_polymotphic_has_many_does_not_allow_to_override_type_and_id
+ welcome = posts(:welcome)
+ tagging = welcome.taggings.build(:taggable_id => 99, :taggable_type => 'ShouldNotChange')
+
+ assert_equal welcome.id, tagging.taggable_id
+ assert_equal 'Post', tagging.taggable_type
+ end
+
def test_dont_call_save_callbacks_twice_on_has_many
firm = companies(:first_firm)
contract = firm.contracts.create!