mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
avoid nil.dup
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
committed by
Santiago Pastorino
parent
1fd9d978a7
commit
40aefb9301
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user