Permalink
Browse files

Merge pull request #5800 from arunagw/bigdecimal_dup

Backport BigDecimal#duplicable? feature check from master
  • Loading branch information...
2 parents a85ffd0 + fedd87c commit e0fd4fc9e2867ee991df66ab1e704f69377cb9c5 @jeremy jeremy committed Apr 10, 2012
@@ -104,3 +104,16 @@ def duplicable?
false
end
end
+
+require 'bigdecimal'
+class BigDecimal
+ begin
+ BigDecimal.new('4.56').dup
+
+ def duplicable?
+ true
+ end
+ rescue TypeError
+ # can't dup, so use superclass implementation
+ end
+end
@@ -4,25 +4,33 @@
require 'active_support/core_ext/numeric/time'
class DuplicableTest < Test::Unit::TestCase
- RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), 5.seconds]
+ RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, 5.seconds]
YES = ['1', Object.new, /foo/, [], {}, Time.now]
NO = [Class.new, Module.new]
+ begin
+ bd = BigDecimal.new('4.56')
+ YES << bd.dup
+ rescue TypeError
+ RAISE_DUP << bd
+ end
+
+
def test_duplicable
(RAISE_DUP + NO).each do |v|
assert !v.duplicable?
end
YES.each do |v|
- assert v.duplicable?
+ assert v.duplicable?, "#{v.class} should be duplicable"
end
(YES + NO).each do |v|
assert_nothing_raised { v.dup }
end
RAISE_DUP.each do |v|
- assert_raises(TypeError) do
+ assert_raises(TypeError, v.class.name) do
v.dup
end
end

0 comments on commit e0fd4fc

Please sign in to comment.