2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-09 09:51:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Email do
|
2016-02-09 09:51:06 -05:00
|
|
|
describe 'validations' do
|
2020-05-06 05:10:02 -04:00
|
|
|
it_behaves_like 'an object with RFC3696 compliant email-formated attributes', :email do
|
2016-02-09 09:51:06 -05:00
|
|
|
subject { build(:email) }
|
|
|
|
end
|
|
|
|
end
|
2016-05-23 05:19:27 -04:00
|
|
|
|
|
|
|
it 'normalize email value' do
|
|
|
|
expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
|
|
|
|
.to eq 'info@example.com'
|
|
|
|
end
|
2017-09-18 08:50:32 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-09-18 08:50:32 -04:00
|
|
|
expect(user).to receive(:update_invalid_gpg_signatures)
|
2017-10-01 11:07:26 -04:00
|
|
|
|
2017-09-18 08:50:32 -04:00
|
|
|
email.confirm
|
|
|
|
end
|
|
|
|
end
|
2017-09-24 13:52:49 -04:00
|
|
|
|
2017-09-20 07:24:10 -04:00
|
|
|
describe 'scopes' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'scopes confirmed emails' do
|
|
|
|
create(:email, :confirmed, user: user)
|
2017-09-20 08:51:27 -04:00
|
|
|
create(:email, user: user)
|
2017-10-01 11:07:26 -04:00
|
|
|
|
2017-09-20 08:51:27 -04:00
|
|
|
expect(user.emails.count).to eq 2
|
2017-09-20 07:24:10 -04:00
|
|
|
expect(user.emails.confirmed.count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
2017-10-27 11:35:40 -04:00
|
|
|
|
2017-10-27 10:32:48 -04:00
|
|
|
describe 'delegation' do
|
|
|
|
let(:user) { create(:user) }
|
2017-10-27 11:35:40 -04:00
|
|
|
|
2017-10-27 10:32:48 -04:00
|
|
|
it 'delegates to :user' do
|
|
|
|
expect(build(:email, user: user).username).to eq user.username
|
|
|
|
end
|
|
|
|
end
|
2016-02-09 09:51:06 -05:00
|
|
|
end
|