-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow overriding the routes proxy in the ResourceController
#5219
Allow overriding the routes proxy in the ResourceController
#5219
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5219 +/- ##
=======================================
Coverage 88.67% 88.67%
=======================================
Files 564 564
Lines 13893 13895 +2
=======================================
+ Hits 12319 12321 +2
Misses 1574 1574
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
Thanks @mamhoff, excellent work as always. I left some initial questions.
backend/spec/controllers/spree/admin/resource_controller_spec.rb
Outdated
Show resolved
Hide resolved
@@ -2,23 +2,34 @@ | |||
|
|||
require 'spec_helper' | |||
|
|||
module Spree | |||
module MyEngine |
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.
What do you think about duplicating these specs so that we also have some for Spree
, instead of replacing them?
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 think the spree
routes proxy is implicitly tested in all of Solidus' admin controllers, so I believe that's not really necessary. If you insist though I can go that route.
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.
Thanks, @mamhoff! That will be helpful! I am only concerned about the chosen test strategy, where we're modifying the Dummy app routes mounting an engine that it's later removed. From Solidus's point of view, this is more of a refactor, so I don't think there's the need to change anything. At most, we can just test the new routes_proxy
public method.
6bb9386
to
1f62a61
Compare
Hm, I did develop the feature using those tests. If we aren't concerned about "how the sausage was made", I'll happily drop the spec change. Y'all decide. :) |
@mamhoff We discussed internally and we think we can drop those specs changes. The setup complexity/impact ratio is probably not worth it. As @waiting-for-dev suggested, probably we can just unit test the new method. On a side note, I checked existing extensions and I found some occurrences of using the AdminResource controller without the need for this change (e.g. https://github.com/solidusio-contrib/solidus_content/blob/da2de159fa3c14c139f9f2aedff80636a5398ff8/app/controllers/solidus_content/resource_controller.rb#L4). Do you know why it's not needed there? Maybe it's just because of this? |
In most Solidus extensions, we create routes within the |
Yep, I saw that but reading the git history, I think it's for another reason, more specific to that extension's purpose and would happen anyway.
Isolating the engine is legit in the Rails world, even if maybe not a common practice in the Soldius' extensions ecosystem. I think it's more than legit for us to support this use case. Thanks for adding some context. 👍 |
Within Solidus, we always want to use the `spree` routes proxy as that is where all routes are defined. However, many people use the Resource controller as a parent controller in their main app, and because of this they need to override all the URL generation methods in the Resource Controller. This allows one to specify the routes proxy in a custom controller as follows: ```rb module MyApp class WidgetsController < Spree::Admin::ResourceController private def routes_proxy main_app end end ``` Engine Developers can use this for engines, as well: ```rb module MyEngine class WidgetsController < Spree::Admin::ResourceController private def routes_proxy my_engine end end ```
1f62a61
to
3957b5e
Compare
Thanks, @mamhoff! |
ResourceController
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio/solidus#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio/solidus#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio/solidus#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio#5219
The controller code we were using relied on a patch to Solidus[1] that will only be released with Solidus 4.2. We want to be compatible with Solidus 4 though, so we're incorporating that patch into our own BaseController and use that instead of Solidus' ResourceController. [1] solidusio#5219
Summary
Within Solidus, we always want to use the
spree
routes proxy as that is where all routes are defined. However, many people use the Resource controller as a parent controller in their main app, and because of this they need to override all the URL generation methods in the Resource Controller.This allows one to specify the routes proxy in a custom controller as follows:
Engine Developers can use this for engines, as well:
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: