Commit abd0d42c authored by Martin Tan's avatar Martin Tan Committed by Alex Pooley

Refactor: add prepend mod to trail registrations controller

parent 9f4f8a74
......@@ -42,13 +42,19 @@ class TrialRegistrationsController < RegistrationsController
def sign_up_params
if params[:user]
params.require(:user).permit(:first_name, :last_name, :username, :email, :password, :skip_confirmation, :email_opted_in)
params.require(:user).permit(*sign_up_params_attributes)
else
{}
end
end
def sign_up_params_attributes
[:first_name, :last_name, :username, :email, :password, :skip_confirmation, :email_opted_in]
end
def resource
@resource ||= Users::AuthorizedBuildService.new(current_user, sign_up_params).execute
end
end
TrialRegistrationsController.prepend_mod
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe TrialRegistrationsController do
let(:com) { true }
before do
allow(Gitlab).to receive(:com?).and_return(com)
end
describe 'POST new' do
let(:user_params) do
build_stubbed(:user)
.slice(:first_name, :last_name, :email, :username, :password)
end
context 'when email_opted_in does not exist in params' do
it 'sets user email_opted_in to false' do
post trial_registrations_path, params: { user: user_params }
expect(response).to have_gitlab_http_status(:found)
expect(User.last.email_opted_in).to be_nil
end
end
context 'when email_opted_in is true in params' do
it 'sets user email_opted_in to true' do
post trial_registrations_path, params: {
user: user_params.merge(email_opted_in: true)
}
expect(response).to have_gitlab_http_status(:found)
expect(User.last.email_opted_in).to be true
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment