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