Add flash message for email confirmation (#12450)

* Add flash message for email confirmation

* Fix spec
This commit is contained in:
Michael Kohl 2021-01-28 09:32:04 +07:00 committed by GitHub
parent e46b537e91
commit 12a8fbddb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View file

@ -0,0 +1,13 @@
class ConfirmationsController < Devise::ConfirmationsController
FLASH_MESSAGE = "Email sent! Please contact support at %<email>s if you are "\
"having trouble receiving your confirmation instructions.".freeze
def create
self.resource = resource_class.send_confirmation_instructions(resource_params)
resource.errors.clear # Don't leak user information, like paranoid mode.
message = format(FLASH_MESSAGE, email: SiteConfig.email_addresses[:members])
flash.now[:global_notice] = message
render :new
end
end

View file

@ -11,12 +11,13 @@ Rails.application.routes.draw do
omniauth_callbacks: "omniauth_callbacks",
registrations: "registrations",
invitations: "invitations",
passwords: "passwords"
passwords: "passwords",
confirmations: "confirmations"
}
devise_scope :user do
get "/enter", to: "registrations#new", as: :sign_up
get "/confirm-email", to: "devise/confirmations#new"
get "/confirm-email", to: "confirmations#new"
delete "/sign_out", to: "devise/sessions#destroy"
end

View file

@ -0,0 +1,14 @@
require "rails_helper"
RSpec.describe "/confirm-email", type: :system do
it "stays on the same page and displays a flash message", :aggregate_failures do
visit confirm_email_path
fill_in "user_email", with: "test@example.com"
click_button "Resend confirmation instructions"
expect(page).to have_current_path(user_confirmation_path)
expected_message = format(ConfirmationsController::FLASH_MESSAGE,
email: SiteConfig.email_addresses[:members])
expect(page).to have_content(expected_message)
end
end