diff options
| author | mo khan <mo@mokhan.ca> | 2014-09-18 10:11:14 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-09-18 10:11:14 -0600 |
| commit | 47181c1901d1cbc2afc974ed60f4730a5468600c (patch) | |
| tree | 99b9c781f23650239aa167bbae141257805c1b37 | |
| parent | 3f346fd2b4b226a013e6dc9d3b959cf1f3a66428 (diff) | |
add action to send reset password instructions.
| -rw-r--r-- | app/controllers/passwords_controller.rb | 5 | ||||
| -rw-r--r-- | app/models/password_reset.rb | 4 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/passwords_controller_spec.rb | 14 |
4 files changed, 24 insertions, 1 deletions
diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index 07431017..695fc10c 100644 --- a/app/controllers/passwords_controller.rb +++ b/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 diff --git a/app/models/password_reset.rb b/app/models/password_reset.rb new file mode 100644 index 00000000..2ba208d5 --- /dev/null +++ b/app/models/password_reset.rb @@ -0,0 +1,4 @@ +class PasswordReset + def self.send_reset_instructions_to(email) + end +end diff --git a/config/routes.rb b/config/routes.rb index d811c9e8..27bf2646 100644 --- a/config/routes.rb +++ b/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 diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index c6e5121f..ab353d74 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/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 |
