diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-11 09:02:22 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-11 09:02:22 -0700 |
commit | 55cfbd4809e17bf8e5bb057021b4be7f08648138 (patch) | |
tree | 6f0ac7821c1955e6c6e06ab3ce439ee8b29ec3cd | |
parent | 8ec1f30cfdea6c80db1434a9f96c28bb119689d0 (diff) | |
parent | bb498a574980eb281f9f5fd5236f584bf23a829d (diff) | |
download | rails-55cfbd4809e17bf8e5bb057021b4be7f08648138.tar.gz rails-55cfbd4809e17bf8e5bb057021b4be7f08648138.tar.bz2 rails-55cfbd4809e17bf8e5bb057021b4be7f08648138.zip |
Merge pull request #519 from knapo/master
`guard_protected_attributes` has invalid assignment to be always true in attributes=
-rw-r--r-- | activerecord/lib/active_record/base.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index b2e058d746..e1bf2ccc8a 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1652,11 +1652,10 @@ MSG 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 diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index fb4eacb632..9bc04ed29c 100644 --- a/activerecord/test/cases/base_test.rb +++ b/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 @@ class BasicsTest < ActiveRecord::TestCase 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 |