From a323b83acfe6e02812ec3b7b4ce912b07c85220e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 7 Jan 2010 00:05:06 -0800 Subject: [PATCH] Remove unneeded reliance on super -> method_missing quirk --- activesupport/lib/active_support/duration.rb | 6 +++-- activesupport/test/core_ext/duration_test.rb | 25 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index c1f0e4bf81d88..887a40d35e9d5 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -36,7 +36,7 @@ def -@ #:nodoc: end def is_a?(klass) #:nodoc: - klass == Duration || super + Duration == klass || value.is_a?(klass) end # Returns true if other is also a Duration instance with the @@ -50,7 +50,9 @@ def ==(other) end def self.===(other) #:nodoc: - other.is_a?(Duration) rescue super + other.is_a?(Duration) + rescue NoMethodError + false end # Calculates a new Time or Date that is as far in the future diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 42b4f10172acc..6530de1ef43e3 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -2,6 +2,31 @@ require 'active_support/time' class DurationTest < ActiveSupport::TestCase + def test_is_a + d = 1.day + assert d.is_a?(ActiveSupport::Duration) + assert d.is_a?(Numeric) + assert d.is_a?(Fixnum) + assert !d.is_a?(Hash) + + k = Class.new + class << k; undef_method :== end + assert !d.is_a?(k) + end + + def test_threequals + assert ActiveSupport::Duration === 1.day + assert !(ActiveSupport::Duration === 1.day.to_i) + assert !(ActiveSupport::Duration === 'foo') + assert !(ActiveSupport::Duration === ActiveSupport::BasicObject.new) + end + + def test_equals + assert 1.day == 1.day + assert 1.day == 1.day.to_i + assert !(1.day == 'foo') + end + def test_inspect assert_equal '0 seconds', 0.seconds.inspect assert_equal '1 month', 1.month.inspect