From 985ab4faadf332602647135136cd949581c6ece6 Mon Sep 17 00:00:00 2001 From: Iraline Date: Wed, 27 Apr 2022 12:04:16 -0300 Subject: [PATCH] Tests to validate the flow of token already used --- .../users/confirmations_controller_spec.rb | 8 +++++++ spec/system/users_auth_spec.rb | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/spec/controllers/users/confirmations_controller_spec.rb b/spec/controllers/users/confirmations_controller_spec.rb index 8cc54549d..d2209683a 100644 --- a/spec/controllers/users/confirmations_controller_spec.rb +++ b/spec/controllers/users/confirmations_controller_spec.rb @@ -9,5 +9,13 @@ describe Users::ConfirmationsController do it "returns a 404 code with a wrong token" do expect { get :show, params: { token: "non_existent" } }.to raise_error ActiveRecord::RecordNotFound end + + it "redirect to sign_in page with a existent token " do + user = create(:user, confirmation_token: "token1") + + get :show, params: { user: user, confirmation_token: "token1" } + + expect(response).to redirect_to(new_user_session_path) + end end end diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index 02eadcfd3..2afa44c6b 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -30,6 +30,30 @@ describe "Users" do expect(page).to have_content error_message end + + scenario "User already confirmed email with the token" do + message = "You have been sent a message containing a verification link. Please click on this link to activate your account." + visit "/" + click_link "Register" + + fill_in "Username", with: "Manuela Carmena" + fill_in "Email", with: "manuela@consul.dev" + fill_in "Password", with: "judgementday" + fill_in "Confirm password", with: "judgementday" + check "user_terms_of_service" + + click_button "Register" + + expect(page).to have_content message + + confirm_email + expect(page).to have_content "Your account has been confirmed." + + sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit user_confirmation_path(confirmation_token: sent_token) + + expect(page).to have_content "You have already been verified; please attempt to sign in." + end end context "Sign in" do