2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-05 12:46:32 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Projects::ParticipantsService do
|
2017-01-05 12:46:32 -05:00
|
|
|
describe '#groups' do
|
2019-03-22 11:51:14 -04:00
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:project) { create(:project, :public) }
|
|
|
|
let(:service) { described_class.new(project, user) }
|
|
|
|
|
|
|
|
it 'avoids N+1 queries' do
|
|
|
|
group_1 = create(:group)
|
|
|
|
group_1.add_owner(user)
|
|
|
|
|
|
|
|
service.groups # Run general application warmup queries
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new { service.groups }.count
|
|
|
|
|
|
|
|
group_2 = create(:group)
|
|
|
|
group_2.add_owner(user)
|
|
|
|
|
|
|
|
expect { service.groups }.not_to exceed_query_limit(control_count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct user counts for groups' do
|
|
|
|
group_1 = create(:group)
|
|
|
|
group_1.add_owner(user)
|
|
|
|
group_1.add_owner(create(:user))
|
|
|
|
|
|
|
|
group_2 = create(:group)
|
|
|
|
group_2.add_owner(user)
|
|
|
|
create(:group_member, :access_request, group: group_2, user: create(:user))
|
|
|
|
|
|
|
|
expect(service.groups).to contain_exactly(
|
|
|
|
a_hash_including(name: group_1.full_name, count: 2),
|
|
|
|
a_hash_including(name: group_2.full_name, count: 1)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-01-05 12:46:32 -05:00
|
|
|
describe 'avatar_url' do
|
2018-06-05 17:18:06 -04:00
|
|
|
let(:group) { create(:group, avatar: fixture_file_upload('spec/fixtures/dk.png')) }
|
2017-01-05 12:46:32 -05:00
|
|
|
|
2019-03-22 11:51:14 -04:00
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
2017-01-05 12:46:32 -05:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'returns an url for the avatar' do
|
2019-03-22 11:51:14 -04:00
|
|
|
expect(service.groups.size).to eq 1
|
|
|
|
expect(service.groups.first[:avatar_url]).to eq("/uploads/-/system/group/avatar/#{group.id}/dk.png")
|
2017-01-05 12:46:32 -05:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'returns an url for the avatar with relative url' do
|
2017-01-05 12:46:32 -05:00
|
|
|
stub_config_setting(relative_url_root: '/gitlab')
|
|
|
|
stub_config_setting(url: Settings.send(:build_gitlab_url))
|
|
|
|
|
2019-03-22 11:51:14 -04:00
|
|
|
expect(service.groups.size).to eq 1
|
|
|
|
expect(service.groups.first[:avatar_url]).to eq("/gitlab/uploads/-/system/group/avatar/#{group.id}/dk.png")
|
2017-01-05 12:46:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|