Skip to content

Commit 188a73b

Browse files
eliacpfergus1
authored andcommitted
Explicitly declare devise generated routes
We have some duplication affecting all stores using this extension and this is the first step toward removing it. E.g. the sign_in path was available at both /login and /spree_user/sign_in as `login_path` or `new_spree_user_session_path`.
1 parent a8ddecf commit 188a73b

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

config/routes.rb

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,46 @@
1010
passwords: 'spree/user_passwords',
1111
confirmations: 'spree/user_confirmations'
1212
},
13-
skip: [:unlocks, :omniauth_callbacks],
14-
path_names: { sign_out: 'logout' },
15-
path_prefix: :user,
16-
router_name: :spree
13+
skip: :all,
1714
})
1815

1916
resources :users, only: [:edit, :update]
2017

2118
devise_scope :spree_user do
19+
# Legacy devise generated paths
20+
# These are deprecated but we still want to support the incoming routes,
21+
# in order to give existing stores an upgrade path.
22+
get 'user/spree_user/sign_in', to: 'user_sessions#new', as: nil
23+
post 'user/spree_user/sign_in', to: 'user_sessions#create', as: nil
24+
match 'user/spree_user/logout', to: 'user_sessions#destroy', via: Devise.sign_out_via, as: nil
25+
get 'user/spree_user/password/new', to: 'user_passwords#new', as: nil
26+
get 'user/spree_user/password/edit', to: 'user_passwords#edit', as: nil
27+
patch 'user/spree_user/password', to: 'user_passwords#update', as: nil
28+
put 'user/spree_user/password', to: 'user_passwords#update', as: nil
29+
post 'user/spree_user/password', to: 'user_passwords#create', as: nil
30+
get 'user/spree_user/cancel', to: 'user_registrations#cancel', as: nil
31+
get 'user/spree_user/sign_up', to: 'user_registrations#new', as: nil
32+
get 'user/spree_user/edit', to: 'user_registrations#edit', as: nil
33+
patch 'user/spree_user', to: 'user_registrations#update', as: nil
34+
put 'user/spree_user', to: 'user_registrations#update', as: nil
35+
delete 'user/spree_user', to: 'user_registrations#destroy', as: nil
36+
post 'user/spree_user', to: 'user_registrations#create', as: nil
37+
38+
# Legacy devise generated helpers
39+
# These helpers are deprecated but we still want to support them
40+
# in order to give existing stores an upgrade path.
41+
get '/login', to: 'user_sessions#new', as: :new_spree_user_session
42+
post '/login', to: 'user_sessions#create', as: :spree_user_session
43+
match '/logout', to: 'user_sessions#destroy', as: :destroy_spree_user_session, via: Devise.sign_out_via
44+
get '/password/recover', to: 'user_passwords#new', as: :new_spree_user_password
45+
get '/password/change', to: 'user_passwords#edit', as: :edit_spree_user_password
46+
patch '/password/change', to: 'user_passwords#update', as: :spree_user_password
47+
get '/spree_user/cancel', to: 'user_registrations#cancel', as: :cancel_spree_user_registration
48+
get '/signup', to: 'user_registrations#new', as: :new_spree_user_registration
49+
get '/spree_user/edit', to: 'user_registrations#edit', as: :edit_spree_user_registration
50+
patch '/spree_user', to: 'user_registrations#update', as: :spree_user_registration
51+
52+
# Custom devise routes
2253
get '/login', to: 'user_sessions#new', as: :login
2354
post '/login', to: 'user_sessions#create', as: :create_new_session
2455
match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via

spec/controllers/spree/user_passwords_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
it 'redirects to the new session path' do
1111
get :edit
1212
expect(response).to redirect_to(
13-
'http://test.host/user/spree_user/sign_in'
13+
'http://test.host/login'
1414
)
1515
end
1616

spec/features/checkout_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
# Need to do this now because the token stored in the DB is the encrypted version
112112
# The 'plain-text' version is sent in the email and there's one way to get that!
113113
reset_password_email = ActionMailer::Base.deliveries.first
114-
token_url_regex = /\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
114+
token_url_regex = /\/password\/change\?reset_password_token=(.*)$/
115115
token = token_url_regex.match(reset_password_email.body.to_s)[1]
116116

117117
visit spree.edit_spree_user_password_path(reset_password_token: token)

spec/mailers/user_mailer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
context 'body includes' do
3333
it 'password reset url' do
34-
expect(@message.body.raw_source).to include "http://#{store.url}/user/spree_user/password/edit"
34+
expect(@message.body.raw_source).to include "http://#{store.url}/password/change"
3535
end
3636
end
3737
end

0 commit comments

Comments
 (0)