2016-04-21 14:55:54 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RegistrationsController do
|
|
|
|
describe '#create' do
|
|
|
|
around(:each) do |example|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
example.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-28 16:09:15 -04:00
|
|
|
let(:user_params) { { user: { name: "new_user", username: "new_username", email: "new@user.com", password: "Any_password" } } }
|
2016-04-21 14:55:54 -04:00
|
|
|
|
2016-04-28 16:09:15 -04:00
|
|
|
context 'when sending email confirmation' do
|
2016-05-27 22:05:52 -04:00
|
|
|
before { allow_any_instance_of(ApplicationSetting).to receive(:send_user_confirmation_email).and_return(false) }
|
2016-04-21 14:55:54 -04:00
|
|
|
|
|
|
|
it 'logs user in directly' do
|
2016-07-05 00:50:32 -04:00
|
|
|
expect { post(:create, user_params) }.not_to change{ ActionMailer::Base.deliveries.size }
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(subject.current_user).not_to be_nil
|
2016-04-21 14:55:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-28 16:09:15 -04:00
|
|
|
context 'when not sending email confirmation' do
|
2016-05-27 22:05:52 -04:00
|
|
|
before { allow_any_instance_of(ApplicationSetting).to receive(:send_user_confirmation_email).and_return(true) }
|
2016-04-21 14:55:54 -04:00
|
|
|
|
|
|
|
it 'does not authenticate user and sends confirmation email' do
|
|
|
|
post(:create, user_params)
|
2016-04-28 16:09:15 -04:00
|
|
|
expect(ActionMailer::Base.deliveries.last.to.first).to eq(user_params[:user][:email])
|
2016-04-21 14:55:54 -04:00
|
|
|
expect(subject.current_user).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|