diff options
author | Akira Matsuda <ronnie@dio.jp> | 2011-02-07 08:29:06 +0900 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-02-07 09:51:51 -0200 |
commit | 40aefb93018277ee7cafc5529b16d7b6df8aa4dd (patch) | |
tree | 9f918509c468a7aff1822aae4fa39e3bfaa511d6 /activerecord | |
parent | 1fd9d978a737d36cf7cca698f0fcbfc6fcdbed98 (diff) | |
download | rails-40aefb93018277ee7cafc5529b16d7b6df8aa4dd.tar.gz rails-40aefb93018277ee7cafc5529b16d7b6df8aa4dd.tar.bz2 rails-40aefb93018277ee7cafc5529b16d7b6df8aa4dd.zip |
avoid nil.dup
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index a72eecb50e..76218d2a73 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -41,7 +41,7 @@ module ActiveRecord if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name]) method_body, line = <<-EOV, __LINE__ + 1 def #{attr_name}=(original_time) - time = original_time.dup + time = original_time.dup unless original_time.nil? unless time.acts_like?(:time) time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time end diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 7e3e204626..c343dd7918 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -460,6 +460,14 @@ class AttributeMethodsTest < ActiveRecord::TestCase end end + def test_write_nil_to_time_attributes + in_time_zone "Pacific Time (US & Canada)" do + record = @target.new + record.written_on = nil + assert_nil record.written_on + end + end + def test_time_attributes_are_retrieved_in_current_time_zone in_time_zone "Pacific Time (US & Canada)" do utc_time = Time.utc(2008, 1, 1) |