blob: 2dd1a55616ebd00f6ef57920ec2fc9e83e782d48 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# frozen_string_literal: true
require "cases/helper"
module ActiveModel
module Type
class DateTest < ActiveModel::TestCase
def test_type_cast_date
type = Type::Date.new
assert_nil type.cast(nil)
assert_nil type.cast("")
assert_nil type.cast(" ")
assert_nil type.cast("ABC")
now = ::Time.now.utc
values_hash = { 1 => now.year, 2 => now.mon, 3 => now.mday }
date_string = now.strftime("%F")
assert_equal date_string, type.cast(date_string).strftime("%F")
assert_equal date_string, type.cast(values_hash).strftime("%F")
end
def test_returns_correct_year
type = Type::Date.new
time = ::Time.utc(1, 1, 1)
date = ::Date.new(time.year, time.mon, time.mday)
values_hash_for_multiparameter_assignment = { 1 => 1, 2 => 1, 3 => 1 }
assert_equal date, type.cast(values_hash_for_multiparameter_assignment)
end
end
end
end
|