debian-mirror-gitlab/spec/lib/gitlab/group_search_results_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.9 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::GroupSearchResults do
2020-11-24 15:15:51 +05:30
# group creation calls GroupFinder, so need to create the group
# before so expect(GroupsFinder) check works
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, group: group) }
2021-09-30 23:02:18 +05:30
2020-11-24 15:15:51 +05:30
let(:filters) { {} }
let(:limit_projects) { Project.all }
let(:query) { 'gob' }
subject(:results) { described_class.new(user, query, limit_projects, group: group, filters: filters) }
describe 'issues search' do
let_it_be(:opened_result) { create(:issue, :opened, project: project, title: 'foo opened') }
let_it_be(:closed_result) { create(:issue, :closed, project: project, title: 'foo closed') }
2021-01-03 14:25:43 +05:30
let_it_be(:confidential_result) { create(:issue, :confidential, project: project, title: 'foo confidential') }
2020-11-24 15:15:51 +05:30
let(:query) { 'foo' }
let(:scope) { 'issues' }
2021-01-03 14:25:43 +05:30
before do
project.add_developer(user)
end
2020-11-24 15:15:51 +05:30
include_examples 'search results filtered by state'
2021-01-03 14:25:43 +05:30
include_examples 'search results filtered by confidential'
2020-11-24 15:15:51 +05:30
end
describe 'merge_requests search' do
let(:opened_result) { create(:merge_request, :opened, source_project: project, title: 'foo opened') }
let(:closed_result) { create(:merge_request, :closed, source_project: project, title: 'foo closed') }
let(:query) { 'foo' }
let(:scope) { 'merge_requests' }
before do
# we're creating those instances in before block because otherwise factory for MRs will fail on after(:build)
opened_result
closed_result
end
include_examples 'search results filtered by state'
end
2019-07-07 11:18:12 +05:30
describe 'user search' do
2020-11-24 15:15:51 +05:30
subject(:objects) { results.objects('users') }
2019-07-07 11:18:12 +05:30
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')
2020-11-24 15:15:51 +05:30
is_expected.to eq [user1]
2019-07-07 11:18:12 +05:30
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')
2020-11-24 15:15:51 +05:30
is_expected.to eq [user1]
2019-07-07 11:18:12 +05:30
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')
2020-11-24 15:15:51 +05:30
is_expected.to eq [user1]
2019-07-07 11:18:12 +05:30
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')
2020-11-24 15:15:51 +05:30
is_expected.to be_empty
2019-07-07 11:18:12 +05:30
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)
2020-11-24 15:15:51 +05:30
is_expected.to be_empty
end
2019-07-07 11:18:12 +05:30
2020-11-24 15:15:51 +05:30
it 'does not return the user invited to the group' do
user = create(:user, username: 'gob_bluth')
create(:group_member, :invited, :developer, user: user, group: group)
is_expected.to be_empty
2019-07-07 11:18:12 +05:30
end
2020-03-13 15:44:24 +05:30
2020-11-24 15:15:51 +05:30
it 'calls GroupFinder during execution' do
expect(GroupsFinder).to receive(:new).with(user).and_call_original
2020-03-13 15:44:24 +05:30
2020-11-24 15:15:51 +05:30
subject
end
end
describe "#issuable_params" do
it 'sets include_subgroups flag by default' do
expect(results.issuable_params[:include_subgroups]).to eq(true)
2020-03-13 15:44:24 +05:30
end
2019-07-07 11:18:12 +05:30
end
end