Skip to content

Commit

Permalink
Don't raise when attributes are nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens committed Jun 27, 2009
1 parent c11c118 commit 17b847d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/delocalize/rails_ext/active_record.rb
Expand Up @@ -29,7 +29,7 @@ def self.define_write_method_for_time_zone_conversion(attr_name)
method_body = <<-EOV
def #{attr_name}=(time)
unless time.acts_like?(:time)
time = time.is_a?(String) ? Time.zone.parse_localized(time) : time.to_time
time = time.is_a?(String) ? Time.zone.parse_localized(time) : time.to_time rescue time
end
time = time.in_time_zone rescue nil if time
write_attribute(:#{attr_name}, time)
Expand Down
8 changes: 8 additions & 0 deletions test/delocalize_test.rb
Expand Up @@ -71,6 +71,14 @@ def setup
assert_nil @product.released_on
end

test "doesn't raise when attribute is nil" do
assert_nothing_raised {
@product.price = nil
@product.released_on = nil
@product.published_at = nil
@product.cant_think_of_a_sensible_time_field = nil
}
end
end

class DelocalizeActionViewTest < ActionView::TestCase
Expand Down

0 comments on commit 17b847d

Please sign in to comment.