add verified/unverified labels to profile emails.

added "Resend confirmation email" for unverified emails
This commit is contained in:
Brett Walker 2017-09-09 15:55:07 +02:00
parent c56208f980
commit cf8a5bcaec
7 changed files with 83 additions and 10 deletions

View File

@ -24,6 +24,16 @@ class Profiles::EmailsController < Profiles::ApplicationController
end
end
def resend_confirmation_instructions
@email = current_user.emails.find(params[:id])
if @email && Emails::ConfirmService.new(current_user, email: @email.email).execute
flash[:notice] = "Confirmation email sent to #{@email.email}"
else
flash[:alert] = "There was a problem sending the confirmation email"
end
redirect_to profile_emails_url
end
private
def email_params

View File

@ -0,0 +1,7 @@
module Emails
class ConfirmService < ::Emails::BaseService
def execute
Email.find_by_email!(@email).resend_confirmation_instructions
end
end
end

View File

@ -32,7 +32,7 @@
All email addresses will be used to identify your commits.
%ul.well-list
%li
= @primary
= render partial: 'shared/email_with_badge', locals: { email: @primary, verified: current_user.confirmed? }
%span.pull-right
%span.label.label-success Primary email
- if @primary === current_user.public_email
@ -41,12 +41,17 @@
%span.label.label-info Notification email
- @emails.each do |email|
%li
= email.email
= render partial: 'shared/email_with_badge', locals: { email: email.email, verified: email.confirmed? }
%span.pull-right
- if email.email === current_user.public_email
%span.label.label-info Public email
- if email.email === current_user.notification_email
%span.label.label-info Notification email
- unless email.confirmed?
%span.label.label-warning Unconfirmed
= link_to 'Remove', profile_email_path(email), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-warning prepend-left-10'
- confirm_title = "#{email.confirmation_sent_at ? 'Resend' : 'Send'} confirmation email"
= link_to confirm_title, resend_confirmation_instructions_profile_email_path(email), method: :put, class: 'btn btn-sm btn-warning prepend-left-10'
= link_to profile_email_path(email), data: { confirm: 'Are you sure?'}, method: :delete, class: 'btn btn-sm btn-danger prepend-left-10' do
%span.sr-only Remove
= icon('trash')

View File

@ -28,7 +28,11 @@ resource :profile, only: [:show, :update] do
put :revoke
end
end
resources :emails, only: [:index, :create, :destroy]
resources :emails, only: [:index, :create, :destroy] do
member do
put :resend_confirmation_instructions
end
end
resources :chat_names, only: [:index, :new, :create, :destroy] do
collection do
delete :deny

View File

@ -17,4 +17,19 @@ describe Profiles::EmailsController do
expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions"
end
end
describe '#resend_confirmation_instructions' do
let(:email_params) { {email: "add_email@example.com" } }
it 'resends an email confirmation' do
email = user.emails.create(email: 'add_email@example.com')
expect {put(:resend_confirmation_instructions, { id: email })}.to change { ActionMailer::Base.deliveries.size }
expect(ActionMailer::Base.deliveries.last.to).to eq [email_params[:email]]
expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions"
end
it 'unable to resend an email confirmation' do
expect {put(:resend_confirmation_instructions, { id: 1 })}.to_not change { ActionMailer::Base.deliveries.size }
end
end
end

View File

@ -17,8 +17,8 @@ feature 'Profile > Emails' do
click_button('Add email address')
expect(page).to have_content('my@email.com Unverified')
expect(page).to have_content('user1@example.org Verified')
expect(page).to have_content('Resend Confirmation Email')
expect(page).to have_content("#{user.email} Verified")
expect(page).to have_content('Resend confirmation email')
end
scenario 'does not add a duplicate email' do
@ -43,14 +43,30 @@ feature 'Profile > Emails' do
scenario 'User confirms email' do
email = user.emails.create(email: 'my@email.com')
visit profile_emails_path
expect(page).to have_content("my@email.com Unverified")
expect(page).to have_content("#{email.email} Unverified")
email.confirm
expect(email.confirmed?).to be_truthy
visit profile_emails_path
expect(page).to have_content("my@email.com Verified")
expect(page).to have_content("#{email.email} Verified")
end
scenario 'User re-sends confirmation email' do
email = user.emails.create(email: 'my@email.com')
visit profile_emails_path
expect { click_link("Resend confirmation email") }.to change { ActionMailer::Base.deliveries.size }
expect(page).to have_content("Confirmation email sent to #{email.email}")
end
scenario 'old unconfirmed emails show Send Confirmation button' do
email = user.emails.create(email: 'my@email.com')
email.update_attribute(:confirmation_sent_at, nil)
visit profile_emails_path
expect(page).to_not have_content('Resend confirmation email')
expect(page).to have_content('Send confirmation email')
end
scenario ''
end

View File

@ -0,0 +1,16 @@
require 'spec_helper'
describe Emails::ConfirmService do
let(:user) { create(:user) }
let(:opts) { { email: 'new@email.com' } }
subject(:service) { described_class.new(user, opts) }
describe '#execute' do
it 'sends a confirmation email again' do
email = user.emails.create(email: opts[:email])
mail = service.execute
expect(mail.subject).to eq('Confirmation instructions')
end
end
end