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

Add engine draw_paths to app #48388

Merged
merged 1 commit into from
Jun 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Add engine's draw paths to application route set, so that the application
can draw route files defined in engine paths.

*Gannon McGibbon*

* Support `VISUAL` environment variable for commands which open an editor,
and prefer it over `EDITOR`.

Expand Down
1 change: 1 addition & 0 deletions railties/lib/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def load_seed
routing_paths = paths["config/routes.rb"].existent
external_paths = self.paths["config/routes"].paths
routes.draw_paths.concat(external_paths)
app.routes.draw_paths.concat(external_paths)

if routes? || routing_paths.any?
app.routes_reloader.paths.unshift(*routing_paths)
Expand Down
28 changes: 28 additions & 0 deletions railties/test/railties/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,34 @@ class AddFirstNameToUsers < ActiveRecord::Migration::Current
assert_nothing_raised { BukkitController }
end

test "can draw routes in app routes from engines" do
@plugin.write "config/routes/testing.rb", <<~RUBY
Rails.application.routes.draw do
get "/testing", to: "test#action", as: :testing
end
RUBY

@plugin.write "config/routes.rb", <<~RUBY
Rails.application.routes.draw do
draw(:testing)
end
RUBY

@plugin.write "app/controllers/testing_controller.rb", <<-RUBY
class TestingController < ActionController::Base
def index
render plain: "test"
end
end
RUBY

boot_rails

get("/testing")

assert_equal("test", last_response.body)
end

test "adds its views to view paths" do
@plugin.write "app/controllers/bukkit_controller.rb", <<-RUBY
class BukkitController < ActionController::Base
Expand Down