Skip to content

Commit

Permalink
Only add exist paths to reloading target
Browse files Browse the repository at this point in the history
Currently, `factories`, `test/factories` and `spec/factories` are
specified by default as reload watching paths.
In many applications, there are directories which do not exist (perhaps
do not have` spec` if using minitest and do not have` spec` if using
minitest).

In Rails 5 series, if specify a path that does not exist in
`EventedFileUpdateChecker`, its parent is added to the watching path.
As a result, `node_modules` is also included in the watching path, and
unexpectedly many directories and files are included in listen's watching
targets. Also, if symlink is included in `node_modules`, it also causes
warning of listen.

This issue is solved in Rails 6. However, since many applications use
this gem in Rails 5 and below, it is good not to add directories that
do not exist on the gem side.

Ref: rails/rails#32700
  • Loading branch information
y-yagi committed Feb 5, 2019
1 parent df44185 commit 7e47e11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/factory_bot_rails/railtie.rb
Expand Up @@ -31,7 +31,7 @@ class Railtie < Rails::Railtie
def definition_file_paths
config.factory_bot.definition_file_paths.map do |path|
Rails.root.join(path)
end
end.select(&:exist?)
end
end
end
8 changes: 8 additions & 0 deletions spec/factory_bot_rails/railtie_spec.rb
Expand Up @@ -54,4 +54,12 @@ def wait_for_rails_to_reload
sleep 0.01
end
end

describe "default definition paths" do
it "include only exist paths" do
expect(FactoryBot.definition_file_paths).to eq(
[Rails.root.join("factories")],
)
end
end
end

0 comments on commit 7e47e11

Please sign in to comment.