1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::GroupSearchResults, feature_category: :global_search do
# 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) }
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') }
let_it_be(:confidential_result) { create(:issue, :confidential, project: project, title: 'foo confidential') }
let(:query) { 'foo' }
let(:scope) { 'issues' }
before do
project.add_developer(user)
end
include_examples 'search results filtered by state'
include_examples 'search results filtered by confidential'
end
describe 'merge_requests search' do
let_it_be(:unarchived_project) { create(:project, :public, group: group) }
let_it_be(:archived_project) { create(:project, :public, :archived, group: group) }
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_it_be(:unarchived_result) { create(:merge_request, source_project: unarchived_project, title: 'foo') }
let_it_be(:archived_result) { create(:merge_request, source_project: archived_project, title: 'foo') }
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'
include_examples 'search results filtered by archived', 'search_merge_requests_hide_archived_projects'
end
describe '#projects' do
let(:scope) { 'projects' }
let(:query) { 'Test' }
describe 'filtering' do
let_it_be(:group) { create(:group) }
let_it_be(:unarchived_result) { create(:project, :public, group: group, name: 'Test1') }
let_it_be(:archived_result) { create(:project, :archived, :public, group: group, name: 'Test2') }
it_behaves_like 'search results filtered by archived', 'search_projects_hide_archived'
end
end
describe 'user search' do
subject(:objects) { results.objects('users') }
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')
is_expected.to eq [user1]
end
it 'returns the user belonging to the subgroup matching the search query' do
user1 = create(:user, username: 'gob_bluth')
subgroup = create(:group, parent: group)
create(:group_member, :developer, user: user1, group: subgroup)
create(:user, username: 'gob_2018')
is_expected.to eq [user1]
end
it 'returns the user belonging to the parent group matching the search query' do
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')
is_expected.to eq [user1]
end
it 'does not return the user belonging to the private subgroup' do
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')
is_expected.to be_empty
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)
is_expected.to be_empty
end
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
end
it 'calls GroupFinder during execution' do
expect(GroupsFinder).to receive(:new).with(user).and_call_original
subject
end
end
describe "#issuable_params" do
it 'sets include_subgroups flag by default' do
expect(results.issuable_params[:include_subgroups]).to eq(true)
end
end
end
|