File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,8 +24,9 @@ def create
2424
2525 set_flash_message ( :notice , :send_instructions ) if is_navigational_format?
2626
27- if resource . errors . empty?
28- respond_with resource , location : admin_user_path ( resource )
27+ if successfully_sent? ( resource )
28+ location = ( spree_current_user && resource . persisted? ) ? admin_user_path ( resource ) : admin_login_path
29+ respond_with resource , location : location
2930 else
3031 respond_with_navigational ( resource ) { render :new }
3132 end
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def create
2020
2121 set_flash_message ( :notice , :send_instructions ) if is_navigational_format?
2222
23- if resource . errors . empty?
23+ if successfully_sent? ( resource )
2424 respond_with resource , location : spree . login_path
2525 else
2626 respond_with_navigational ( resource ) { render :new }
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33RSpec . describe Spree ::Admin ::UserPasswordsController , type : :controller do
4- before { @request . env [ "devise.mapping" ] = Devise . mappings [ :spree_user ] }
4+ before do
5+ @request . env [ "devise.mapping" ] = Devise . mappings [ :spree_user ]
6+ end
57
68 describe "#create" do
7- it "responds with success" do
9+ before do
10+ create ( :store )
11+ create ( :user , email : "admin@example.com" )
12+ end
13+
14+ it "redirects to the login page" do
815 post :create , params : { spree_user : { email : "admin@example.com" } }
916
1017 expect ( assigns [ :spree_user ] . email ) . to eq ( "admin@example.com" )
11- expect ( response . code ) . to eq ( "200" )
18+ expect ( response ) . to have_http_status ( 302 )
19+ end
20+
21+ context "when the user email is not found" do
22+ it "re-renders the form" do
23+ post :create , params : { spree_user : { email : "unknown@example.com" } }
24+
25+ expect ( response ) . to have_http_status ( 200 )
26+ expect ( response ) . to render_template :new
27+ end
28+
29+ context "when Devise is in paranoid mode" do
30+ around do |example |
31+ original_paranoid = Devise . paranoid
32+ Devise . paranoid = true
33+ example . run
34+ Devise . paranoid = original_paranoid
35+ end
36+
37+ it "does not reveal that the email is not found" do
38+ post :create , params : { spree_user : { email : "unknown@example.com" } }
39+
40+ expect ( response ) . to have_http_status ( 302 )
41+ end
42+ end
1243 end
1344 end
1445end
Original file line number Diff line number Diff line change 4242 end
4343 end
4444 end
45+
46+ describe "POST create" do
47+ before do
48+ create ( :store )
49+ create ( :user , email : "admin@example.com" )
50+ end
51+
52+ context "when the user email is not found" do
53+ it "re-renders the form" do
54+ post :create , params : { spree_user : { email : "unknown@example.com" } }
55+
56+ expect ( response ) . to have_http_status ( 200 )
57+ expect ( response ) . to render_template :new
58+ end
59+
60+ context "when Devise is in paranoid mode" do
61+ around do |example |
62+ original_paranoid = Devise . paranoid
63+ Devise . paranoid = true
64+ example . run
65+ Devise . paranoid = original_paranoid
66+ end
67+
68+ it "does not reveal that the email is not found" do
69+ post :create , params : { spree_user : { email : "unknown@example.com" } }
70+
71+ expect ( response ) . to have_http_status ( 302 )
72+ end
73+ end
74+ end
75+
76+ context "when the user email is found" do
77+ it "redirects back to the login page" do
78+ post :create , params : { spree_user : { email : "admin@example.com" } }
79+
80+ expect ( response ) . to redirect_to spree . login_path
81+ expect ( response ) . to have_http_status ( 302 )
82+ end
83+ end
84+ end
4585end
Original file line number Diff line number Diff line change 3636 if Spree . solidus_gem_version < Gem ::Version . new ( "2.11" )
3737 config . extend Spree ::TestingSupport ::AuthorizationHelpers ::Request , type : :system
3838 end
39+
40+ config . before ( :each , type : :controller ) do
41+ ActionMailer ::Base . default_url_options [ :host ] = "example.com"
42+ end
3943end
You can’t perform that action at this time.
0 commit comments