debian-mirror-gitlab/spec/controllers/profiles/emails_controller_spec.rb

52 lines
1.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
describe Profiles::EmailsController do
let(:user) { create(:user) }
before do
sign_in(user)
end
2020-05-24 23:13:21 +05:30
around do |example|
perform_enqueued_jobs do
example.run
end
end
2018-03-17 18:26:18 +05:30
describe '#create' do
2020-05-24 23:13:21 +05:30
context 'when email address is valid' do
let(:email_params) { { email: "add_email@example.com" } }
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
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
2018-03-17 18:26:18 +05:30
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')
2019-02-15 15:39:39 +05:30
expect { put(:resend_confirmation_instructions, params: { id: email }) }.to change { ActionMailer::Base.deliveries.size }
2018-03-17 18:26:18 +05:30
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
2019-02-15 15:39:39 +05:30
expect { put(:resend_confirmation_instructions, params: { id: 1 }) }.not_to change { ActionMailer::Base.deliveries.size }
2018-03-17 18:26:18 +05:30
end
end
end