File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed
lib/active_record/associations Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
## Rails 4.0.0 (unreleased) ##
2
2
3
+ * Prevent mass assignment to the type column of polymorphic associations when using ` build `
4
+ Fix #8265
5
+
6
+ * Yves Senn*
7
+
3
8
* Fix postgresql adapter to handle BC timestamps correctly
4
9
5
10
HistoryEvent.create!(:name => "something", :occured_at => Date.new(0) - 5.years)
Original file line number Diff line number Diff line change @@ -232,7 +232,8 @@ def stale_state
232
232
233
233
def build_record ( attributes )
234
234
reflection . build_association ( attributes ) do |record |
235
- attributes = create_scope . except ( *( record . changed - [ reflection . foreign_key ] ) )
235
+ skip_assign = [ reflection . foreign_key , reflection . type ] . compact
236
+ attributes = create_scope . except ( *( record . changed - skip_assign ) )
236
237
record . assign_attributes ( attributes )
237
238
end
238
239
end
Original file line number Diff line number Diff line change @@ -1579,6 +1579,14 @@ def test_abstract_class_with_polymorphic_has_many
1579
1579
assert_equal [ tagging ] , post . taggings
1580
1580
end
1581
1581
1582
+ def test_build_with_polymotphic_has_many_does_not_allow_to_override_type_and_id
1583
+ welcome = posts ( :welcome )
1584
+ tagging = welcome . taggings . build ( :taggable_id => 99 , :taggable_type => 'ShouldNotChange' )
1585
+
1586
+ assert_equal welcome . id , tagging . taggable_id
1587
+ assert_equal 'Post' , tagging . taggable_type
1588
+ end
1589
+
1582
1590
def test_dont_call_save_callbacks_twice_on_has_many
1583
1591
firm = companies ( :first_firm )
1584
1592
contract = firm . contracts . create!
You can’t perform that action at this time.
0 commit comments