File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,19 @@ def create
1818 notice : "If the account exists you will receive an email or SMS with instructions on how to reset your password in a few minutes."
1919 end
2020
21+ def update
22+ self . resource = resource_class . reset_password_by_token ( resource_params )
23+
24+ yield resource if block_given?
25+
26+ if resource . errors . empty?
27+ flash [ :notice ] = "Your password has been changed successfully."
28+ redirect_to new_session_path ( resource_name )
29+ else
30+ respond_with resource
31+ end
32+ end
33+
2134 private
2235
2336 def render_error
Original file line number Diff line number Diff line change 123123 end
124124 end
125125 end
126+
127+ describe "PUT /update" do
128+ let ( :token ) do
129+ raw_token , enc_token = Devise . token_generator . generate ( User , :reset_password_token )
130+ user . update! ( reset_password_token : enc_token , reset_password_sent_at : Time . current )
131+ raw_token
132+ end
133+
134+ let ( :params ) do
135+ {
136+ user : {
137+ reset_password_token : token ,
138+ password : "newpassword123!" ,
139+ password_confirmation : "newpassword123!"
140+ }
141+ }
142+ end
143+
144+ subject ( :submit_reset ) { put user_password_path , params : params }
145+
146+ it "successfully resets the password" do
147+ submit_reset
148+ expect ( response ) . to redirect_to ( new_user_session_path )
149+ expect ( flash [ :notice ] ) . to eq ( "Your password has been changed successfully." )
150+ end
151+ end
126152end
You can’t perform that action at this time.
0 commit comments