aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-02-10 10:11:09 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-10 10:11:09 -0800
commitfc3fad8d85a82e2ac9ed5c108fb2410b72ab447b (patch)
treef6fdbac555c03f573a4506bc98754e67d217dfc6 /activesupport
parent415424f3888d2318fe63680196426404884290e6 (diff)
parent6f68e632746f72469cbd1c1b6cb9d3f1ed1730a0 (diff)
downloadrails-fc3fad8d85a82e2ac9ed5c108fb2410b72ab447b.tar.gz
rails-fc3fad8d85a82e2ac9ed5c108fb2410b72ab447b.tar.bz2
rails-fc3fad8d85a82e2ac9ed5c108fb2410b72ab447b.zip
Merge pull request #4985 from shigeya/range_overlaps_to_use_cover
make Range#overlaps? accept Range of Time
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/range/overlaps.rb2
-rw-r--r--activesupport/test/core_ext/range_ext_test.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/overlaps.rb b/activesupport/lib/active_support/core_ext/range/overlaps.rb
index 7df653b53f..603657c180 100644
--- a/activesupport/lib/active_support/core_ext/range/overlaps.rb
+++ b/activesupport/lib/active_support/core_ext/range/overlaps.rb
@@ -3,6 +3,6 @@ class Range
# (1..5).overlaps?(4..6) # => true
# (1..5).overlaps?(7..9) # => false
def overlaps?(other)
- include?(other.first) || other.include?(first)
+ cover?(other.first) || other.cover?(first)
end
end
diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb
index 8a91f6d69c..cf1ec448c2 100644
--- a/activesupport/test/core_ext/range_ext_test.rb
+++ b/activesupport/test/core_ext/range_ext_test.rb
@@ -71,4 +71,16 @@ class RangeTest < ActiveSupport::TestCase
range = (1..3)
assert range.method(:include?) != range.method(:cover?)
end
+
+ def test_overlaps_on_time
+ time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
+ time_range_2 = Time.utc(2005, 12, 10, 17, 00)..Time.utc(2005, 12, 10, 18, 00)
+ assert time_range_1.overlaps?(time_range_2)
+ end
+
+ def test_no_overlaps_on_time
+ time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
+ time_range_2 = Time.utc(2005, 12, 10, 17, 31)..Time.utc(2005, 12, 10, 18, 00)
+ assert !time_range_1.overlaps?(time_range_2)
+ end
end