aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMariano Valles <mariano.valles@wooga.com>2014-07-16 16:23:54 +0200
committerMariano Valles <mariano.valles@wooga.com>2014-07-16 16:23:54 +0200
commit431b4b4d8881fce7bd937d7d9ff38afb1e3d8b4c (patch)
tree07b77666cbbd532b4b98c3e991647a78593592cf /activerecord
parent7098c9083ccd08eb36cce5abcc99ad0506945ef0 (diff)
downloadrails-431b4b4d8881fce7bd937d7d9ff38afb1e3d8b4c.tar.gz
rails-431b4b4d8881fce7bd937d7d9ff38afb1e3d8b4c.tar.bz2
rails-431b4b4d8881fce7bd937d7d9ff38afb1e3d8b4c.zip
Fix case statement to use ::Numeric and ::String
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/type/decimal.rb2
-rw-r--r--activerecord/test/cases/type/decimal_test.rb24
-rw-r--r--activerecord/test/cases/types_test.rb17
3 files changed, 25 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb
index 1c7edc12f5..31c465afdc 100644
--- a/activerecord/lib/active_record/type/decimal.rb
+++ b/activerecord/lib/active_record/type/decimal.rb
@@ -15,7 +15,7 @@ module ActiveRecord
def cast_value(value)
case value
- when Numeric, String, Rational
+ when ::Numeric, ::String
BigDecimal(value, precision.to_i)
when proc { value.respond_to?(:to_d) }
value.to_d
diff --git a/activerecord/test/cases/type/decimal_test.rb b/activerecord/test/cases/type/decimal_test.rb
new file mode 100644
index 0000000000..1415afc420
--- /dev/null
+++ b/activerecord/test/cases/type/decimal_test.rb
@@ -0,0 +1,24 @@
+require "cases/helper"
+
+module ActiveRecord
+ module ConnectionAdapters
+ class DecimalTest < ActiveRecord::TestCase
+ def test_type_cast_decimal
+ type = Type::Decimal.new
+ assert_equal BigDecimal.new("0"), type.type_cast_from_user(BigDecimal.new("0"))
+ assert_equal BigDecimal.new("123"), type.type_cast_from_user(123.0)
+ assert_equal BigDecimal.new("1"), type.type_cast_from_user(:"1")
+ end
+
+ def test_type_cast_rational_to_decimal_with_precision
+ type = Type::Decimal.new(precision: 2)
+ assert_equal BigDecimal("0.33"), type.type_cast_from_user(Rational(1, 3))
+ end
+
+ def test_type_cast_rational_to_decimal_without_precision_defaults_to_18_36
+ type = Type::Decimal.new
+ assert_equal BigDecimal("0.333333333333333333E0"), type.type_cast_from_user(Rational(1, 3))
+ end
+ end
+ end
+end
diff --git a/activerecord/test/cases/types_test.rb b/activerecord/test/cases/types_test.rb
index 541c0a4e12..5c54812f30 100644
--- a/activerecord/test/cases/types_test.rb
+++ b/activerecord/test/cases/types_test.rb
@@ -95,23 +95,6 @@ module ActiveRecord
assert_not type.changed?(nil, nil, nil)
end
- def test_type_cast_decimal
- type = Type::Decimal.new
- assert_equal BigDecimal.new("0"), type.type_cast_from_user(BigDecimal.new("0"))
- assert_equal BigDecimal.new("123"), type.type_cast_from_user(123.0)
- assert_equal BigDecimal.new("1"), type.type_cast_from_user(:"1")
- end
-
- def test_type_cast_rational_to_decimal_with_precision
- type = Type::Decimal.new(precision: 2)
- assert_equal BigDecimal("0.33"), type.type_cast_from_user(Rational(1, 3))
- end
-
- def test_type_cast_rational_to_decimal_without_precision_defaults_to_18_36
- type = Type::Decimal.new
- assert_equal BigDecimal("0.333333333333333333E0"), type.type_cast_from_user(Rational(1, 3))
- end
-
def test_type_cast_binary
type = Type::Binary.new
assert_equal nil, type.type_cast_from_user(nil)