Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #519 from knapo/master

`guard_protected_attributes` has invalid assignment to be always true in attributes=
  • Loading branch information...
commit 55cfbd4809e17bf8e5bb057021b4be7f08648138 2 parents 8ec1f30 + bb498a5
@josevalim josevalim authored
View
7 activerecord/lib/active_record/base.rb
@@ -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
View
9 activerecord/test/cases/base_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.