提交 40aefb93 编写于 作者: A Akira Matsuda 提交者: Santiago Pastorino

avoid nil.dup

Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 1fd9d978
......@@ -41,7 +41,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
......
......@@ -460,6 +460,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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册