diff options
Diffstat (limited to 'activerecord/test/cases/type/integer_test.rb')
-rw-r--r-- | activerecord/test/cases/type/integer_test.rb | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/activerecord/test/cases/type/integer_test.rb b/activerecord/test/cases/type/integer_test.rb index 1e836f2142..84fb05dd8e 100644 --- a/activerecord/test/cases/type/integer_test.rb +++ b/activerecord/test/cases/type/integer_test.rb @@ -6,45 +6,45 @@ module ActiveRecord class IntegerTest < ActiveRecord::TestCase test "simple values" do type = Type::Integer.new - assert_equal 1, type.type_cast_from_user(1) - assert_equal 1, type.type_cast_from_user('1') - assert_equal 1, type.type_cast_from_user('1ignore') - assert_equal 0, type.type_cast_from_user('bad1') - assert_equal 0, type.type_cast_from_user('bad') - assert_equal 1, type.type_cast_from_user(1.7) - assert_equal 0, type.type_cast_from_user(false) - assert_equal 1, type.type_cast_from_user(true) - assert_nil type.type_cast_from_user(nil) + assert_equal 1, type.cast(1) + assert_equal 1, type.cast('1') + assert_equal 1, type.cast('1ignore') + assert_equal 0, type.cast('bad1') + assert_equal 0, type.cast('bad') + assert_equal 1, type.cast(1.7) + assert_equal 0, type.cast(false) + assert_equal 1, type.cast(true) + assert_nil type.cast(nil) end test "random objects cast to nil" do type = Type::Integer.new - assert_nil type.type_cast_from_user([1,2]) - assert_nil type.type_cast_from_user({1 => 2}) - assert_nil type.type_cast_from_user((1..2)) + assert_nil type.cast([1,2]) + assert_nil type.cast({1 => 2}) + assert_nil type.cast((1..2)) end test "casting ActiveRecord models" do type = Type::Integer.new firm = Firm.create(:name => 'Apple') - assert_nil type.type_cast_from_user(firm) + assert_nil type.cast(firm) end test "casting objects without to_i" do type = Type::Integer.new - assert_nil type.type_cast_from_user(::Object.new) + assert_nil type.cast(::Object.new) end test "casting nan and infinity" do type = Type::Integer.new - assert_nil type.type_cast_from_user(::Float::NAN) - assert_nil type.type_cast_from_user(1.0/0.0) + assert_nil type.cast(::Float::NAN) + assert_nil type.cast(1.0/0.0) end test "casting booleans for database" do type = Type::Integer.new - assert_equal 1, type.type_cast_for_database(true) - assert_equal 0, type.type_cast_for_database(false) + assert_equal 1, type.serialize(true) + assert_equal 0, type.serialize(false) end test "changed?" do @@ -60,53 +60,53 @@ module ActiveRecord test "values below int min value are out of range" do assert_raises(::RangeError) do - Integer.new.type_cast_for_database(-2147483649) + Integer.new.serialize(-2147483649) end end test "values above int max value are out of range" do assert_raises(::RangeError) do - Integer.new.type_cast_for_database(2147483648) + Integer.new.serialize(2147483648) end end test "very small numbers are out of range" do assert_raises(::RangeError) do - Integer.new.type_cast_for_database(-9999999999999999999999999999999) + Integer.new.serialize(-9999999999999999999999999999999) end end test "very large numbers are out of range" do assert_raises(::RangeError) do - Integer.new.type_cast_for_database(9999999999999999999999999999999) + Integer.new.serialize(9999999999999999999999999999999) end end test "normal numbers are in range" do type = Integer.new - assert_equal(0, type.type_cast_for_database(0)) - assert_equal(-1, type.type_cast_for_database(-1)) - assert_equal(1, type.type_cast_for_database(1)) + assert_equal(0, type.serialize(0)) + assert_equal(-1, type.serialize(-1)) + assert_equal(1, type.serialize(1)) end test "int max value is in range" do - assert_equal(2147483647, Integer.new.type_cast_for_database(2147483647)) + assert_equal(2147483647, Integer.new.serialize(2147483647)) end test "int min value is in range" do - assert_equal(-2147483648, Integer.new.type_cast_for_database(-2147483648)) + assert_equal(-2147483648, Integer.new.serialize(-2147483648)) end test "columns with a larger limit have larger ranges" do type = Integer.new(limit: 8) - assert_equal(9223372036854775807, type.type_cast_for_database(9223372036854775807)) - assert_equal(-9223372036854775808, type.type_cast_for_database(-9223372036854775808)) + assert_equal(9223372036854775807, type.serialize(9223372036854775807)) + assert_equal(-9223372036854775808, type.serialize(-9223372036854775808)) assert_raises(::RangeError) do - type.type_cast_for_database(-9999999999999999999999999999999) + type.serialize(-9999999999999999999999999999999) end assert_raises(::RangeError) do - type.type_cast_for_database(9999999999999999999999999999999) + type.serialize(9999999999999999999999999999999) end end |