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
strong_memoize(:plan_title) do
plan = plan_data.find { |plan| plan[:id] == params[:plan_id] }
plan[:code].titleize if plan
end
def subscription_seats
@subscription_seats ||= subscription.seats
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,7 +3,6 @@
require 'spec_helper'
describe SubscriptionsHelper do
describe '#subscription_data' do
let_it_be(:raw_plan_data) do
[
{
......@@ -19,14 +18,19 @@ describe SubscriptionsHelper do
}
]
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
describe '#subscription_data' do
let_it_be(:user) { create(:user, setup_for_company: nil, name: 'First Last') }
before do
allow(helper).to receive(:current_user).and_return(user)
end
subject { helper.subscription_data }
it { is_expected.to include(setup_for_company: 'false') }
......@@ -36,26 +40,24 @@ describe SubscriptionsHelper do
end
describe '#plan_title' do
let_it_be(:subscription) { create(:gitlab_subscription) }
subject { helper.plan_title }
it { is_expected.to eq('Bronze') }
context 'no plan_id URL parameter present' do
before do
allow(helper).to receive(:subscription).and_return(subscription)
allow(helper).to receive(:params).and_return({})
end
subject { helper.plan_title }
it { is_expected.to eq(subscription.hosted_plan.title) }
it { is_expected.to eq(nil) }
end
describe '#subscription_seats' do
let_it_be(:subscription) { create(:gitlab_subscription) }
context 'a non-existing plan_id URL parameter present' do
before do
allow(helper).to receive(:subscription).and_return(subscription)
allow(helper).to receive(:params).and_return(plan_id: 'xxx')
end
subject { helper.subscription_seats }
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