From ca0c0a20ac8efd0c3332e9d03d1fdf63eaac5eea Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 5 Jan 2012 14:59:05 -0800 Subject: add the class name to the assertion message --- activesupport/test/core_ext/duplicable_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/test/core_ext/duplicable_test.rb b/activesupport/test/core_ext/duplicable_test.rb index e48e6a7c45..d1a886fba0 100644 --- a/activesupport/test/core_ext/duplicable_test.rb +++ b/activesupport/test/core_ext/duplicable_test.rb @@ -22,7 +22,7 @@ class DuplicableTest < Test::Unit::TestCase end RAISE_DUP.each do |v| - assert_raises(TypeError) do + assert_raises(TypeError, v.class.name) do v.dup end end -- cgit v1.2.3 From 2991370a4081cfb71533ade113c5aaf1d70bfe06 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 20 Mar 2012 09:51:22 -0700 Subject: bigdecimal can be duped on Ruby 2.0 Conflicts: activesupport/test/core_ext/duplicable_test.rb --- .../lib/active_support/core_ext/object/duplicable.rb | 12 ++++++++++++ activesupport/test/core_ext/duplicable_test.rb | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index 9d044eba71..6c607b0d16 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -104,3 +104,15 @@ class Module false end end + +class BigDecimal + begin + BigDecimal.new('4.56').dup + + def duplicable? + true + end + rescue TypeError + # can't dup, so use superclass implementation + end +end diff --git a/activesupport/test/core_ext/duplicable_test.rb b/activesupport/test/core_ext/duplicable_test.rb index d1a886fba0..356b849adf 100644 --- a/activesupport/test/core_ext/duplicable_test.rb +++ b/activesupport/test/core_ext/duplicable_test.rb @@ -4,17 +4,25 @@ require 'active_support/core_ext/object/duplicable' 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| -- cgit v1.2.3 From fedd87cc0542461b3f04f8a7fb9aa5a89a7e1992 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 20 Mar 2012 10:38:43 -0700 Subject: probably should require the objects we monkey patch. --- activesupport/lib/active_support/core_ext/object/duplicable.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index 6c607b0d16..9d1630bb7c 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -105,6 +105,7 @@ class Module end end +require 'bigdecimal' class BigDecimal begin BigDecimal.new('4.56').dup -- cgit v1.2.3