Commit 257c7f39 authored by Dallas Reedy's avatar Dallas Reedy Committed by Ash McKenzie

Move variables & logic from view into helpers

This cleans up the view and adheres to the principle of “Fat Helpers,
Skinny Views” (I’m not sure that’s a real thing, but I like it).
parent 8f2f7442
...@@ -13,6 +13,16 @@ module EE ...@@ -13,6 +13,16 @@ module EE
], selected) ], selected)
end 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) def namespace_options_for_select(selected = nil)
grouped_options = { grouped_options = {
'New' => [[_('Create group'), 0]], 'New' => [[_('Create group'), 0]],
......
- page_title _('Start a Free Gold Trial') - 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 %h3.center.pt-6
= _('Almost there') = _('Almost there')
...@@ -17,7 +15,7 @@ ...@@ -17,7 +15,7 @@
#group_name.form-group.hidden #group_name.form-group.hidden
= label_tag :new_group_name, _('New Group Name'), for: :new_group_name, class: 'col-form-label' = 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' = text_field_tag :new_group_name, nil, class: 'form-control'
- if should_ask_company_question - if should_ask_company_question?
.form-group .form-group
= label_tag :trial_entity, _('Is this GitLab trial for your company?') = label_tag :trial_entity, _('Is this GitLab trial for your company?')
.gl-form-checkbox-group .gl-form-checkbox-group
......
...@@ -5,6 +5,62 @@ require 'spec_helper' ...@@ -5,6 +5,62 @@ require 'spec_helper'
RSpec.describe EE::TrialHelper do RSpec.describe EE::TrialHelper do
using RSpec::Parameterized::TableSyntax 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 describe '#namespace_options_for_select' do
let_it_be(:user) { create :user } let_it_be(:user) { create :user }
let_it_be(:group1) { create :group } 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