GRN2-xx: Restructured email verification and password reset (#1444)

* Restructured email verification and password reset

* Fixed issue with password reset

Co-authored-by: Jesus Federico <jesus@123it.ca>
This commit is contained in:
Ahmad Farhat
2020-04-29 17:56:46 -04:00
committed by GitHub
parent 8f3ba8a038
commit 28302107bd
10 changed files with 46 additions and 81 deletions

View File

@ -35,8 +35,7 @@ describe AccountActivationsController, type: :controller do
it "renders the verify view if the user is not signed in and is not verified" do
user = create(:user, email_verified: false, provider: "greenlight")
user.create_activation_token
get :show, params: { token: user.activation_token }
get :show, params: { token: user.create_activation_token }
expect(response).to render_template(:show)
end
@ -46,8 +45,7 @@ describe AccountActivationsController, type: :controller do
it "activates a user if they have the correct activation token" do
@user = create(:user, email_verified: false, provider: "greenlight")
@user.create_activation_token
get :edit, params: { token: @user.activation_token }
get :edit, params: { token: @user.create_activation_token }
@user.reload
expect(@user.email_verified).to eq(true)
@ -64,8 +62,7 @@ describe AccountActivationsController, type: :controller do
it "does not allow the user to click the verify link again" do
@user = create(:user, provider: "greenlight")
@user.create_activation_token
get :edit, params: { token: @user.activation_token }
get :edit, params: { token: @user.create_activation_token }
expect(flash[:alert]).to be_present
expect(response).to redirect_to(root_path)
end
@ -75,8 +72,7 @@ describe AccountActivationsController, type: :controller do
@user.add_role :pending
@user.create_activation_token
get :edit, params: { token: @user.activation_token }
get :edit, params: { token: @user.create_activation_token }
expect(flash[:success]).to be_present
expect(response).to redirect_to(root_path)
@ -87,8 +83,8 @@ describe AccountActivationsController, type: :controller do
it "resends the email to the current user if the resend button is clicked" do
user = create(:user, email_verified: false, provider: "greenlight")
user.create_activation_token
expect { get :resend, params: { token: user.activation_token } }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect { get :resend, params: { token: user.create_activation_token } }
.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(flash[:success]).to be_present
expect(response).to redirect_to(root_path)
end
@ -96,8 +92,7 @@ describe AccountActivationsController, type: :controller do
it "redirects a verified user to the root path" do
user = create(:user, provider: "greenlight")
user.create_activation_token
get :resend, params: { token: user.activation_token }
get :resend, params: { token: user.create_activation_token }
expect(flash[:alert]).to be_present
expect(response).to redirect_to(root_path)

View File

@ -81,8 +81,6 @@ describe PasswordResetsController, type: :controller do
context "valid user" do
it "reloads page with notice if password is empty" do
token = "reset_token"
allow(controller).to receive(:valid_user).and_return(nil)
allow(controller).to receive(:check_expiration).and_return(nil)
params = {
@ -99,7 +97,6 @@ describe PasswordResetsController, type: :controller do
it "reloads page with notice if password is confirmation doesn't match" do
token = "reset_token"
allow(controller).to receive(:valid_user).and_return(nil)
allow(controller).to receive(:check_expiration).and_return(nil)
params = {
@ -116,14 +113,12 @@ describe PasswordResetsController, type: :controller do
it "updates attributes if the password update is a success" do
user = create(:user, provider: "greenlight")
user.create_reset_digest
old_digest = user.password_digest
allow(controller).to receive(:valid_user).and_return(nil)
allow(controller).to receive(:check_expiration).and_return(nil)
params = {
id: user.reset_token,
id: user.create_reset_digest,
user: {
password: :password,
password_confirmation: :password,

View File

@ -138,8 +138,13 @@ describe User, type: :model do
it 'creates token and respective reset digest' do
user = create(:user)
reset_digest_success = user.create_reset_digest
expect(reset_digest_success).to eq(true)
expect(user.create_reset_digest).to be_truthy
end
it 'correctly verifies the token' do
user = create(:user)
token = user.create_reset_digest
expect(User.exists?(reset_digest: User.hash_token(token))).to be true
end
it 'verifies if password reset link expired' do