diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-02-24 19:44:19 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-02-24 19:44:19 -0500 |
commit | bf8f42b2fea7e104826e214bcdd1255aa9acc802 (patch) | |
tree | de606dba6db87db1ecd41fd9e09f3844e56a7ccf /activemodel/test/cases/type | |
parent | 9099cf064f66ae4e6414736ad513399c86100902 (diff) | |
parent | 0683552b15becd6949ab4e125d9790f1b65b7415 (diff) | |
download | rails-bf8f42b2fea7e104826e214bcdd1255aa9acc802.tar.gz rails-bf8f42b2fea7e104826e214bcdd1255aa9acc802.tar.bz2 rails-bf8f42b2fea7e104826e214bcdd1255aa9acc802.zip |
Merge branch 'jhawthorn-ruby_2_4_bigdecimal_casting'
Closes #27429
Diffstat (limited to 'activemodel/test/cases/type')
-rw-r--r-- | activemodel/test/cases/type/decimal_test.rb | 8 | ||||
-rw-r--r-- | activemodel/test/cases/type/float_test.rb | 8 | ||||
-rw-r--r-- | activemodel/test/cases/type/integer_test.rb | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/activemodel/test/cases/type/decimal_test.rb b/activemodel/test/cases/type/decimal_test.rb index 46a913258e..c3b43725cc 100644 --- a/activemodel/test/cases/type/decimal_test.rb +++ b/activemodel/test/cases/type/decimal_test.rb @@ -11,6 +11,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..8026d63ad5 100644 --- a/activemodel/test/cases/type/float_test.rb +++ b/activemodel/test/cases/type/float_test.rb @@ -9,6 +9,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/integer_test.rb b/activemodel/test/cases/type/integer_test.rb index 2b9b03f3cf..a91144036b 100644 --- a/activemodel/test/cases/type/integer_test.rb +++ b/activemodel/test/cases/type/integer_test.rb @@ -7,6 +7,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") |