aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/type
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/test/cases/type')
-rw-r--r--activemodel/test/cases/type/big_integer_test.rb2
-rw-r--r--activemodel/test/cases/type/binary_test.rb2
-rw-r--r--activemodel/test/cases/type/boolean_test.rb2
-rw-r--r--activemodel/test/cases/type/date_test.rb2
-rw-r--r--activemodel/test/cases/type/date_time_test.rb2
-rw-r--r--activemodel/test/cases/type/decimal_test.rb10
-rw-r--r--activemodel/test/cases/type/float_test.rb10
-rw-r--r--activemodel/test/cases/type/immutable_string_test.rb2
-rw-r--r--activemodel/test/cases/type/integer_test.rb3
-rw-r--r--activemodel/test/cases/type/registry_test.rb2
-rw-r--r--activemodel/test/cases/type/string_test.rb15
-rw-r--r--activemodel/test/cases/type/time_test.rb2
-rw-r--r--activemodel/test/cases/type/value_test.rb2
13 files changed, 54 insertions, 2 deletions
diff --git a/activemodel/test/cases/type/big_integer_test.rb b/activemodel/test/cases/type/big_integer_test.rb
index 56002b7cc6..3d29235d52 100644
--- a/activemodel/test/cases/type/big_integer_test.rb
+++ b/activemodel/test/cases/type/big_integer_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/binary_test.rb b/activemodel/test/cases/type/binary_test.rb
index e9c2ccfca4..ef4f125a3b 100644
--- a/activemodel/test/cases/type/binary_test.rb
+++ b/activemodel/test/cases/type/binary_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/boolean_test.rb b/activemodel/test/cases/type/boolean_test.rb
index 92e5aebfb7..97b165ab48 100644
--- a/activemodel/test/cases/type/boolean_test.rb
+++ b/activemodel/test/cases/type/boolean_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/date_test.rb b/activemodel/test/cases/type/date_test.rb
index 0cc90e99d3..15c40a37b7 100644
--- a/activemodel/test/cases/type/date_test.rb
+++ b/activemodel/test/cases/type/date_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/date_time_test.rb b/activemodel/test/cases/type/date_time_test.rb
index 75a7fc686e..598ccf485e 100644
--- a/activemodel/test/cases/type/date_time_test.rb
+++ b/activemodel/test/cases/type/date_time_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/decimal_test.rb b/activemodel/test/cases/type/decimal_test.rb
index 46a913258e..a0acdc2736 100644
--- a/activemodel/test/cases/type/decimal_test.rb
+++ b/activemodel/test/cases/type/decimal_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
@@ -11,6 +13,14 @@ module ActiveModel
assert_equal BigDecimal.new("1"), type.cast(:"1")
end
+ def test_type_cast_decimal_from_invalid_string
+ type = Decimal.new
+ assert_nil type.cast("")
+ assert_equal BigDecimal.new("1"), type.cast("1ignore")
+ assert_equal BigDecimal.new("0"), type.cast("bad1")
+ assert_equal BigDecimal.new("0"), type.cast("bad")
+ end
+
def test_type_cast_decimal_from_float_with_large_precision
type = Decimal.new(precision: ::Float::DIG + 2)
assert_equal BigDecimal.new("123.0"), type.cast(123.0)
diff --git a/activemodel/test/cases/type/float_test.rb b/activemodel/test/cases/type/float_test.rb
index 2e34f57f7e..46e8b34dfe 100644
--- a/activemodel/test/cases/type/float_test.rb
+++ b/activemodel/test/cases/type/float_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
@@ -9,6 +11,14 @@ module ActiveModel
assert_equal 1.0, type.cast("1")
end
+ def test_type_cast_float_from_invalid_string
+ type = Type::Float.new
+ assert_nil type.cast("")
+ assert_equal 1.0, type.cast("1ignore")
+ assert_equal 0.0, type.cast("bad1")
+ assert_equal 0.0, type.cast("bad")
+ end
+
def test_changing_float
type = Type::Float.new
diff --git a/activemodel/test/cases/type/immutable_string_test.rb b/activemodel/test/cases/type/immutable_string_test.rb
index 23e58974fb..72f5779dfb 100644
--- a/activemodel/test/cases/type/immutable_string_test.rb
+++ b/activemodel/test/cases/type/immutable_string_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb
index 2b9b03f3cf..d2e635b447 100644
--- a/activemodel/test/cases/type/integer_test.rb
+++ b/activemodel/test/cases/type/integer_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
require "active_support/core_ext/numeric/time"
@@ -7,6 +9,7 @@ module ActiveModel
class IntegerTest < ActiveModel::TestCase
test "simple values" do
type = Type::Integer.new
+ assert_nil type.cast("")
assert_equal 1, type.cast(1)
assert_equal 1, type.cast("1")
assert_equal 1, type.cast("1ignore")
diff --git a/activemodel/test/cases/type/registry_test.rb b/activemodel/test/cases/type/registry_test.rb
index 927b6d0307..f34104286c 100644
--- a/activemodel/test/cases/type/registry_test.rb
+++ b/activemodel/test/cases/type/registry_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/string_test.rb b/activemodel/test/cases/type/string_test.rb
index 222083817e..d39389718b 100644
--- a/activemodel/test/cases/type/string_test.rb
+++ b/activemodel/test/cases/type/string_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
@@ -12,16 +14,25 @@ module ActiveModel
end
test "cast strings are mutable" do
- s = "foo"
type = Type::String.new
+
+ s = "foo".dup
assert_equal false, type.cast(s).frozen?
+ assert_equal false, s.frozen?
+
+ f = "foo".freeze
+ assert_equal false, type.cast(f).frozen?
+ assert_equal true, f.frozen?
end
test "values are duped coming out" do
- s = "foo"
type = Type::String.new
+
+ s = "foo"
assert_not_same s, type.cast(s)
+ assert_equal s, type.cast(s)
assert_not_same s, type.deserialize(s)
+ assert_equal s, type.deserialize(s)
end
end
end
diff --git a/activemodel/test/cases/type/time_test.rb b/activemodel/test/cases/type/time_test.rb
index 0cc4d33caa..0bea95768d 100644
--- a/activemodel/test/cases/type/time_test.rb
+++ b/activemodel/test/cases/type/time_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"
diff --git a/activemodel/test/cases/type/value_test.rb b/activemodel/test/cases/type/value_test.rb
index d8b3e7f164..671343b0c8 100644
--- a/activemodel/test/cases/type/value_test.rb
+++ b/activemodel/test/cases/type/value_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "cases/helper"
require "active_model/type"