Skip to content

Commit fde22eb

Browse files
committed
Ensure the admin sign in root path fallback is '/admin'
Previously relied on solidus_frontend defining `spree.root_path`, and used it redirecting admin users to the store home page.
1 parent b3e431c commit fde22eb

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/controllers/backend/spree/admin/user_sessions_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def authorization_failure
3535

3636
private
3737

38+
def signed_in_root_path(_resource)
39+
spree.admin_path
40+
end
41+
3842
# NOTE: as soon as this gem stops supporting Solidus 3.1 if-else should be removed and left only include
3943
if defined?(::Spree::Admin::SetsUserLanguageLocaleKey)
4044
include ::Spree::Admin::SetsUserLanguageLocaleKey
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Spree::Admin::UserSessionsController, type: :controller do
4+
let(:user) { create(:user, password: 'secret') }
5+
6+
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
7+
8+
it "redirects to the admin root after signing in with no stored location" do
9+
get :new
10+
11+
post(:create,
12+
params: {
13+
spree_user: {
14+
email: user.email,
15+
password: 'secret'
16+
},
17+
}
18+
)
19+
20+
expect(response).to redirect_to spree.admin_path
21+
end
22+
end

spec/features/admin/sign_in_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.feature 'Admin - Sign In', type: :feature do
44
background do
5-
@user = create(:user, email: 'email@person.com')
5+
@user = create(:admin_user, email: 'email@person.com')
66
visit spree.admin_login_path
77
end
88

@@ -19,7 +19,7 @@
1919
expect(page).to have_text 'Logged in successfully'
2020
expect(page).not_to have_text 'Login'
2121
expect(page).to have_text 'Logout'
22-
expect(current_path).to eq '/'
22+
expect(current_path).to eq '/admin/orders'
2323
end
2424

2525
scenario 'shows validation erros' do

0 commit comments

Comments
 (0)