Commit 2fa8d8f6 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'move-variables-and-logic-from-trials-select-view-to-helper-methods' into 'master'

Move variables & logic from view into helpers

See merge request gitlab-org/gitlab!41035
parents 3dc7c5bf 257c7f39
......@@ -13,6 +13,16 @@ module EE
], selected)
end
def should_ask_company_question?
glm_params[:glm_source] != 'about.gitlab.com'
end
def glm_params
strong_memoize(:glm_params) do
params.slice(:glm_source, :glm_content).to_unsafe_h
end
end
def namespace_options_for_select(selected = nil)
grouped_options = {
'New' => [[_('Create group'), 0]],
......
- page_title _('Start a Free Gold Trial')
- glm_params = { glm_source: params[:glm_source], glm_content: params[:glm_content] }
- should_ask_company_question = glm_params[:glm_source] != 'about.gitlab.com'
%h3.center.pt-6
= _('Almost there')
......@@ -17,7 +15,7 @@
#group_name.form-group.hidden
= label_tag :new_group_name, _('New Group Name'), for: :new_group_name, class: 'col-form-label'
= text_field_tag :new_group_name, nil, class: 'form-control'
- if should_ask_company_question
- if should_ask_company_question?
.form-group
= label_tag :trial_entity, _('Is this GitLab trial for your company?')
.gl-form-checkbox-group
......
......@@ -5,6 +5,62 @@ require 'spec_helper'
RSpec.describe EE::TrialHelper do
using RSpec::Parameterized::TableSyntax
describe '#should_ask_company_question?' do
before do
allow(helper).to receive(:glm_params).and_return(glm_source ? { glm_source: glm_source } : {})
end
subject { helper.should_ask_company_question? }
where(:glm_source, :result) do
'about.gitlab.com' | false
'abouts.gitlab.com' | true
'about.gitlab.org' | true
'about.gitlob.com' | true
nil | true
end
with_them do
it { is_expected.to eq(result) }
end
end
describe '#glm_params' do
let(:glm_source) { nil }
let(:glm_content) { nil }
let(:params) do
ActionController::Parameters.new({
controller: 'FooBar', action: 'stuff', id: '123'
}.tap do |p|
p[:glm_source] = glm_source if glm_source
p[:glm_content] = glm_content if glm_content
end)
end
before do
allow(helper).to receive(:params).and_return(params)
end
subject { helper.glm_params }
it 'is memoized' do
expect(helper).to receive(:strong_memoize)
subject
end
where(:glm_source, :glm_content, :result) do
nil | nil | {}
'source' | nil | { glm_source: 'source' }
nil | 'content' | { glm_content: 'content' }
'source' | 'content' | { glm_source: 'source', glm_content: 'content' }
end
with_them do
it { is_expected.to eq(HashWithIndifferentAccess.new(result)) }
end
end
describe '#namespace_options_for_select' do
let_it_be(:user) { create :user }
let_it_be(:group1) { create :group }
......
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