Sha256: 478f4d47fe430ee3ce2451a24a839acf07fc85460b92161443dcde6ee9ebe95b

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'

class Superstore::Types::DateRangeTypeTest < Superstore::Types::TestCase
  test 'serialize' do
    assert_equal ["2004-04-25", "2004-05-15"], type.serialize(Date.new(2004, 4, 25) .. Date.new(2004, 5, 15))
  end

  test 'deserialize' do
    assert_equal Date.new(2004, 4, 25)..Date.new(2004, 5, 15), type.deserialize(["2004-04-25", "2004-05-15"])
    assert_nil type.deserialize(["2004-05-15", "2004-04-25"])

    # decode returns argument if already a Range
    range = Date.new(2019, 1, 1)..Date.new(2019, 2, 1)
    assert_equal range, type.deserialize(range)
  end

  test 'cast_value' do
    assert_equal Date.new(2004, 4, 25)..Date.new(2004, 5, 15), type.cast_value(Date.new(2004, 4, 25)..Date.new(2004, 5, 15))
    assert_nil type.cast_value(Date.new(2004, 5, 15)..Date.new(2004, 4, 25))
    assert_equal Date.new(2004, 4, 25)..Date.new(2004, 5, 15), type.cast_value([Date.new(2004, 4, 25), Date.new(2004, 5, 15)])
    assert_nil type.cast_value([Date.new(2004, 5, 15), Date.new(2004, 4, 25)])
    assert_equal Date.new(2004, 4, 25)..Date.new(2004, 5, 15), type.cast_value(["2004-04-25", "2004-05-15"])

    assert_nil type.cast_value(["2004-04-25", nil])
    assert_nil type.cast_value([nil, "2004-05-15"])
    assert_nil type.cast_value(["xx", "2004-05-15"])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
superstore-2.5.0 test/unit/types/date_range_type_test.rb