From a33007d31a539ef5365ee13455f386c4e0b658fe Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 28 Nov 2007 20:12:49 +0000 Subject: [PATCH] attr_readonly uses a set of strings instead of an array of symbols internally. References #10300. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8230 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 4 ++-- activerecord/test/base_test.rb | 2 +- activerecord/test/locking_test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 991d8b040c..eea83ecbbf 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -672,7 +672,7 @@ def accessible_attributes # :nodoc: # Attributes listed as readonly can be set for a new record, but will be ignored in database updates afterwards. def attr_readonly(*attributes) - write_inheritable_array("attr_readonly", attributes - (readonly_attributes || [])) + write_inheritable_attribute("attr_readonly", Set.new(attributes.map(&:to_s)) + (readonly_attributes || [])) end # Returns an array of all the attributes that have been specified as readonly. @@ -2103,7 +2103,7 @@ def remove_attributes_protected_from_mass_assignment(attributes) # Removes attributes which have been marked as readonly. def remove_readonly_attributes(attributes) unless self.class.readonly_attributes.nil? - attributes.delete_if { |key, value| self.class.readonly_attributes.include?(key.gsub(/\(.+/,"").intern) } + attributes.delete_if { |key, value| self.class.readonly_attributes.include?(key.gsub(/\(.+/,"")) } else attributes end diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index a95ee7cd8a..6fac80b2c4 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -856,7 +856,7 @@ def test_mass_assignment_protection_inheritance end def test_readonly_attributes - assert_equal [ :title ], ReadonlyTitlePost.readonly_attributes + assert_equal Set.new([ 'title' ]), ReadonlyTitlePost.readonly_attributes post = ReadonlyTitlePost.create(:title => "cannot change this", :body => "changeable") post.reload diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb index b0d6f8417f..97fbfaaeb1 100644 --- a/activerecord/test/locking_test.rb +++ b/activerecord/test/locking_test.rb @@ -99,7 +99,7 @@ def test_lock_with_custom_column_without_default_sets_version_to_zero end def test_readonly_attributes - assert_equal [ :first_name ], ReadonlyFirstNamePerson.readonly_attributes + assert_equal Set.new([ 'first_name' ]), ReadonlyFirstNamePerson.readonly_attributes p = ReadonlyFirstNamePerson.create(:first_name => "unchangeable name") p.reload -- GitLab