2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::GroupSearchResults do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe 'user search' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
it 'returns the users belonging to the group matching the search query' do
|
|
|
|
user1 = create(:user, username: 'gob_bluth')
|
|
|
|
create(:group_member, :developer, user: user1, group: group)
|
|
|
|
|
|
|
|
user2 = create(:user, username: 'michael_bluth')
|
|
|
|
create(:group_member, :developer, user: user2, group: group)
|
|
|
|
|
|
|
|
create(:user, username: 'gob_2018')
|
|
|
|
|
|
|
|
result = described_class.new(user, anything, group, 'gob').objects('users')
|
|
|
|
|
|
|
|
expect(result).to eq [user1]
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns the user belonging to the subgroup matching the search query' do
|
2019-07-07 11:18:12 +05:30
|
|
|
user1 = create(:user, username: 'gob_bluth')
|
|
|
|
subgroup = create(:group, parent: group)
|
|
|
|
create(:group_member, :developer, user: user1, group: subgroup)
|
|
|
|
|
|
|
|
create(:user, username: 'gob_2018')
|
|
|
|
|
|
|
|
result = described_class.new(user, anything, group, 'gob').objects('users')
|
|
|
|
|
|
|
|
expect(result).to eq [user1]
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns the user belonging to the parent group matching the search query' do
|
2019-07-07 11:18:12 +05:30
|
|
|
user1 = create(:user, username: 'gob_bluth')
|
|
|
|
parent_group = create(:group, children: [group])
|
|
|
|
create(:group_member, :developer, user: user1, group: parent_group)
|
|
|
|
|
|
|
|
create(:user, username: 'gob_2018')
|
|
|
|
|
|
|
|
result = described_class.new(user, anything, group, 'gob').objects('users')
|
|
|
|
|
|
|
|
expect(result).to eq [user1]
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'does not return the user belonging to the private subgroup' do
|
2019-07-07 11:18:12 +05:30
|
|
|
user1 = create(:user, username: 'gob_bluth')
|
|
|
|
subgroup = create(:group, :private, parent: group)
|
|
|
|
create(:group_member, :developer, user: user1, group: subgroup)
|
|
|
|
|
|
|
|
create(:user, username: 'gob_2018')
|
|
|
|
|
|
|
|
result = described_class.new(user, anything, group, 'gob').objects('users')
|
|
|
|
|
|
|
|
expect(result).to eq []
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return the user belonging to an unrelated group' do
|
|
|
|
user = create(:user, username: 'gob_bluth')
|
|
|
|
unrelated_group = create(:group)
|
|
|
|
create(:group_member, :developer, user: user, group: unrelated_group)
|
|
|
|
|
|
|
|
result = described_class.new(user, anything, group, 'gob').objects('users')
|
|
|
|
|
|
|
|
expect(result).to eq []
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'sets include_subgroups flag by default' do
|
|
|
|
result = described_class.new(user, anything, group, 'gob')
|
|
|
|
|
|
|
|
expect(result.issuable_params[:include_subgroups]).to eq(true)
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|