Don't alter the Hash passed to attributes=, closes #3385
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3417 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
f9e0ba2913
commit
f41feb349c
@ -1334,8 +1334,9 @@ def []=(attr_name, value)
|
||||
# from this form of mass-assignment by using the +attr_protected+ macro. Or you can alternatively
|
||||
# specify which attributes *can* be accessed in with the +attr_accessible+ macro. Then all the
|
||||
# attributes not included in that won't be allowed to be mass-assigned.
|
||||
def attributes=(attributes)
|
||||
return if attributes.nil?
|
||||
def attributes=(attrs)
|
||||
return if attrs.nil?
|
||||
attributes= attrs.dup
|
||||
attributes.stringify_keys!
|
||||
|
||||
multi_parameter_attributes = []
|
||||
|
@ -133,8 +133,19 @@ def test_create
|
||||
topic = Topic.new
|
||||
topic.title = "New Topic"
|
||||
topic.save
|
||||
topicReloaded = Topic.find(topic.id)
|
||||
assert_equal("New Topic", topicReloaded.title)
|
||||
topic_reloaded = Topic.find(topic.id)
|
||||
assert_equal("New Topic", topic_reloaded.title)
|
||||
end
|
||||
|
||||
def test_hashes_not_mangled
|
||||
new_topic = { :title => "New Topic" }
|
||||
new_topic_values = { :title => "AnotherTopic" }
|
||||
|
||||
topic = Topic.new(new_topic)
|
||||
assert_equal new_topic[:title], topic.title
|
||||
|
||||
topic.attributes= new_topic_values
|
||||
assert_equal new_topic_value[:title], topic.title
|
||||
end
|
||||
|
||||
def test_create_many
|
||||
|
Loading…
Reference in New Issue
Block a user