Skip to content

Commit

Permalink
avoid nil.dup
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
amatsuda authored and Santiago Pastorino and Emilio Tagua committed Feb 12, 2011
1 parent 73b9e43 commit 6e04f58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/attribute_methods_test.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 6e04f58

Please sign in to comment.