diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 9 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 6771e3e9c9..dbcf50a08b 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed Base#write_attribute to work with both symbols and strings #1190 [Paul Legato] + * Fixed that has_and_belongs_to_many didn't respect single table inheritance types #1081 [Florian Weber] * Speed up ActiveRecord#method_missing for the common case (read_attribute). diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 697e7a0c41..183aae280f 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1241,7 +1241,7 @@ module ActiveRecord #:nodoc: # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+. Empty strings for fixnum and float # columns are turned into nil. def write_attribute(attr_name, value) - @attributes[attr_name] = empty_string_for_number_column?(attr_name, value) ? nil : value + @attributes[attr_name.to_s] = empty_string_for_number_column?(attr_name.to_s, value) ? nil : value end def empty_string_for_number_column?(attr_name, value) diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 74e03097aa..0adcb3baa4 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -170,6 +170,15 @@ class BasicsTest < Test::Unit::TestCase topicReloaded.send :write_attribute, 'does_not_exist', 'test' assert_nothing_raised { topicReloaded.save } end + + def test_write_attribute + topic = Topic.new + topic.send(:write_attribute, :title, "Still another topic") + assert_equal "Still another topic", topic.title + + topic.send(:write_attribute, "title", "Still another topic: part 2") + assert_equal "Still another topic: part 2", topic.title + end def test_preserving_date_objects # SQL Server doesn't have a separate column type just for dates, so all are returned as time |