From 25b3cbb241a334d750eed24f5094151e52ed7c69 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 17 Feb 2019 21:44:15 +0900 Subject: Add edge test cases for integer and string types --- activemodel/test/cases/type/integer_test.rb | 7 +++++++ activemodel/test/cases/type/string_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'activemodel/test/cases/type') diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb index df12098974..9bd0110099 100644 --- a/activemodel/test/cases/type/integer_test.rb +++ b/activemodel/test/cases/type/integer_test.rb @@ -50,6 +50,13 @@ module ActiveModel assert_equal 7200, type.cast(2.hours) end + test "casting empty string" do + type = Type::Integer.new + assert_nil type.cast("") + assert_nil type.serialize("") + assert_equal 0, type.deserialize("") + end + test "changed?" do type = Type::Integer.new diff --git a/activemodel/test/cases/type/string_test.rb b/activemodel/test/cases/type/string_test.rb index 2d85556d20..9cc530e8db 100644 --- a/activemodel/test/cases/type/string_test.rb +++ b/activemodel/test/cases/type/string_test.rb @@ -12,6 +12,14 @@ module ActiveModel assert_equal "123", type.cast(123) end + test "type casting for database" do + type = Type::String.new + object, array, hash = Object.new, [true], { a: :b } + assert_equal object, type.serialize(object) + assert_equal array, type.serialize(array) + assert_equal hash, type.serialize(hash) + end + test "cast strings are mutable" do type = Type::String.new -- cgit v1.2.3