gitlab-org--gitlab-foss/spec/models/email_spec.rb

67 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Email do
describe 'modules' do
subject { described_class }
it { is_expected.to include_module(AsyncDeviseEmail) }
end
describe 'validations' do
it_behaves_like 'an object with RFC3696 compliant email-formated attributes', :email do
subject { build(:email) }
end
end
it 'normalize email value' do
expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
.to eq 'info@example.com'
end
describe '#update_invalid_gpg_signatures' do
let(:user) { create(:user) }
it 'synchronizes the gpg keys when the email is updated' do
email = user.emails.create(email: 'new@email.com')
2017-10-01 11:07:26 -04:00
expect(user).to receive(:update_invalid_gpg_signatures)
2017-10-01 11:07:26 -04:00
email.confirm
end
end
describe 'scopes' do
let(:user) { create(:user) }
it 'scopes confirmed emails' do
create(:email, :confirmed, user: user)
create(:email, user: user)
2017-10-01 11:07:26 -04:00
expect(user.emails.count).to eq 2
expect(user.emails.confirmed.count).to eq 1
end
end
2017-10-27 11:35:40 -04:00
describe 'delegation' do
let(:user) { create(:user) }
2017-10-27 11:35:40 -04:00
it 'delegates to :user' do
expect(build(:email, user: user).username).to eq user.username
end
end
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
end