mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
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
This commit is contained in:
@@ -672,7 +672,7 @@ module ActiveRecord #: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 @@ module ActiveRecord #:nodoc:
|
||||
# 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
|
||||
|
||||
@@ -856,7 +856,7 @@ class BasicsTest < Test::Unit::TestCase
|
||||
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
|
||||
|
||||
@@ -99,7 +99,7 @@ class OptimisticLockingTest < Test::Unit::TestCase
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user