From 1842a6920f6205262407ca893d31577f050b6b87 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Fri, 10 Jan 2014 22:29:42 +0530 Subject: Fix iterating over DateTime by doing strict checking for Time objects - Fixes #13667 --- activesupport/lib/active_support/core_ext/range/each.rb | 3 +-- activesupport/test/core_ext/range_ext_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/range/each.rb b/activesupport/lib/active_support/core_ext/range/each.rb index d51ea2e944..ecef78f55f 100644 --- a/activesupport/lib/active_support/core_ext/range/each.rb +++ b/activesupport/lib/active_support/core_ext/range/each.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/module/aliasing' -require 'active_support/core_ext/object/acts_like' class Range #:nodoc: @@ -17,7 +16,7 @@ class Range #:nodoc: private def ensure_iteration_allowed - if first.acts_like?(:time) + if first.is_a?(Time) raise TypeError, "can't iterate from #{first.class}" end end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 6d6afc85c4..150e6b65fb 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -112,4 +112,8 @@ class RangeTest < ActiveSupport::TestCase end end + def test_date_time_with_each + datetime = DateTime.now + assert ((datetime - 1.hour)..datetime).each {} + end end -- cgit v1.2.3