From 5da13d60508f0ebacb3ba5afd3d29eb00c7ca59e Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Wed, 29 Oct 2014 01:28:52 +0900 Subject: Skip to_time if the value is a Time instance This skips calling `#to_time` if the value is a instance of subclass of `Time`, like `ActiveSupport::TimeWithZone`. --- test/workbook/worksheet/tc_cell.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/workbook') diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index f9761330..5ae2a51f 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -119,6 +119,19 @@ class TestCell < Test::Unit::TestCase assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24")) end + def test_cast_time_subclass + subtime = Class.new(Time) do + def to_time + raise "#to_time of Time subclass should not be called" + end + end + + time = subtime.now + + @c.type = :time + assert_equal(time, @c.send(:cast_value, time)) + end + def test_color assert_raise(ArgumentError) { @c.color = -1.1 } assert_nothing_raised { @c.color = "FF00FF00" } -- cgit v1.2.3