diff options
author | Xavier Noria <fxn@hashref.com> | 2015-11-08 14:29:26 -0800 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-08 22:49:50 -0800 |
commit | a62387d620b8b6862922b6a359b76c584986075d (patch) | |
tree | 59aca782231342d99e6e1a50b8d0c46389fd4c34 /activesupport/test | |
parent | cfb487535bbdaedd6b8f8b55476f0991829f809c (diff) | |
download | rails-a62387d620b8b6862922b6a359b76c584986075d.tar.gz rails-a62387d620b8b6862922b6a359b76c584986075d.tar.bz2 rails-a62387d620b8b6862922b6a359b76c584986075d.zip |
stop ascending at the longest common subpath
This commit also bases everything on Pathname internally.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/file_evented_update_checker_test.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/activesupport/test/file_evented_update_checker_test.rb b/activesupport/test/file_evented_update_checker_test.rb index 10b7a5c979..727b99958e 100644 --- a/activesupport/test/file_evented_update_checker_test.rb +++ b/activesupport/test/file_evented_update_checker_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'fileutils' require 'thread' +require 'pathname' require 'file_update_checker_with_enumerable_test_cases' class FileEventedUpdateCheckerTest < ActiveSupport::TestCase @@ -10,3 +11,62 @@ class FileEventedUpdateCheckerTest < ActiveSupport::TestCase ActiveSupport::FileEventedUpdateChecker.new(files, dirs, &block) end end + +class FileEventedUpdateCheckerPathHelperTest < ActiveSupport::TestCase + def pn(path) + Pathname.new(path) + end + + setup do + @ph = ActiveSupport::FileEventedUpdateChecker::PathHelper.new + end + + test '#xpath returns the expanded path as a Pathname object' do + assert_equal pn(__FILE__).expand_path, @ph.xpath(__FILE__) + end + + test '#normalize_extension returns a bare extension as is' do + assert_equal 'rb', @ph.normalize_extension('rb') + end + + test '#normalize_extension removes a leading dot' do + assert_equal 'rb', @ph.normalize_extension('.rb') + end + + test '#normalize_extension supports symbols' do + assert_equal 'rb', @ph.normalize_extension(:rb) + end + + test '#longest_common_subpath finds the longest common subpath, if there is one' do + paths = %w( + /foo/bar + /foo/baz + /foo/bar/baz/woo/zoo + ).map {|path| pn(path)} + + assert_equal pn('/foo'), @ph.longest_common_subpath(paths) + end + + test '#longest_common_subpath returns the root directory as an edge case' do + paths = %w( + /foo/bar + /foo/baz + /foo/bar/baz/woo/zoo + /wadus + ).map {|path| pn(path)} + + assert_equal pn('/'), @ph.longest_common_subpath(paths) + end + + test '#longest_common_subpath returns nil for an empty collection' do + assert_nil @ph.longest_common_subpath([]) + end + + test '#existing_parent returns the most specific existing ascendant' do + wd = Pathname.getwd + + assert_equal wd, @ph.existing_parent(wd) + assert_equal wd, @ph.existing_parent(wd.join('non-existing/directory')) + assert_equal pn('/'), @ph.existing_parent(pn('/non-existing/directory')) + end +end |