aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-20 09:51:22 -0700
committerArun Agrawal <arunagw@gmail.com>2012-04-10 21:06:17 +0530
commit2991370a4081cfb71533ade113c5aaf1d70bfe06 (patch)
treedbd95ffb9bac9e8c2e2121e516f1cc5c10d3abd4
parentca0c0a20ac8efd0c3332e9d03d1fdf63eaac5eea (diff)
downloadrails-2991370a4081cfb71533ade113c5aaf1d70bfe06.tar.gz
rails-2991370a4081cfb71533ade113c5aaf1d70bfe06.tar.bz2
rails-2991370a4081cfb71533ade113c5aaf1d70bfe06.zip
bigdecimal can be duped on Ruby 2.0
Conflicts: activesupport/test/core_ext/duplicable_test.rb
-rw-r--r--activesupport/lib/active_support/core_ext/object/duplicable.rb12
-rw-r--r--activesupport/test/core_ext/duplicable_test.rb12
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|