aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorAkshay Vishnoi <akshay.vishnoi@vinsol.com>2014-04-16 03:34:26 +0530
committerAkshay Vishnoi <akshay.vishnoi@vinsol.com>2014-04-16 03:34:26 +0530
commite120d21211f9644e9b832e51ba7aa6c45448b782 (patch)
tree9b51a7550351c694e6743feca57cf4a6c7b69103 /activesupport/test/core_ext
parent0bccde963c0b3e2ad65b2bdac9d144f40854ec90 (diff)
downloadrails-e120d21211f9644e9b832e51ba7aa6c45448b782.tar.gz
rails-e120d21211f9644e9b832e51ba7aa6c45448b782.tar.bz2
rails-e120d21211f9644e9b832e51ba7aa6c45448b782.zip
Object#duplicable?
1. Improve tests 2. Remove unnecessary constant 3. Add docs for BigDecimal#duplicable?
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/object/duplicable_test.rb25
1 files changed, 9 insertions, 16 deletions
diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb
index e0566e012c..84512380cf 100644
--- a/activesupport/test/core_ext/object/duplicable_test.rb
+++ b/activesupport/test/core_ext/object/duplicable_test.rb
@@ -5,34 +5,27 @@ require 'active_support/core_ext/numeric/time'
class DuplicableTest < ActiveSupport::TestCase
RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, 5.seconds]
- YES = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new]
- NO = []
+ ALLOW_DUP = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new]
+ # Needed to support Ruby 1.9.x, as it doesn't allow dup on BigDecimal, instead
+ # raises TypeError exception. Checking here on the runtime whether BigDecimal
+ # will allow dup or not.
begin
bd = BigDecimal.new('4.56')
- YES << bd.dup
+ ALLOW_DUP << bd.dup
rescue TypeError
RAISE_DUP << bd
end
-
def test_duplicable
- (RAISE_DUP + NO).each do |v|
+ RAISE_DUP.each do |v|
assert !v.duplicable?
+ assert_raises(TypeError, v.class.name) { v.dup }
end
- YES.each do |v|
- assert v.duplicable?, "#{v.class} should be duplicable"
- end
-
- (YES + NO).each do |v|
+ ALLOW_DUP.each do |v|
+ assert v.duplicable?, "#{ v.class } should be duplicable"
assert_nothing_raised { v.dup }
end
-
- RAISE_DUP.each do |v|
- assert_raises(TypeError, v.class.name) do
- v.dup
- end
- end
end
end