Skip to content
Browse files

Modify read_attribute to allow a symbol argument #2024 [Ken Kunz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2096 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 46c4fd4 commit 69d662051e609f8fc3e28d2c77a917cd0befddca @jamis jamis committed Sep 2, 2005
Showing with 15 additions and 2 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +3 −2 activerecord/lib/active_record/base.rb
  3. +10 −0 activerecord/test/base_test.rb
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Modify read_attribute to allow a symbol argument #2024 [Ken Kunz]
+
* Make destroy return self #1913 [sebastian.kanthak@muehlheim.de]
* Fix typo in validations documentation #1938 [court3nay]
View
5 activerecord/lib/active_record/base.rb
@@ -1108,13 +1108,13 @@ def reload
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
# (Alias for the protected read_attribute method).
def [](attr_name)
- read_attribute(attr_name.to_s)
+ read_attribute(attr_name)
end
# Updates the attribute identified by <tt>attr_name</tt> with the specified +value+.
# (Alias for the protected write_attribute method).
def []=(attr_name, value)
- write_attribute(attr_name.to_s, value)
+ write_attribute(attr_name, value)
end
# Allows you to set all the attributes at once by passing in a hash with keys
@@ -1267,6 +1267,7 @@ def method_missing(method_id, *args, &block)
# Returns the value of attribute identified by <tt>attr_name</tt> after it has been type cast (for example,
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
+ attr_name = attr_name.to_s
if !(value = @attributes[attr_name]).nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
View
10 activerecord/test/base_test.rb
@@ -180,6 +180,16 @@ def test_write_attribute
assert_equal "Still another topic: part 2", topic.title
end
+ def test_read_attribute
+ topic = Topic.new
+ topic.title = "Don't change the topic"
+ assert_equal "Don't change the topic", topic.send(:read_attribute, "title")
+ assert_equal "Don't change the topic", topic["title"]
+
+ assert_equal "Don't change the topic", topic.send(:read_attribute, :title)
+ assert_equal "Don't change the topic", topic[:title]
+ end
+
def test_read_attribute_when_false
topic = topics(:first)
topic.approved = false

0 comments on commit 69d6620

Please sign in to comment.
Something went wrong with that request. Please try again.