Commit
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,13 @@ def #{attr_name}(reload = false) | |
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}=(time) | ||
def #{attr_name}=(original_time) | ||
time = original_time.dup | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
amatsuda
Author
Member
|
||
unless time.acts_like?(:time) | ||
time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time | ||
end | ||
time = time.in_time_zone rescue nil if time | ||
write_attribute(:#{attr_name}, time) | ||
write_attribute(:#{attr_name}, (time || original_time)) | ||
end | ||
EOV | ||
generated_attribute_methods.module_eval(method_body, __FILE__, line) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,20 +119,16 @@ def test_read_attributes_before_type_cast_on_boolean | |
unless current_adapter?(:Mysql2Adapter) | ||
def test_read_attributes_before_type_cast_on_datetime | ||
developer = Developer.find(:first) | ||
# Oracle adapter returns Time before type cast | ||
unless current_adapter?(:OracleAdapter) | ||
assert_equal developer.created_at.to_s(:db) , developer.attributes_before_type_cast["created_at"] | ||
else | ||
assert_equal developer.created_at.to_s(:db) , developer.attributes_before_type_cast["created_at"].to_s(:db) | ||
assert_equal developer.created_at.to_s(:db), developer.attributes_before_type_cast["created_at"].to_s | ||
|
||
developer.created_at = "345643456" | ||
assert_equal developer.created_at_before_type_cast, "345643456" | ||
assert_equal developer.created_at, nil | ||
developer.created_at = "345643456" | ||
|
||
developer.created_at = "2010-03-21 21:23:32" | ||
assert_equal developer.created_at_before_type_cast, "2010-03-21 21:23:32" | ||
assert_equal developer.created_at, Time.parse("2010-03-21 21:23:32") | ||
end | ||
assert_equal developer.created_at_before_type_cast, "345643456" | ||
assert_equal developer.created_at, nil | ||
|
||
developer.created_at = "2010-03-21 21:23:32" | ||
assert_equal developer.created_at_before_type_cast.to_s, "2010-03-21 21:23:32" | ||
This comment has been minimized.
Sorry, something went wrong.
adzap
Contributor
|
||
assert_equal developer.created_at, Time.parse("2010-03-21 21:23:32") | ||
end | ||
end | ||
|
||
|
1 comment
on commit c8b7606
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see this ticket for patches to fix this code and why the tests are broken.
original_time.dup
gets called even if original_time is nil, resulting in an exception (can't dup NilClass). Anunless original_time.nil?
would help.