Commit 89ed43d5 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'rd-fix-show-trial-errors-helper' into 'master'

Fix error where helper was incorrectly returning `true`

See merge request gitlab-org/gitlab!18231
parents 2fce1fea d2f48269
---
title: Fix error where helper was incorrectly returning `true`
merge_request: 18231
author:
type: fixed
......@@ -17,9 +17,9 @@ class TrialsController < ApplicationController
end
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
else
render :new
......@@ -29,9 +29,9 @@ class TrialsController < ApplicationController
def apply
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 })
else
render :select
......
......@@ -26,12 +26,12 @@ module EE
grouped_options_for_select(grouped_options, nil, prompt: _('Please select'))
end
def show_trial_errors?(namespace, trial_result)
namespace&.invalid? || !trial_result&.dig(:success)
def show_trial_errors?(namespace, service_result)
namespace&.invalid? || (service_result && !service_result[:success])
end
def trial_errors(namespace, trial_result)
namespace&.errors&.full_messages&.to_sentence&.presence || trial_result&.dig(:errors)&.presence
def trial_errors(namespace, service_result)
namespace&.errors&.full_messages&.to_sentence&.presence || service_result&.dig(:errors)&.presence
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 @@
%p.center
= _('We need some additional information to activate your free trial')
- if @lead_result&.dig(:errors).present?
.flash-container
.flash-alert.text-center
= _('We have found the following errors:')
.flash-text
= @lead_result[:errors]
= render 'errors'
= form_tag create_lead_trials_path, method: :post do |f|
.form-group
......
......@@ -6,12 +6,7 @@
%p.center
= _('You can apply your Trial to your Personal account or create a New Group.')
- if show_trial_errors?(@namespace, @trial_result)
.flash-container
.flash-alert.text-center
= _('We have found the following errors:')
.flash-text
= trial_errors(@namespace, @trial_result)
= render 'errors'
= form_tag apply_trials_path, method: :post do
.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