Skip to content

Commit

Permalink
Add embedded engine initializers to spring watcher
Browse files Browse the repository at this point in the history
This will allow embedded engine initializers to reload the application
when changed. Previously, the server would have to be reloaded manually.

Co-Authored-By: Gannon McGibbon <gannon.mcgibbon@shopify.com>
  • Loading branch information
andrewn617 and gmcgibbon committed Aug 1, 2024
1 parent c5987d5 commit 7f053a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def preload
watcher.add Spring.gemfile, Spring.gemfile_lock

if defined?(Rails) && Rails.application
watcher.add Rails.application.paths["config/initializers"]
Rails::Engine.descendants.each do |engine|
if engine.root.to_s.start_with?(Rails.root.to_s)
watcher.add engine.paths["config/initializers"]
end
end
watcher.add Rails.application.paths["config/database"]
if secrets_path = Rails.application.paths["config/secrets"]
watcher.add secrets_path
Expand Down
20 changes: 20 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ def exec_name
test "rails db:system:change" do
assert_success "bin/rails db:system:change --to=sqlite3"
end

test "watches embedded engine initializers" do
engine_file = app.path("engine/lib/my_engine.rb")
engine_file.mkpath
engine_file.write(<<~RUBY)
require "rails/engine"
class MyEngine < Rails::Engine
end
RUBY
app.path("engine/config/initializers/first.rb").write("")

assert_success app.spring_test_command

app.path("engine/config/initializers/second.rb").write("")

app.await_reload

assert_success app.spring_test_command
end
end
end
end

0 comments on commit 7f053a7

Please sign in to comment.