2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Email do
|
2020-05-24 23:13:21 +05:30
|
|
|
describe 'modules' do
|
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
it { is_expected.to include_module(AsyncDeviseEmail) }
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe 'validations' do
|
2021-04-17 20:07:23 +05:30
|
|
|
it_behaves_like 'an object with RFC3696 compliant email-formatted attributes', :email do
|
2016-04-02 18:10:28 +05:30
|
|
|
subject { build(:email) }
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
context 'when the email conflicts with the primary email of a different user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:email) { build(:email, email: user.email) }
|
|
|
|
|
|
|
|
it 'is invalid' do
|
|
|
|
expect(email).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'normalize email value' do
|
|
|
|
expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
|
|
|
|
.to eq 'info@example.com'
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe '#update_invalid_gpg_signatures' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'synchronizes the gpg keys when the email is updated' do
|
2021-09-04 01:27:46 +05:30
|
|
|
email = user.emails.create!(email: 'new@email.com')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(user).to receive(:update_invalid_gpg_signatures)
|
|
|
|
|
|
|
|
email.confirm
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'scopes' do
|
2021-12-11 22:18:48 +05:30
|
|
|
let(:user) { create(:user, :unconfirmed) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'scopes confirmed emails' do
|
|
|
|
create(:email, :confirmed, user: user)
|
|
|
|
create(:email, user: user)
|
|
|
|
|
|
|
|
expect(user.emails.count).to eq 2
|
|
|
|
expect(user.emails.confirmed.count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
describe 'delegations' do
|
|
|
|
it { is_expected.to delegate_method(:can?).to(:user) }
|
|
|
|
it { is_expected.to delegate_method(:username).to(:user) }
|
|
|
|
it { is_expected.to delegate_method(:pending_invitations).to(:user) }
|
|
|
|
it { is_expected.to delegate_method(:accept_pending_invitations!).to(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe 'Devise emails' do
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe 'behaviour' do
|
|
|
|
it 'sends emails asynchronously' do
|
|
|
|
expect do
|
|
|
|
user.emails.create!(email: 'hello@hello.com')
|
|
|
|
end.to have_enqueued_job.on_queue('mailers')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|