Sha256: 6283664c227fc5f0d13db041bfa341821c4f421502cf3a72544d196486145e8c

Contents?: true

Size: 983 Bytes

Versions: 2

Compression:

Stored size: 983 Bytes

Contents

require 'test_helper'

class Superstore::Types::TimeTypeTest < Superstore::Types::TestCase
  test 'serialize' do
    assert_equal '2004-12-24T01:02:03.000000Z', type.serialize(Time.utc(2004, 12, 24, 1, 2, 3))
    assert_nil type.serialize(nil)
  end

  test 'deserialize' do
    assert_nil type.deserialize(nil)
    assert_nil type.deserialize('bad format')
    assert_equal Time.utc(2004, 12, 24, 1, 2, 3), type.deserialize('2004-12-24T01:02:03.000000Z')
    assert_equal Time.utc(2004, 12, 24, 12, 13, 45), type.deserialize('2004-12-24 12:13:45 -0000')

    Time.use_zone 'Central Time (US & Canada)' do
      with_zone = type.deserialize('2013-07-18T13:12:46-07:00')
      assert_equal Time.utc(2013, 07, 18, 20, 12, 46), with_zone
      assert_equal 'CDT', with_zone.zone
    end
  end

  test 'cast_value' do
    assert_nil type.cast_value(1000)
    assert_nil type.cast_value(1000.0)

    my_date = Date.new
    assert_equal my_date.to_time, type.cast_value(my_date)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
superstore-3.0.0 test/unit/types/time_type_test.rb
superstore-2.5.0 test/unit/types/time_type_test.rb