未验证 提交 26a202a9 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #34219 from wilddima/datetime-exception-message

Add message to exception in datetime type
......@@ -39,9 +39,9 @@ def fallback_string_to_time(string)
end
def value_from_multiparameter_assignment(values_hash)
missing_parameter = (1..3).detect { |key| !values_hash.key?(key) }
if missing_parameter
raise ArgumentError, missing_parameter
missing_parameters = (1..3).select { |key| !values_hash.key?(key) }
if missing_parameters.any?
raise ArgumentError, "Provided hash #{values_hash} doesn't contain necessary keys: #{missing_parameters}"
end
super
end
......
......@@ -25,6 +25,17 @@ def test_string_to_time_with_timezone
end
end
def test_hash_to_time
type = Type::DateTime.new
assert_equal ::Time.utc(2018, 10, 15, 0, 0, 0), type.cast(1 => 2018, 2 => 10, 3 => 15)
end
def test_hash_with_wrong_keys
type = Type::DateTime.new
error = assert_raises(ArgumentError) { type.cast(a: 1) }
assert_equal "Provided hash {:a=>1} doesn't contain necessary keys: [1, 2, 3]", error.message
end
private
def with_timezone_config(default:)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册