class ActiveModel::Type::DateTimeTest
Public Instance Methods
test_string_to_time_with_timezone()
click to toggle source
# File activemodel/test/cases/type/date_time_test.rb, line 20 def test_string_to_time_with_timezone ["UTC", "US/Eastern"].each do |zone| with_timezone_config default: zone do type = Type::DateTime.new assert_equal ::Time.utc(2013, 9, 4, 0, 0, 0), type.cast("Wed, 04 Sep 2013 03:00:00 EAT") end end end
test_type_cast_datetime_and_timestamp()
click to toggle source
# File activemodel/test/cases/type/date_time_test.rb, line 9 def test_type_cast_datetime_and_timestamp type = Type::DateTime.new assert_nil type.cast(nil) assert_nil type.cast("") assert_nil type.cast(" ") assert_nil type.cast("ABC") datetime_string = ::Time.now.utc.strftime("%FT%T") assert_equal datetime_string, type.cast(datetime_string).strftime("%FT%T") end
Private Instance Methods
with_timezone_config(default:) { || ... }
click to toggle source
# File activemodel/test/cases/type/date_time_test.rb, line 31 def with_timezone_config(default:) old_zone_default = ::Time.zone_default ::Time.zone_default = ::Time.find_zone(default) yield ensure ::Time.zone_default = old_zone_default end