aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/type/decimal_test.rb
diff options
context:
space:
mode:
authorMariano Valles <mariano.valles@wooga.com>2014-07-16 17:17:31 +0200
committerMariano Valles <mariano.valles@wooga.com>2014-07-16 17:17:31 +0200
commitdd02463a26f3d9cd20bb6fb5ef84e0df7477c75d (patch)
tree0e7e5d11e5c5d56b33b8e455ff56f74b0601a114 /activerecord/test/cases/type/decimal_test.rb
parent431b4b4d8881fce7bd937d7d9ff38afb1e3d8b4c (diff)
downloadrails-dd02463a26f3d9cd20bb6fb5ef84e0df7477c75d.tar.gz
rails-dd02463a26f3d9cd20bb6fb5ef84e0df7477c75d.tar.bz2
rails-dd02463a26f3d9cd20bb6fb5ef84e0df7477c75d.zip
Fix decimal_test module and add new test for object responding to to_d
Diffstat (limited to 'activerecord/test/cases/type/decimal_test.rb')
-rw-r--r--activerecord/test/cases/type/decimal_test.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/activerecord/test/cases/type/decimal_test.rb b/activerecord/test/cases/type/decimal_test.rb
index 1415afc420..951cd879dd 100644
--- a/activerecord/test/cases/type/decimal_test.rb
+++ b/activerecord/test/cases/type/decimal_test.rb
@@ -1,24 +1,33 @@
require "cases/helper"
module ActiveRecord
- module ConnectionAdapters
+ module Type
class DecimalTest < ActiveRecord::TestCase
def test_type_cast_decimal
- type = Type::Decimal.new
+ 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)
+ def test_type_cast_decimal_from_rational_with_precision
+ 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
+ def test_type_cast_decimal_from_rational_without_precision_defaults_to_18_36
+ type = Decimal.new
assert_equal BigDecimal("0.333333333333333333E0"), type.type_cast_from_user(Rational(1, 3))
end
+
+ def test_type_cast_decimal_from_object_responding_to_d
+ value = Object.new
+ def value.to_d
+ BigDecimal.new("1")
+ end
+ type = Decimal.new
+ assert_equal BigDecimal("1"), type.type_cast_from_user(value)
+ end
end
end
end