Commit df4dbc79

mo khan <mo@mokhan.ca>
2014-09-18 16:17:51
add page to reset the password.
1 parent 47181c1
Changed files (4)
app/controllers/passwords_controller.rb
@@ -7,4 +7,9 @@ class PasswordsController < ApplicationController
     PasswordReset.send_reset_instructions_to(params[:user][:email])
     redirect_to new_session_path, notice: 'Password reset instructions have been emailed to you.'
   end
+
+  def edit
+    @user = User.find_by(reset_password_token: params[:id])
+    redirect_to root_path if @user.nil?
+  end
 end
app/views/passwords/edit.html.erb
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, :create]
+  resources :passwords, only: [:new, :create, :edit]
   resource :registration, only: [:create]
 
   # sitemap
spec/controllers/passwords_controller_spec.rb
@@ -21,4 +21,21 @@ describe PasswordsController do
       expect(flash[:notice]).to_not be_empty
     end
   end
+
+  describe "#edit" do
+    let(:reset_token) { SecureRandom.hex(32) }
+    let(:user) { build(:user) }
+
+    it "loads the password reset token" do
+      allow(User).to receive(:find_by).with(reset_password_token: reset_token).and_return(user)
+      get :edit, id: reset_token
+      expect(assigns(:user)).to eql(user)
+    end
+
+    it "redirects to the homepage if the user cannot be found" do
+      allow(User).to receive(:find_by).with(reset_password_token: reset_token).and_return(nil)
+      get :edit, id: reset_token
+      expect(response).to redirect_to(root_path)
+    end
+  end
 end