Commit 47181c19
Changed files (4)
app
controllers
models
config
spec
controllers
app/controllers/passwords_controller.rb
@@ -2,4 +2,9 @@ class PasswordsController < ApplicationController
def new
@user = User.new
end
+
+ def create
+ PasswordReset.send_reset_instructions_to(params[:user][:email])
+ redirect_to new_session_path, notice: 'Password reset instructions have been emailed to you.'
+ end
end
app/models/password_reset.rb
@@ -0,0 +1,4 @@
+class PasswordReset
+ def self.send_reset_instructions_to(email)
+ end
+end
config/routes.rb
@@ -52,7 +52,7 @@ Cake::Application.routes.draw do
# /users
#devise_for :users, :controllers => {:registrations => 'registrations'}, :path => '', :path_names => { :sign_in => "signin", :sign_out => "signout", :sign_up => "register" }
- resources :passwords, only: [:new]
+ resources :passwords, only: [:new, :create]
resource :registration, only: [:create]
# sitemap
spec/controllers/passwords_controller_spec.rb
@@ -7,4 +7,18 @@ describe PasswordsController do
expect(assigns(:user)).to be_new_record
end
end
+
+ describe "#create" do
+ let(:email) { Faker::Internet.email }
+
+ it "sends a password reset email for the user" do
+ allow(PasswordReset).to receive(:send_reset_instructions_to)
+
+ post :create, user: { email: email }
+
+ expect(PasswordReset).to have_received(:send_reset_instructions_to).with(email)
+ expect(response).to redirect_to(new_session_path)
+ expect(flash[:notice]).to_not be_empty
+ end
+ end
end