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

FIX plataformatec/devise#4127 #4700

Merged
merged 4 commits into from
Jan 23, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/devise/failure_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,16 @@ def scope_url

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
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)
context.send(route, opts)
elsif respond_to?(:root_url)
Expand Down
40 changes: 35 additions & 5 deletions test/integration/mounted_engine_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
require 'test_helper'

class MyMountableEngine
def self.call(env)
['200', { 'Content-Type' => 'text/html' }, ['Rendered content of MyMountableEngine']]
module MyMountableEngine
class Engine < ::Rails::Engine
isolate_namespace MyMountableEngine
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

# If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling
Expand All @@ -13,7 +26,7 @@ def self.call(env)

Rails.application.routes.draw do
authenticate(:user) do
mount MyMountableEngine, at: '/mountable_engine'
mount MyMountableEngine::Engine, at: '/mountable_engine'
end
end

Expand All @@ -31,6 +44,23 @@ class AuthenticatedMountedEngineTest < Devise::IntegrationTest
get '/mountable_engine'

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