BigW Consortium Gitlab

emails_controller_spec.rb 1.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
require 'spec_helper'

describe Profiles::EmailsController do
  let(:user) { create(:user) }

  before do
    sign_in(user)
  end

  describe '#create' do
Brett Walker committed
11
    let(:email_params) { { email: "add_email@example.com" } }
12 13

    it 'sends an email confirmation' do
14
      expect { post(:create, { email: email_params }) }.to change { ActionMailer::Base.deliveries.size }
15 16 17 18
      expect(ActionMailer::Base.deliveries.last.to).to eq [email_params[:email]]
      expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions"
    end
  end
19 20

  describe '#resend_confirmation_instructions' do
Brett Walker committed
21
    let(:email_params) { { email: "add_email@example.com" } }
22 23 24

    it 'resends an email confirmation' do
      email = user.emails.create(email: 'add_email@example.com')
25 26

      expect { put(:resend_confirmation_instructions, { id: email }) }.to change { ActionMailer::Base.deliveries.size }
27 28 29 30 31
      expect(ActionMailer::Base.deliveries.last.to).to eq [email_params[:email]]
      expect(ActionMailer::Base.deliveries.last.subject).to match "Confirmation instructions"
    end

    it 'unable to resend an email confirmation' do
32
      expect { put(:resend_confirmation_instructions, { id: 1 }) }.not_to change { ActionMailer::Base.deliveries.size }
33 34
    end
  end
35
end