mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 14:58:05 -05:00
FIX plataformatec/devise#4127 (#4700)
This commit is contained in:
@@ -144,11 +144,16 @@ module Devise
|
|||||||
|
|
||||||
opts[:format] = request_format unless skip_format?
|
opts[:format] = request_format unless skip_format?
|
||||||
|
|
||||||
opts[:script_name] = relative_url_root if relative_url_root?
|
|
||||||
|
|
||||||
router_name = Devise.mappings[scope].router_name || Devise.available_router_name
|
router_name = Devise.mappings[scope].router_name || Devise.available_router_name
|
||||||
context = send(router_name)
|
context = send(router_name)
|
||||||
|
|
||||||
|
if relative_url_root?
|
||||||
|
opts[:script_name] = relative_url_root
|
||||||
|
elsif defined? context.routes
|
||||||
|
rootpath = context.routes.url_helpers.root_path
|
||||||
|
opts[:script_name] = rootpath.chomp('/') unless rootpath.length <= 1
|
||||||
|
end
|
||||||
|
|
||||||
if context.respond_to?(route)
|
if context.respond_to?(route)
|
||||||
context.send(route, opts)
|
context.send(route, opts)
|
||||||
elsif respond_to?(:root_url)
|
elsif respond_to?(:root_url)
|
||||||
|
|||||||
@@ -2,10 +2,23 @@
|
|||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class MyMountableEngine
|
module MyMountableEngine
|
||||||
def self.call(env)
|
class Engine < ::Rails::Engine
|
||||||
['200', { 'Content-Type' => 'text/html' }, ['Rendered content of MyMountableEngine']]
|
isolate_namespace MyMountableEngine
|
||||||
end
|
end
|
||||||
|
class TestsController < ActionController::Base
|
||||||
|
def index
|
||||||
|
render plain: 'Root test successful'
|
||||||
|
end
|
||||||
|
def inner_route
|
||||||
|
render plain: 'Inner route test successful'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
MyMountableEngine::Engine.routes.draw do
|
||||||
|
get 'test', to: 'tests#inner_route'
|
||||||
|
root to: 'tests#index'
|
||||||
end
|
end
|
||||||
|
|
||||||
# If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling
|
# If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling
|
||||||
@@ -15,7 +28,7 @@ Rails.application.routes.disable_clear_and_finalize = true
|
|||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
authenticate(:user) do
|
authenticate(:user) do
|
||||||
mount MyMountableEngine, at: '/mountable_engine'
|
mount MyMountableEngine::Engine, at: '/mountable_engine'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,6 +46,23 @@ class AuthenticatedMountedEngineTest < Devise::IntegrationTest
|
|||||||
get '/mountable_engine'
|
get '/mountable_engine'
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_contain 'Rendered content of MyMountableEngine'
|
assert_contain 'Root test successful'
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
test 'renders a inner route of the mounted engine when authenticated' do
|
||||||
|
sign_in_as_user
|
||||||
|
get '/mountable_engine/test'
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_contain 'Inner route test successful'
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'respond properly to a non existing route of the mounted engine' do
|
||||||
|
sign_in_as_user
|
||||||
|
|
||||||
|
assert_raise ActionController::RoutingError do
|
||||||
|
get '/mountable_engine/non-existing-route'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user