Commit d2f48269 authored by Rubén Dávila's avatar Rubén Dávila Committed by Mayra Cabrera

Fix error where helper was incorrectly returning `true`

Helper was incorrectly returning `true` when user was moving from Step 2
(Lead generation) to Step 3 (Selection of namespace). When landing at
Step 3. `trial_result` is `nil` so helper show return `false`.
parent 2fce1fea
---
title: Fix error where helper was incorrectly returning `true`
merge_request: 18231
author:
type: fixed
...@@ -17,9 +17,9 @@ class TrialsController < ApplicationController ...@@ -17,9 +17,9 @@ class TrialsController < ApplicationController
end end
def create_lead def create_lead
@lead_result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params }) @result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params })
if @lead_result[:success] if @result[:success]
redirect_to select_trials_url redirect_to select_trials_url
else else
render :new render :new
...@@ -29,9 +29,9 @@ class TrialsController < ApplicationController ...@@ -29,9 +29,9 @@ class TrialsController < ApplicationController
def apply def apply
return render(:select) if @namespace.invalid? return render(:select) if @namespace.invalid?
@trial_result = GitlabSubscriptions::ApplyTrialService.new.execute(apply_trial_params) @result = GitlabSubscriptions::ApplyTrialService.new.execute(apply_trial_params)
if @trial_result&.dig(:success) if @result&.dig(:success)
redirect_to group_url(@namespace, { trial: true }) redirect_to group_url(@namespace, { trial: true })
else else
render :select render :select
......
...@@ -26,12 +26,12 @@ module EE ...@@ -26,12 +26,12 @@ module EE
grouped_options_for_select(grouped_options, nil, prompt: _('Please select')) grouped_options_for_select(grouped_options, nil, prompt: _('Please select'))
end end
def show_trial_errors?(namespace, trial_result) def show_trial_errors?(namespace, service_result)
namespace&.invalid? || !trial_result&.dig(:success) namespace&.invalid? || (service_result && !service_result[:success])
end end
def trial_errors(namespace, trial_result) def trial_errors(namespace, service_result)
namespace&.errors&.full_messages&.to_sentence&.presence || trial_result&.dig(:errors)&.presence namespace&.errors&.full_messages&.to_sentence&.presence || service_result&.dig(:errors)&.presence
end end
end end
end end
- if show_trial_errors?(@namespace, @result)
.flash-container
.flash-alert.text-center
= _('We have found the following errors:')
.flash-text
= trial_errors(@namespace, @result)
...@@ -6,12 +6,7 @@ ...@@ -6,12 +6,7 @@
%p.center %p.center
= _('We need some additional information to activate your free trial') = _('We need some additional information to activate your free trial')
- if @lead_result&.dig(:errors).present? = render 'errors'
.flash-container
.flash-alert.text-center
= _('We have found the following errors:')
.flash-text
= @lead_result[:errors]
= form_tag create_lead_trials_path, method: :post do |f| = form_tag create_lead_trials_path, method: :post do |f|
.form-group .form-group
......
...@@ -6,12 +6,7 @@ ...@@ -6,12 +6,7 @@
%p.center %p.center
= _('You can apply your Trial to your Personal account or create a New Group.') = _('You can apply your Trial to your Personal account or create a New Group.')
- if show_trial_errors?(@namespace, @trial_result) = render 'errors'
.flash-container
.flash-alert.text-center
= _('We have found the following errors:')
.flash-text
= trial_errors(@namespace, @trial_result)
= form_tag apply_trials_path, method: :post do = form_tag apply_trials_path, method: :post do
.form-group .form-group
......
# frozen_string_literal: true
require 'spec_helper'
describe EE::TrialHelper do
using RSpec::Parameterized::TableSyntax
describe '#show_trial_errors?' do
where(:namespace, :trial_result, :expected_result) do
nil | { success: true } | false
nil | nil | nil
build(:namespace) | nil | nil
build(:namespace) | { success: true } | false
build(:namespace, name: 'admin') | { success: true } | true
nil | { success: false } | true
build(:namespace) | { success: false } | true
end
with_them do
it 'show errors when Namespace is invalid or Trial generation was unsuccessful' do
expect(helper.show_trial_errors?(namespace, trial_result)).to eq(expected_result)
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