Improve engine routes installation#2076
Open
kennyadsl wants to merge 5 commits into
Open
Conversation
This test is now failing, as it wasn't matching the route because it was
using different style of quote in the fixture at test/app_templates/config/routes.rb:
mount ShopifyApp::Engine, at: "/"
This commit just exposes some lack in this generator.
This generator seems to be useless: - The routes it's injecting in the host routes file are already in the engine's routes, and they are configurable. See config/routes.rb - It seems it has been created as alternative approach to the engine's routes but the generator was not removing them correctly, so it wasn't working as expected. See previous commit for more details. - The routes template for this generator seems to be out to date. I doubt someone used it recently. Removing this path for routes makes the application code cleaner and creates a unique way of handling routes.
If we want to inject declarative webhook routes into the host
application, it's a good idea to setup routes to have it from the
beginning.
This commit add this namespace to the routes, and align all the fixture
files to be as similar as possible to a brand new host application after
the install.
After the install, a host app routes file looks like this:
Rails.application.routes.draw do
root :to => 'home#index'
get '/products', :to => 'products#index'
namespace :webhooks do
# Add your webhook routes here
end
mount ShopifyApp::Engine, at: '/'
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
This pull request refactors how routes are generated and managed in the Shopify App generators. The main focus is on simplifying and modernizing route injection, removing legacy route generator code, and improving the setup of webhook routes. Below are the most important changes:
Route Generation Refactoring
RoutesGeneratorand its associated template and tests, eliminating the custom logic for injecting ShopifyApp routes and disabling engine routes.add_webhook_routemethod to use the Railsroutehelper with namespacing instead of directly injecting lines intoroutes.rb, making the code more idiomatic and maintainable.setup_routesmethod in the install generator to scaffold a namespaced section for webhook routes, providing clearer guidance for developers.Test and Template Updates
Reviewer's guide to testing
Currently, if you create a new app, run the install generator and then run:
It won't work, as the
webhooksnamespace is not present in the routes file.With this change, it works.
Checklist
Before submitting the PR, please consider if any of the following are needed:
CHANGELOG.mdif the changes would impact usersREADME.md, if appropriate./docs, if necessary