aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-22 06:47:44 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-22 06:47:44 -0800
commit83e71051258b98bd5c4df80b321c7b690ddcab35 (patch)
treec40be8c2333aaba0928e41407e0fd2ac0442809c /activerecord/test/cases/associations/has_many_associations_test.rb
parent4e00e8e91637e117f702ec277a5db1fd087cb347 (diff)
parentd397a38c0268e61295e23f617e9bf70d905ea610 (diff)
downloadrails-83e71051258b98bd5c4df80b321c7b690ddcab35.tar.gz
rails-83e71051258b98bd5c4df80b321c7b690ddcab35.tar.bz2
rails-83e71051258b98bd5c4df80b321c7b690ddcab35.zip
Merge pull request #8295 from senny/8265_backport
backport #8291, prevent mass assignment of polymorphic type with `build`
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 c311bf70d2..b4788e0a3d 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1704,6 +1704,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!