2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-04 13:23:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Profiles::EmailsController do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#create' do
|
2020-05-06 05:10:02 -04:00
|
|
|
context 'when email address is valid' do
|
|
|
|
let(:email_params) { { email: "add_email@example.com" } }
|
2017-09-04 13:23:33 -04:00
|
|
|
|
2020-05-06 05:10:02 -04:00
|
|
|
it 'sends an email confirmation' do
|
|
|
|
expect { post(:create, params: { email: email_params }) }.to change { ActionMailer::Base.deliveries.size }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when email address is invalid' do
|
|
|
|
let(:email_params) { { email: "test.@example.com" } }
|
|
|
|
|
|
|
|
it 'does not send an email confirmation' do
|
|
|
|
expect { post(:create, params: { email: email_params }) }.not_to change { ActionMailer::Base.deliveries.size }
|
|
|
|
end
|
2017-09-04 13:23:33 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-09 09:55:07 -04:00
|
|
|
|
|
|
|
describe '#resend_confirmation_instructions' do
|
2017-09-14 10:18:32 -04:00
|
|
|
let(:email_params) { { email: "add_email@example.com" } }
|
2017-09-09 09:55:07 -04:00
|
|
|
|
|
|
|
it 'resends an email confirmation' do
|
|
|
|
email = user.emails.create(email: 'add_email@example.com')
|
2017-10-01 11:07:26 -04:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
expect { put(:resend_confirmation_instructions, params: { id: email }) }.to change { ActionMailer::Base.deliveries.size }
|
2017-09-09 09:55:07 -04:00
|
|
|
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
|
2018-12-17 17:52:17 -05:00
|
|
|
expect { put(:resend_confirmation_instructions, params: { id: 1 }) }.not_to change { ActionMailer::Base.deliveries.size }
|
2017-09-09 09:55:07 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-04 13:23:33 -04:00
|
|
|
end
|