Skip to content

Commit

Permalink
first pass on password reset specs
Browse files Browse the repository at this point in the history
created initial PasswordResetsController and interactors. Specs
currently red.

Added password to User factory, this is duplicated in other branches.
  • Loading branch information
npauzenga committed Dec 16, 2015
1 parent 8b05deb commit ef122a5
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/password_resets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class PasswordResetsController < ApplicationController

end
4 changes: 4 additions & 0 deletions app/interactors/password_reset_organizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PasswordResetOrganizer
include Interactor::Organizer

end
3 changes: 3 additions & 0 deletions app/interactors/update_password.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class UpdatePassword
include Interactor
end
111 changes: 111 additions & 0 deletions spec/controllers/password_resets_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
RSpec.describe PasswordResetsController do
describe "POST #create" do
let(:user) { create(:confirmed_user) }
let(:params) { { password_reset: { email: user.email } } }
let(:arguments) { { email: user.email } }
let(:context) { double(:context, success?: true) }

before(:example) do
allow(PasswordResetOrganizer).to receive(:call).with(arguments).
and_return(context)
end

it "calls PasswordResetOrganizer" do
expect(PasswordResetOrganizer).to receive(:call)
post :create, params
end

context "when successful" do
it "returns HTTP status 201" do
post :create, params
expect(response).to have_http_status(201)
end

it "redirects to index" do
post :create, params
expect(response).to redirect_to("/")
end

it "renders a success notice" do
post :create, params
expect(JSON.parse(response.body)).to eq(password: ["reset sent"])
end
end

context "when unsuccessful" do
let(:context) { double(:context, success?: false) }

it "returns HTTP status 404" do
post :create, params
expect(response).to have_http_status(404)
end

it "redirects to index" do
post :create, params
expect(response).to redirect_to("/")
end

it "renders an error" do
post :create, params
expect(JSON.parse(response.body)).to eq(password: ["reset failed"])
end
end
end

describe "PATCH #udpate" do
let(:user) { create(:confirmed_user) }
let(:params) { { password_reset: { email: user.email } } }
let(:arguments) { { user_params: user_params, user: user } }
let(:context) { double(:context, success?: true) }

let(:user_params) do
{ password: user.password }
end

before(:example) do
allow(UpdatePassword).to receive(:call).with(arguments).
and_return(context)
end

it "calls UpdatePassword interactor" do
expect(UpdatePassword).to receive(:call)
patch :update, params
end

context "when successful" do
it "returns HTTP status 200" do
patch :update, params
expect(response).to have_http_status(200)
end

it "redirects to /signin" do
patch :update, params
expect(response).to redirect_to("/signin")
end

it "renders a success notice" do
patch :update, params
expect(JSON.parse(response.body)).to eq(password: ["password updated"])
end
end

context "when unsuccessful" do
let(:context) { double(:context, success?: false) }

it "returns HTTP status 500" do
patch :update, params
expect(response).to have_http_status(500)
end

it "redirects to index" do
patch :update, params
expect(response).to redirect_to("/")
end

it "renders an error" do
patch :update, params
expect(JSON.parse(response.body)).to eq(password: ["update failed"])
end
end
end
end
1 change: 1 addition & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
city Faker::Address.city
state Faker::Address.state
country Faker::Address.country
password "helloworld"
email_confirmed true
end

Expand Down

0 comments on commit ef122a5

Please sign in to comment.