Permalink
Browse files

Use indifferent access attributes instead of stringifying them

  • Loading branch information...
1 parent e212799 commit a69316b293e26031de4fcabc481331180608098a @lifo lifo committed Oct 7, 2009
@@ -270,7 +270,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)
@@ -323,7 +323,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)
@@ -85,6 +85,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

0 comments on commit a69316b

Please sign in to comment.