-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created initial PasswordResetsController and interactors. Specs currently red. Added password to User factory, this is duplicated in other branches.
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class PasswordResetsController < ApplicationController | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class PasswordResetOrganizer | ||
include Interactor::Organizer | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class UpdatePassword | ||
include Interactor | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters