BigW Consortium Gitlab

email_spec.rb 1.19 KB
Newer Older
1 2
require 'spec_helper'

3
describe Email do
4 5 6 7 8
  describe 'validations' do
    it_behaves_like 'an object with email-formated attributes', :email do
      subject { build(:email) }
    end
  end
9 10 11 12 13

  it 'normalize email value' do
    expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
      .to eq 'info@example.com'
  end
14 15 16 17 18 19 20 21 22 23 24

  describe '#update_invalid_gpg_signatures' do
    let(:user) do
      create(:user, email: 'tula.torphy@abshire.ca').tap do |user|
        user.skip_reconfirmation!
      end
    end
    let(:user) { create(:user) }

    it 'synchronizes the gpg keys when the email is updated' do
      email = user.emails.create(email: 'new@email.com')
25

26
      expect(user).to receive(:update_invalid_gpg_signatures)
27

28 29 30
      email.confirm
    end
  end
31

32 33 34 35 36
  describe 'scopes' do
    let(:user) { create(:user) }

    it 'scopes confirmed emails' do
      create(:email, :confirmed, user: user)
37
      create(:email, user: user)
38

39
      expect(user.emails.count).to eq 2
40 41 42
      expect(user.emails.confirmed.count).to eq 1
    end
  end
Brett Walker committed
43

44 45
  describe 'delegation' do
    let(:user) { create(:user) }
Brett Walker committed
46

47 48 49 50
    it 'delegates to :user' do
      expect(build(:email, user: user).username).to eq user.username
    end
  end
51
end