Permalink
Browse files

avoid nil.dup

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 73b9e43 commit 6e04f58f0e8886b500cfc7b6542b3381a9dff17a @amatsuda amatsuda committed with Santiago Pastorino and Emilio Tagua Feb 6, 2011
@@ -38,7 +38,7 @@ def define_method_attribute=(attr_name)
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
@@ -459,6 +459,14 @@ def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_els
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)

0 comments on commit 6e04f58

Please sign in to comment.