Skip to content
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

Watch app embedded engine initializers #723

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def preload

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"].expanded
end
end
watcher.add Rails.application.paths["config/database"]
if secrets_path = Rails.application.paths["config/secrets"]
watcher.add secrets_path
Expand Down
25 changes: 25 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,31 @@ 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
app.path("config/application.rb").write(<<~RUBY, mode: "a+")

$LOAD_PATH << Pathname.new(__dir__).join("../engine/lib").realpath.to_s
require "my_engine"
RUBY
engine_lib = app.path("engine/lib/my_engine.rb")
engine_lib.dirname.mkpath
engine_lib.write(<<~RUBY)
require "rails/engine"

class MyEngine < Rails::Engine
end
RUBY
engine_initializer = app.path("engine/config/initializers/one.rb")
engine_initializer.dirname.mkpath
engine_initializer.write("")

assert_success app.spring_test_command

engine_initializer.write("raise 'omg'")

assert_failure app.spring_test_command, stderr: "omg (RuntimeError)"
end
end
end
end
Loading