From 56c3d72aa75dd286e35a220f53297e043e799ab2 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Tue, 5 Jul 2005 12:38:06 +0000 Subject: Fix regression from [1631] that caused an attribute to be set to nil if it was assigned false git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1709 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 2 +- activerecord/test/base_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 183aae280f..3b5f9b94db 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1200,7 +1200,7 @@ module ActiveRecord #:nodoc: # Returns the value of attribute identified by attr_name 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) - if value = @attributes[attr_name] + if !(value = @attributes[attr_name]).nil? if column = column_for_attribute(attr_name) if unserializable_attribute?(attr_name, column) unserialize_attribute(attr_name) diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 0adcb3baa4..8b316df190 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -180,6 +180,12 @@ class BasicsTest < Test::Unit::TestCase assert_equal "Still another topic: part 2", topic.title end + def test_read_attribute_when_false + topic = topics(:first) + topic.approved = false + assert_equal 0, topic.approved, "approved should be 0" + end + def test_preserving_date_objects # SQL Server doesn't have a separate column type just for dates, so all are returned as time if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter -- cgit v1.2.3