aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2014-01-10 22:29:42 +0530
committerPrathamesh Sonpatki <csonpatki@gmail.com>2014-01-11 18:35:38 +0530
commit1842a6920f6205262407ca893d31577f050b6b87 (patch)
treec38e3a45ff0b8b8f4b9b775799340a8a778f6bd1
parente633cdb34a382fc606a424c5861764a9707a771d (diff)
downloadrails-1842a6920f6205262407ca893d31577f050b6b87.tar.gz
rails-1842a6920f6205262407ca893d31577f050b6b87.tar.bz2
rails-1842a6920f6205262407ca893d31577f050b6b87.zip
Fix iterating over DateTime by doing strict checking for Time objects
- Fixes #13667
-rw-r--r--activesupport/lib/active_support/core_ext/range/each.rb3
-rw-r--r--activesupport/test/core_ext/range_ext_test.rb4
2 files changed, 5 insertions, 2 deletions
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