Skip to content
Browse files

Merge pull request #10567 from neerajdotname/read_attribute_before_ty…

…pe_cast_should_accept_symbol

read_attribute_before_type_cast should accept symbol
  • Loading branch information...
2 parents 0215faf + 3e0c06d commit 51157c9b46cb200b45554700dae3b4026f268b7f @rafaelfranca rafaelfranca committed May 11, 2013
View
4 activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Method read_attribute_before_type_cast should accept input as symbol.
+
+ *Neeraj Singh*
+
* Confirm a record has not already been destroyed before decrementing counter cache.
*Ben Tucker*
View
3 activerecord/lib/active_record/attribute_methods/before_type_cast.rb
@@ -41,8 +41,9 @@ module BeforeTypeCast
# task.read_attribute_before_type_cast('id') # => '1'
# task.read_attribute('completed_on') # => Sun, 21 Oct 2012
# task.read_attribute_before_type_cast('completed_on') # => "2012-10-21"
+ # task.read_attribute_before_type_cast(:completed_on) # => "2012-10-21"
def read_attribute_before_type_cast(attr_name)
- @attributes[attr_name]
+ @attributes[attr_name.to_s]
end
# Returns a hash of attributes before typecasting and deserialization.
View
1 activerecord/test/cases/attribute_methods_test.rb
@@ -130,6 +130,7 @@ def test_id_before_type_cast_with_custom_primary_key
assert_equal '10', keyboard.id_before_type_cast
assert_equal nil, keyboard.read_attribute_before_type_cast('id')
assert_equal '10', keyboard.read_attribute_before_type_cast('key_number')
+ assert_equal '10', keyboard.read_attribute_before_type_cast(:key_number)
end
# Syck calls respond_to? before actually calling initialize

0 comments on commit 51157c9

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