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 ...@@ -60,13 +60,11 @@ class SubscriptionsController < ApplicationController
).execute ).execute
if response[:success] 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( response[:data] = { location: edit_subscriptions_group_path(group.path, plan_id: plan_id, quantity: quantity) }
'end',
label: subscription_params[:plan_id], track_paid_signup_flow_event('end', label: plan_id, value: quantity)
value: subscription_params[:quantity]
)
end end
render json: response[:data] render json: response[:data]
......
# frozen_string_literal: true # frozen_string_literal: true
module SubscriptionsHelper module SubscriptionsHelper
include ::Gitlab::Utils::StrongMemoize
def subscription_data def subscription_data
{ {
setup_for_company: (current_user.setup_for_company == true).to_s, setup_for_company: (current_user.setup_for_company == true).to_s,
...@@ -11,11 +13,10 @@ module SubscriptionsHelper ...@@ -11,11 +13,10 @@ module SubscriptionsHelper
end end
def plan_title def plan_title
@plan_title ||= subscription.hosted_plan.title strong_memoize(:plan_title) do
end plan = plan_data.find { |plan| plan[:id] == params[:plan_id] }
plan[:code].titleize if plan
def subscription_seats end
@subscription_seats ||= subscription.seats
end end
private private
...@@ -26,8 +27,4 @@ module SubscriptionsHelper ...@@ -26,8 +27,4 @@ module SubscriptionsHelper
.reject { |plan| plan[:free] } .reject { |plan| plan[:free] }
.map { |plan| plan.slice(:id, :code, :price_per_year) } .map { |plan| plan.slice(:id, :code, :price_per_year) }
end end
def subscription
@subscription ||= @group.gitlab_subscription
end
end end
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
= image_tag('illustrations/subscription-success.svg', class: 'mw-xs') = image_tag('illustrations/subscription-success.svg', class: 'mw-xs')
.gl-banner-content.d-flex.flex-column.justify-content-center .gl-banner-content.d-flex.flex-column.justify-content-center
%h3= _('Thanks for your purchase!') %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 } %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 .edit-group.d-flex.flex-column.align-items-center.gl-pt-5
#progress-bar #progress-bar
......
...@@ -197,7 +197,7 @@ describe SubscriptionsController do ...@@ -197,7 +197,7 @@ describe SubscriptionsController do
it 'returns the group edit location in JSON format' do it 'returns the group edit location in JSON format' do
subject 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
end end
......
...@@ -3,28 +3,32 @@ ...@@ -3,28 +3,32 @@
require 'spec_helper' require 'spec_helper'
describe SubscriptionsHelper do 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 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') } let_it_be(:user) { create(:user, setup_for_company: nil, name: 'First Last') }
before do before do
allow(helper).to receive(:current_user).and_return(user) 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 end
subject { helper.subscription_data } subject { helper.subscription_data }
...@@ -36,26 +40,24 @@ describe SubscriptionsHelper do ...@@ -36,26 +40,24 @@ describe SubscriptionsHelper do
end end
describe '#plan_title' do 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 } subject { helper.plan_title }
it { is_expected.to eq(subscription.hosted_plan.title) } it { is_expected.to eq('Bronze') }
end
describe '#subscription_seats' do context 'no plan_id URL parameter present' do
let_it_be(:subscription) { create(:gitlab_subscription) } before do
allow(helper).to receive(:params).and_return({})
end
before do it { is_expected.to eq(nil) }
allow(helper).to receive(:subscription).and_return(subscription)
end 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
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