Commit 9a304d3a authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'refactor-billable-membership-entity' into 'master'

Extract Routing Logic from BillableMembership Entity

See merge request gitlab-org/gitlab!59412
parents bcd369a6 27e4aa5f
......@@ -166,6 +166,16 @@ module GitlabRoutingHelper
resend_invite_group_group_member_path(group_member.source, group_member)
end
# Members
def source_members_url(member)
case member.source_type
when 'Namespace'
group_group_members_url(member.source)
when 'Project'
project_project_members_url(member.source)
end
end
# Artifacts
# Rails path generators are slow because they need to do large regex comparisons
......
......@@ -4,7 +4,7 @@ module EE
module API
module Entities
class BillableMembership < Grape::Entity
include ::Gitlab::Routing
include RequestAwareEntity
expose :id
expose :source_id
......@@ -12,12 +12,7 @@ module EE
member.source.full_name
end
expose :source_members_url do |member|
case member.source_type
when 'Namespace'
group_group_members_url(member.source)
when 'Project'
project_project_members_url(member.source)
end
source_members_url(member)
end
expose :created_at
expose :expires_at
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::EE::API::Entities::BillableMembership do
describe '#as_json' do
it 'returns source_members_url for a group' do
membership = create(:group_member)
group_members_url = Gitlab::Routing.url_helpers.group_group_members_url(membership.source)
expect(described_class.new(membership).as_json[:source_members_url]).to eq(group_members_url)
end
it 'returns source_members_url for a project' do
membership = create(:project_member)
project_members_url = Gitlab::Routing.url_helpers.project_project_members_url(membership.source)
expect(described_class.new(membership).as_json[:source_members_url]).to eq(project_members_url)
end
end
end
......@@ -113,6 +113,24 @@ RSpec.describe GitlabRoutingHelper do
end
end
describe 'members helpers' do
describe '#source_members_url' do
it 'returns a url to the memberships page for a group membership' do
membership = build_stubbed(:group_member)
group_members_url = "http://test.host/groups/#{membership.source.full_path}/-/group_members"
expect(source_members_url(membership)).to eq(group_members_url)
end
it 'returns a url to the memberships page for a project membership' do
membership = build_stubbed(:project_member)
project_members_url = "http://test.host/#{membership.source.full_path}/-/project_members"
expect(source_members_url(membership)).to eq(project_members_url)
end
end
end
context 'artifacts' do
let_it_be(:project) { create(:project) }
let_it_be(:job) { create(:ci_build, project: project, name: 'test:job', artifacts_expire_at: 1.hour.from_now) }
......
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