提交 55cfbd48 编写于 作者: J José Valim

Merge pull request #519 from knapo/master

`guard_protected_attributes` has invalid assignment to be always true in attributes=
......@@ -1652,11 +1652,10 @@ def attributes=(new_attributes, guard_protected_attributes = nil)
return unless new_attributes.is_a?(Hash)
guard_protected_attributes ||= true
if guard_protected_attributes
assign_attributes(new_attributes)
else
if guard_protected_attributes == false
assign_attributes(new_attributes, :without_protection => true)
else
assign_attributes(new_attributes)
end
end
......
......@@ -45,6 +45,10 @@ class ReadonlyTitlePost < Post
attr_readonly :title
end
class ProtectedTitlePost < Post
attr_protected :title
end
class Weird < ActiveRecord::Base; end
class Boolean < ActiveRecord::Base; end
......@@ -491,8 +495,9 @@ def test_non_valid_identifier_column_name
def test_attributes_guard_protected_attributes_is_deprecated
attributes = { "title" => "An amazing title" }
topic = Topic.new
assert_deprecated { topic.send(:attributes=, attributes, false) }
post = ProtectedTitlePost.new
assert_deprecated { post.send(:attributes=, attributes, false) }
assert_equal "An amazing title", post.title
end
def test_multiparameter_attributes_on_date
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册