Fall back to Devise.available_router_name when mapping has none#7
Merged
Conversation
Hosts that mount Devise inside an engine commonly pin URL helpers via the GLOBAL setting (Devise.router_name = :engine in devise.rb initializer) rather than passing router_name: in devise_for. In that case Devise.mappings[scope].router_name is nil, but Devise.available_router_name returns :engine — Devise's own URL-helper dispatcher uses that fallback, and we have to too. Without the fallback the failure handler dropped through to `self`, which doesn't carry the engine-scoped session helper, and raised NoMethodError on hosts using the global pattern. The dummy_engine app's routes drop the per-mapping `router_name:` option so the regression test now exercises the global-only setup (matches the host-app pattern that surfaced the bug).
PR #7 reconfigured spec/dummy_engine to use global-only Devise.router_name (drops the per-mapping router_name: option) so the existing OmniAuth-failure scenario in spec/engine/features/engine_mounted_login_spec.rb covers the new fallback code path. That coverage was implicit — someone reading the diff sees a config change + a method change without an obvious connection. Spell it out: top comment now documents that the dummy uses global-only router_name and why the fallback matters; the failure-path context is renamed to 'OmniAuth failure path under global Devise.router_name'; a sanity check asserts Devise.mappings[:admin_user].router_name is nil and Devise.available_router_name == :admin_panel so a future flip back to the per-mapping form is loud.
The scenario now checks not just have_current_path but also have_button (the SSO landing renders again) and have_content for the access-denied flash. If the failure handler ever silently redirects to the wrong place — or if the SSO landing view itself regresses — the test catches it; previously only the path was checked, which would have passed a redirect to an empty AA index page that happens to share /admin/login.
Fivell
added a commit
that referenced
this pull request
Jun 2, 2026
PR #7 reconfigured spec/dummy_engine to use global-only Devise.router_name (drops the per-mapping router_name: option) so the existing OmniAuth-failure scenario in spec/engine/features/engine_mounted_login_spec.rb covers the new fallback code path. That coverage was implicit — someone reading the diff sees a config change + a method change without an obvious connection. Spell it out: top comment now documents that the dummy uses global-only router_name and why the fallback matters; the failure-path context is renamed to 'OmniAuth failure path under global Devise.router_name'; a sanity check asserts Devise.mappings[:admin_user].router_name is nil and Devise.available_router_name == :admin_panel so a future flip back to the per-mapping form is loud.
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.
Summary
Follow-up to the previous engine-mounted-Devise fix. Hosts that pin URL helpers via
Devise.router_name = :enginein the devise initializer (the global setting) — but don't also passrouter_name:todevise_for— still hitNoMethodErrorbecauseDevise.mappings[scope].router_nameisnilfor them and the previous patch fell through toself.Why
Devise's own URL-helper dispatcher (
devise/controllers/url_helpers.rb#generate_helpers!) uses both:The previous gem fix only honored the per-mapping value. This commit adds the
Devise.available_router_namefallback so the dispatcher matches Devise's own behavior:Devise.available_router_namedefaults to:main_app, so the default-app case still resolves through themain_appproxy — no special branching needed.Test coverage
spec/dummy_engine/lib/admin_panel/config/routes.rbnow uses the global-only pattern (devise_for :admin_users, ActiveAdmin::Devise.configwith norouter_name:), so the existing failure-path scenario inspec/engine/features/engine_mounted_login_spec.rbexercises this code path. It would fail with the previous patch and passes with this one.Test plan
rake spec:allis green — covers default, engine (global-only), and isolated-engine setups.