Sha256: 0176f8ae5e8d2afa2c9d658ce9092e53879994d0c802e5933de55f42161d4b3f
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true require "cases/helper" require "active_model/type" module ActiveModel module Type class DateTimeTest < ActiveModel::TestCase 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 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 private 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-on-quails-0.1.0 | activemodel/test/cases/type/date_time_test.rb |