Commit b9b4c986 authored by Etienne Baqué's avatar Etienne Baqué

Added guest scope to group_member

parent af5b22bb
......@@ -73,6 +73,10 @@ module LoadedInGroupList
def member_count
@member_count ||= try(:preloaded_member_count) || members.count
end
def guest_count
@guest_count ||= members.guests.count
end
end
LoadedInGroupList::ClassMethods.prepend_if_ee('EE::LoadedInGroupList::ClassMethods')
......@@ -69,7 +69,8 @@ module SubscriptionsHelper
{
id: namespace.id,
name: namespace.name,
users: namespace.member_count
users: namespace.member_count,
guests: namespace.guest_count
}
end
end
......
......@@ -22,6 +22,7 @@ module EE
end
scope :reporters, -> { where(access_level: ::Gitlab::Access::REPORTER) }
scope :guests, -> { where(access_level: ::Gitlab::Access::GUEST) }
scope :non_owners, -> { where("members.access_level < ?", ::Gitlab::Access::OWNER) }
scope :by_user_id, ->(user_id) { where(user_id: user_id) }
end
......
......@@ -38,12 +38,14 @@ RSpec.describe SubscriptionsHelper do
describe '#subscription_data' do
let_it_be(:user) { create(:user, setup_for_company: nil, name: 'First Last') }
let_it_be(:user2) { create(:user) }
let_it_be(:group) { create(:group, name: 'My Namespace') }
before do
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id', namespace_id: group.id.to_s)
allow(helper).to receive(:current_user).and_return(user)
group.add_owner(user)
group.add_guest(user2)
end
subject { helper.subscription_data([group]) }
......@@ -54,7 +56,7 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to include(ci_minutes_plans: '[{"name":"1000 CI minutes pack","code":"ci_minutes","active":true,"deprecated":false,"free":null,"price_per_month":0.8333333333333334,"price_per_year":10,"features":null,"about_page_href":null,"hide_deprecated_card":false}]') }
it { is_expected.to include(plan_id: 'bronze_id') }
it { is_expected.to include(namespace_id: group.id.to_s) }
it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":1}]}) }
it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":2,"guests":1}]}) }
describe 'new_user' do
where(:referer, :expected_result) do
......
......@@ -181,14 +181,22 @@ RSpec.describe GroupMember do
end
describe 'scopes' do
let_it_be(:group) { create(:group) }
let_it_be(:member1) { create(:group_member, group: group) }
let_it_be(:member2) { create(:group_member, group: group) }
let_it_be(:member3) { create(:group_member) }
let_it_be(:guest1) { create(:group_member, :guest) }
let_it_be(:guest2) { create(:group_member, :guest, group: group) }
describe '.by_group_ids' do
it 'returns only members from selected groups' do
group = create(:group)
member1 = create(:group_member, group: group)
member2 = create(:group_member, group: group)
create(:group_member)
expect(described_class.by_group_ids([group.id])).to contain_exactly(member1, member2, guest2)
end
end
expect(described_class.by_group_ids([group.id])).to match_array([member1, member2])
describe '.guests' do
it 'returns only guests members' do
expect(described_class.guests).to contain_exactly(guest1, guest2)
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