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

Signing out redirects incorrectly when activeadmin route is scoped #1791

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
21 changes: 15 additions & 6 deletions lib/active_admin/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ module Controller

# Redirect to the default namespace on logout
def root_path
(Rails.configuration.action_controller[:relative_url_root] || '') +
if ActiveAdmin.application.default_namespace
"/#{ActiveAdmin.application.default_namespace}"
else
"/"
end
namespace = ActiveAdmin.application.default_namespace.presence
root_path_method = [*namespace, :root_path].join('_')
url_helpers = Rails.application.routes.url_helpers

path = if url_helpers.respond_to? root_path_method
url_helpers.send root_path_method
else
# Guess a root_path when url_helpers not helpful
"/#{namespace}"
end

# NOTE: `relative_url_root` is deprecated by rails.
# Remove prefix here if it is removed completely.
prefix = Rails.configuration.action_controller[:relative_url_root] || ''
prefix + path
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/unit/devise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ def self.helper(*); end
end

end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in routing_spec instead of devise_spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better in devise_spec. It is mainly related to root_path method in devise.rb and there are other root_path related tests in devise_spec already.


context "within a scoped route" do

SCOPE = '/aa_scoped'

before do
# Remove existing routes
routes = Rails.application.routes
routes.clear!

# Add scoped routes
routes.draw do
scope :path => SCOPE do
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
end
end
end

after do
# Resume default routes
reload_routes!
end

it "should include scope path in root_path" do
controller.root_path.should == "#{SCOPE}/admin"
end

end

describe "#config" do
let(:config) { ActiveAdmin::Devise.config }
Expand Down