提交 0c27d088 编写于 作者: P Pratik Naik

Use indifferent access attributes instead of stringifying them

上级 c352ec06
......@@ -283,7 +283,7 @@ def _delete #:nodoc:
# <tt>:_destroy</tt> key set to a truthy value, then the existing record
# will be marked for destruction.
def assign_nested_attributes_for_one_to_one_association(association_name, attributes, allow_destroy)
attributes = attributes.stringify_keys
attributes = attributes.with_indifferent_access
if attributes['id'].blank?
unless reject_new_record?(association_name, attributes)
......@@ -336,7 +336,7 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
end
attributes_collection.each do |attributes|
attributes = attributes.stringify_keys
attributes = attributes.with_indifferent_access
if attributes['id'].blank?
unless reject_new_record?(association_name, attributes)
......
......@@ -104,6 +104,14 @@ def test_reject_if_method_with_arguments
pirate.ship_attributes = { :name => 'Red Pearl', :_reject_me_if_new => true }
assert_difference('Ship.count') { pirate.save! }
end
def test_reject_if_with_indifferent_keys
Pirate.accepts_nested_attributes_for :ship, :reject_if => proc {|attributes| attributes[:name].blank? }
pirate = Pirate.new(:catchphrase => "Stop wastin' me time")
pirate.ship_attributes = { :name => 'Hello Pearl' }
assert_difference('Ship.count') { pirate.save! }
end
end
class TestNestedAttributesOnAHasOneAssociation < ActiveRecord::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册