Commit a570ea9e authored by Vitaly Slobodin's avatar Vitaly Slobodin

Add addon_data method for presenting addon data properties

parent a86108e0
......@@ -16,6 +16,14 @@ module SubscriptionsHelper
}
end
def addon_data(group)
{
group_data: [present_group(group)].to_json,
namespace_id: params[:namespace_id],
source: params[:source]
}
end
def plan_title
strong_memoize(:plan_title) do
plan = subscription_available_plans.find { |plan| plan[:id] == params[:plan_id] }
......@@ -45,13 +53,15 @@ module SubscriptionsHelper
end
def present_groups(groups)
groups.map do |namespace|
{
id: namespace.id,
name: namespace.name,
users: namespace.member_count,
guests: namespace.guest_count
}
end
groups.map { |namespace| present_group(namespace) }
end
def present_group(namespace)
{
id: namespace.id,
name: namespace.name,
users: namespace.member_count,
guests: namespace.guest_count
}
end
end
- page_title _('Buy CI Minutes')
#js-buy-minutes{ data: subscription_data(@eligible_groups) }
#js-buy-minutes{ data: addon_data(@group) }
......@@ -132,4 +132,21 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to eq(nil) }
end
end
describe '#addon_data' do
subject(:addon_data) { helper.addon_data(group) }
let_it_be(:user) { create(:user, name: 'First Last') }
let_it_be(:group) { create(:group, name: 'My Namespace') }
before do
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:params).and_return({ namespace_id: group.id.to_s, source: 'some_source' })
group.add_owner(user)
end
it { is_expected.to include(namespace_id: group.id.to_s) }
it { is_expected.to include(source: 'some_source') }
it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":1,"guests":0}]}) }
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