Commit e928c92a authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'fix-group-editing-error' into 'master'

Fix error displaying group edit page

See merge request gitlab-org/gitlab!23774
parents d1af200a af544046
......@@ -60,13 +60,11 @@ class SubscriptionsController < ApplicationController
).execute
if response[:success]
response[:data] = { location: edit_subscriptions_group_path(group.path) }
plan_id, quantity = subscription_params.values_at(:plan_id, :quantity)
track_paid_signup_flow_event(
'end',
label: subscription_params[:plan_id],
value: subscription_params[:quantity]
)
response[:data] = { location: edit_subscriptions_group_path(group.path, plan_id: plan_id, quantity: quantity) }
track_paid_signup_flow_event('end', label: plan_id, value: quantity)
end
render json: response[:data]
......
# frozen_string_literal: true
module SubscriptionsHelper
include ::Gitlab::Utils::StrongMemoize
def subscription_data
{
setup_for_company: (current_user.setup_for_company == true).to_s,
......@@ -11,11 +13,10 @@ module SubscriptionsHelper
end
def plan_title
@plan_title ||= subscription.hosted_plan.title
end
def subscription_seats
@subscription_seats ||= subscription.seats
strong_memoize(:plan_title) do
plan = plan_data.find { |plan| plan[:id] == params[:plan_id] }
plan[:code].titleize if plan
end
end
private
......@@ -26,8 +27,4 @@ module SubscriptionsHelper
.reject { |plan| plan[:free] }
.map { |plan| plan.slice(:id, :code, :price_per_year) }
end
def subscription
@subscription ||= @group.gitlab_subscription
end
end
......@@ -7,7 +7,7 @@
= image_tag('illustrations/subscription-success.svg', class: 'mw-xs')
.gl-banner-content.d-flex.flex-column.justify-content-center
%h3= _('Thanks for your purchase!')
- number_of_users = n_('1 user', '%{num} users', subscription_seats) % { num: subscription_seats }
- number_of_users = n_('1 user', '%{num} users', params[:quantity]) % { num: params[:quantity] }
%p= _('You have successfully purchased a %{plan} plan subscription for %{seats}. You’ll receive a receipt via email.') % { plan: plan_title, seats: number_of_users }
.edit-group.d-flex.flex-column.align-items-center.gl-pt-5
#progress-bar
......
......@@ -197,7 +197,7 @@ describe SubscriptionsController do
it 'returns the group edit location in JSON format' do
subject
expect(response.body).to eq({ location: "/-/subscriptions/groups/#{group.path}/edit" }.to_json)
expect(response.body).to eq({ location: "/-/subscriptions/groups/#{group.path}/edit?plan_id=x&quantity=2" }.to_json)
end
end
......
......@@ -3,28 +3,32 @@
require 'spec_helper'
describe SubscriptionsHelper do
let_it_be(:raw_plan_data) do
[
{
"name" => "Free Plan",
"free" => true
},
{
"id" => "bronze_id",
"name" => "Bronze Plan",
"free" => false,
"code" => "bronze",
"price_per_year" => 48.0
}
]
end
before do
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id')
allow_any_instance_of(FetchSubscriptionPlansService).to receive(:execute).and_return(raw_plan_data)
end
describe '#subscription_data' do
let_it_be(:raw_plan_data) do
[
{
"name" => "Free Plan",
"free" => true
},
{
"id" => "bronze_id",
"name" => "Bronze Plan",
"free" => false,
"code" => "bronze",
"price_per_year" => 48.0
}
]
end
let_it_be(:user) { create(:user, setup_for_company: nil, name: 'First Last') }
before do
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id')
allow_any_instance_of(FetchSubscriptionPlansService).to receive(:execute).and_return(raw_plan_data)
end
subject { helper.subscription_data }
......@@ -36,26 +40,24 @@ describe SubscriptionsHelper do
end
describe '#plan_title' do
let_it_be(:subscription) { create(:gitlab_subscription) }
before do
allow(helper).to receive(:subscription).and_return(subscription)
end
subject { helper.plan_title }
it { is_expected.to eq(subscription.hosted_plan.title) }
end
it { is_expected.to eq('Bronze') }
describe '#subscription_seats' do
let_it_be(:subscription) { create(:gitlab_subscription) }
context 'no plan_id URL parameter present' do
before do
allow(helper).to receive(:params).and_return({})
end
before do
allow(helper).to receive(:subscription).and_return(subscription)
it { is_expected.to eq(nil) }
end
subject { helper.subscription_seats }
context 'a non-existing plan_id URL parameter present' do
before do
allow(helper).to receive(:params).and_return(plan_id: 'xxx')
end
it { is_expected.to eq(subscription.seats) }
it { is_expected.to eq(nil) }
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