Correctly classify the files and directories that pass to watcher

Currently, autoload paths pass to the watcher as directories. If using evented
watcher, this possibly pass as it is to `Listen`.
But autoload paths include files and `Listen` raise an error when was passed
file. So, it is necessary to classify files and directories correctly.

Fixes #37011.
This commit is contained in:
yuuji.yaginuma 2019-09-01 15:52:31 +09:00
parent d05f1f036f
commit 81befcf267
2 changed files with 29 additions and 1 deletions

View File

@ -351,7 +351,7 @@ module Rails
files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
ActiveSupport::Dependencies.autoload_paths.each do |path|
dirs[path.to_s] = [:rb]
File.file?(path) ? files << path.to_s : dirs[path.to_s] = [:rb]
end
[files, dirs]

View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
require "isolation/abstract_unit"
module ApplicationTests
class WatcherTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
setup :build_app
teardown :teardown_app
def app
@app ||= Rails.application
end
test "watchable_args classifies files included in autoload path" do
add_to_config <<-RUBY
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
RUBY
app_file "app/README.md", ""
require "#{rails_root}/config/environment"
files, _ = Rails.application.watchable_args
assert_includes files, "#{rails_root}/app/README.md"
end
end
end