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

describe RegistrationsController do
  describe '#create' do
    around(:each) do |example|
      perform_enqueued_jobs do
        example.run
      end
    end

11
    let(:user_params) { { user: { name: "new_user", username: "new_username", email: "new@user.com", password: "Any_password" } } }
12

13 14
    context 'when sending email confirmation' do
      before { allow(current_application_settings).to receive(:send_user_confirmation_email).and_return(false) }
15 16 17 18

      it 'logs user in directly' do
        post(:create, user_params)
        expect(ActionMailer::Base.deliveries.last).to be_nil
19
        expect(subject.current_user).to_not be_nil
20 21 22
      end
    end

23 24
    context 'when not sending email confirmation' do
      before { allow(current_application_settings).to receive(:send_user_confirmation_email).and_return(true) }
25 26 27

      it 'does not authenticate user and sends confirmation email' do
        post(:create, user_params)
28
        expect(ActionMailer::Base.deliveries.last.to.first).to eq(user_params[:user][:email])
29 30 31 32 33
        expect(subject.current_user).to be_nil
      end
    end
  end
end