2016-04-21 14:55:54 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RegistrationsController do
|
|
|
|
describe '#create' do
|
2017-01-03 02:08:21 -05:00
|
|
|
let(:user_params) { { user: { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password' } } }
|
|
|
|
|
|
|
|
context 'email confirmation' do
|
|
|
|
around(:each) do |example|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
example.run
|
|
|
|
end
|
2016-04-21 14:55:54 -04:00
|
|
|
end
|
|
|
|
|
2017-01-03 02:08:21 -05:00
|
|
|
context 'when send_user_confirmation_email is false' do
|
|
|
|
it 'signs the user in' do
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:send_user_confirmation_email).and_return(false)
|
|
|
|
|
|
|
|
expect { post(:create, user_params) }.not_to change{ ActionMailer::Base.deliveries.size }
|
|
|
|
expect(subject.current_user).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-04-21 14:55:54 -04:00
|
|
|
|
2017-01-03 02:08:21 -05:00
|
|
|
context 'when send_user_confirmation_email is true' do
|
|
|
|
it 'does not authenticate user and sends confirmation email' do
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:send_user_confirmation_email).and_return(true)
|
2016-04-21 14:55:54 -04:00
|
|
|
|
2017-01-03 02:08:21 -05:00
|
|
|
post(:create, user_params)
|
|
|
|
|
|
|
|
expect(ActionMailer::Base.deliveries.last.to.first).to eq(user_params[:user][:email])
|
|
|
|
expect(subject.current_user).to be_nil
|
|
|
|
end
|
2016-04-21 14:55:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-03 02:08:21 -05:00
|
|
|
context 'when reCAPTCHA is enabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(recaptcha_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays an error when the reCAPTCHA is not solved' do
|
|
|
|
# Without this, `verify_recaptcha` arbitraily returns true in test env
|
|
|
|
Recaptcha.configuration.skip_verify_env.delete('test')
|
2016-04-21 14:55:54 -04:00
|
|
|
|
|
|
|
post(:create, user_params)
|
2017-01-03 02:08:21 -05:00
|
|
|
|
|
|
|
expect(response).to render_template(:new)
|
|
|
|
expect(flash[:alert]).to include 'There was an error with the reCAPTCHA. Please re-solve the reCAPTCHA.'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to the dashboard when the recaptcha is solved' do
|
|
|
|
# Avoid test ordering issue and ensure `verify_recaptcha` returns true
|
|
|
|
unless Recaptcha.configuration.skip_verify_env.include?('test')
|
|
|
|
Recaptcha.configuration.skip_verify_env << 'test'
|
|
|
|
end
|
|
|
|
|
|
|
|
post(:create, user_params)
|
|
|
|
|
|
|
|
expect(flash[:notice]).to include 'Welcome! You have signed up successfully.'
|
2016-04-21 14:55:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|