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