New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only add exist paths to reloading target #317
Only add exist paths to reloading target #317
Conversation
|
||
describe "default definition paths" do | ||
it "include only exist paths" do | ||
expect(FactoryBot.definition_file_paths).to eq([Rails.root.join("factories")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [84/80]
971dffb
to
7e47e11
Compare
The test is an error due to an incompatibility issue with Rails and the new version of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good catch. Now I remember seeing rails/rails#33822.
Is there a scenario where this fix could cause problems? If spring is running, then after that I add my first factory to spec/factories
, will I need to run spring stop
to get that factory to load?
And if that is the case, would it make sense to only do this filtering out if we are running a rails version before 6.0?
lib/factory_bot_rails/railtie.rb
Outdated
@@ -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?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will quite work because the FactoryBot.definition_file_paths
gets used for two things, both a directory and a file. So if spec/factories
is in FactoryBot.definition_file_paths
we watch both the spec/factories
directory and also the spec/factories.rb
file. With this change we would also stop watching spec/factories.rb
if spec/factories
doesn't exist. We may need to move this logic into the reloader class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When checking the directory to watching, the same check is done for the parent directory of the file. Therefore, the same fix is necessary for the files.
https://github.com/rails/rails/blob/188ccf2f41b3d6bb77ba48b81343f80cf5615b75/activesupport/lib/active_support/evented_file_update_checker.rb#L126
checker = ActiveSupport::EventedFileUpdateChecker.new(%w(spec/factories.rb test/factories.rb), []) {}
checker.send(:directories_to_watch).include?(Rails.root)
#=> true
Thanks for your review! Yes, your concern is correct. But of course, it is possible to respond by checking the version of Rails. Should I do? |
I will trust your judgement on the scenario with I think we will still have some failing tests once this gets rebased on |
7e47e11
to
78916d1
Compare
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
78916d1
to
ceba13b
Compare
Oh, sorry. I misunderstood |
Thanks! I'll have time to push the 5.0.1 release on Friday. |
Thanks! |
Currently,
factories
,test/factories
andspec/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 havespec
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 innode_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