From dbfe5c6ac4431c50293183f4561150e6c2ce43ad Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 15 Mar 2019 13:19:23 -0700 Subject: Match evented checker behavior on dir with no exts When FileUpdateChecker is passed a directory and given an empty array of extensions to match on, it will match any extension. Previously, EventedFileUpdateChecker would never match any files when given an empty array. This commit makes it EventedFileUpdateChecker match FileUpdateChecker, and watch all extensions when given an empty array. --- .../lib/active_support/evented_file_update_checker.rb | 4 +++- activesupport/test/file_update_checker_shared_tests.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb index 54bc5c0ae5..3893b0de0e 100644 --- a/activesupport/lib/active_support/evented_file_update_checker.rb +++ b/activesupport/lib/active_support/evented_file_update_checker.rb @@ -131,7 +131,9 @@ module ActiveSupport ext = @ph.normalize_extension(file.extname) file.dirname.ascend do |dir| - if @dirs.fetch(dir, []).include?(ext) + matching = @dirs[dir] + + if matching && (matching.empty? || matching.include?(ext)) break true elsif dir == @lcsp || dir.root? break false diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index 72683816b3..84d89fa0a7 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -186,6 +186,18 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end + test "should execute the block if files change in a watched directory any extensions" do + i = 0 + + checker = new_checker([], tmpdir => []) { i += 1 } + + touch(tmpfile("foo.rb")) + wait + + assert checker.execute_if_updated + assert_equal 1, i + end + test "should execute the block if files change in a watched directory several extensions" do i = 0 -- cgit v1.2.3