aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2015-11-11 10:18:43 +0100
committerXavier Noria <fxn@hashref.com>2015-11-11 10:18:43 +0100
commit472b8e054b293c3c4a07572bd2d4904d51d861e0 (patch)
tree2b438b0d7fe03ae995978f04d3a3d2aa19a19d95 /activesupport
parente42a5fd3d579f60594fbed2f0f728e434da123b9 (diff)
downloadrails-472b8e054b293c3c4a07572bd2d4904d51d861e0.tar.gz
rails-472b8e054b293c3c4a07572bd2d4904d51d861e0.tar.bz2
rails-472b8e054b293c3c4a07572bd2d4904d51d861e0.zip
revises the implementation of Pathname#ascendant_of? (in refinement)
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/file_evented_update_checker.rb9
-rw-r--r--activesupport/test/file_evented_update_checker_test.rb29
2 files changed, 37 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/file_evented_update_checker.rb b/activesupport/lib/active_support/file_evented_update_checker.rb
index ae500d697f..9c66363e9f 100644
--- a/activesupport/lib/active_support/file_evented_update_checker.rb
+++ b/activesupport/lib/active_support/file_evented_update_checker.rb
@@ -79,7 +79,14 @@ module ActiveSupport
using Module.new {
refine Pathname do
def ascendant_of?(other)
- other.to_s =~ /\A#{Regexp.quote(to_s)}#{Pathname::SEPARATOR_PAT}?/
+ if self != other && other.to_s.start_with?(to_s)
+ # On Windows each_filename does not include the drive letter,
+ # but the test above already detects if they differ.
+ parts = each_filename.to_a
+ other_parts = other.each_filename.to_a
+
+ other_parts[0, parts.length] == parts
+ end
end
end
}
diff --git a/activesupport/test/file_evented_update_checker_test.rb b/activesupport/test/file_evented_update_checker_test.rb
index 9d09cbca8f..071449d399 100644
--- a/activesupport/test/file_evented_update_checker_test.rb
+++ b/activesupport/test/file_evented_update_checker_test.rb
@@ -118,4 +118,33 @@ class FileEventedUpdateCheckerPathHelperTest < ActiveSupport::TestCase
assert_equal paths.values_at(0, 2, 4), @ph.filter_out_descendants(paths)
end
+
+ test '#filter_out_descendants works on path units' do
+ paths = %w(
+ /foo/bar
+ /foo/barrrr
+ ).map { |path| pn(path) }
+
+ assert_equal paths, @ph.filter_out_descendants(paths)
+ end
+
+ test '#filter_out_descendants deals correctly with the root directory' do
+ paths = %w(
+ /
+ /foo
+ /foo/bar
+ ).map { |path| pn(path) }
+
+ assert_equal paths.values_at(0), @ph.filter_out_descendants(paths)
+ end
+
+ test '#filter_out_descendants preserves duplicates' do
+ paths = %w(
+ /foo
+ /foo/bar
+ /foo
+ ).map { |path| pn(path) }
+
+ assert_equal paths.values_at(0, 2), @ph.filter_out_descendants(paths)
+ end
end