summaryrefslogtreecommitdiff
path: root/spec/finders/todos_finder_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/finders/todos_finder_spec.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/finders/todos_finder_spec.rb')
-rw-r--r--spec/finders/todos_finder_spec.rb54
1 files changed, 36 insertions, 18 deletions
diff --git a/spec/finders/todos_finder_spec.rb b/spec/finders/todos_finder_spec.rb
index f6796398782..577ad80ede1 100644
--- a/spec/finders/todos_finder_spec.rb
+++ b/spec/finders/todos_finder_spec.rb
@@ -4,14 +4,14 @@ require 'spec_helper'
RSpec.describe TodosFinder do
describe '#execute' do
- let(:user) { create(:user) }
- let(:group) { create(:group) }
- let(:project) { create(:project, namespace: group) }
- let(:issue) { create(:issue, project: project) }
- let(:merge_request) { create(:merge_request, source_project: project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, :repository, namespace: group) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:merge_request) { create(:merge_request, source_project: project) }
let(:finder) { described_class }
- before do
+ before_all do
group.add_developer(user)
end
@@ -89,8 +89,6 @@ RSpec.describe TodosFinder do
end
it 'raises an argument error when invalid type is passed' do
- create(:todo, user: user, group: group, target: create(:design))
-
todos_finder = finder.new(user, { type: %w[Issue MergeRequest NotAValidType] })
expect { todos_finder.execute }.to raise_error(ArgumentError)
@@ -131,8 +129,8 @@ RSpec.describe TodosFinder do
end
context 'when filtering by author' do
- let(:author1) { create(:user) }
- let(:author2) { create(:user) }
+ let_it_be(:author1) { create(:user) }
+ let_it_be(:author2) { create(:user) }
let!(:todo1) { create(:todo, user: user, author: author1) }
let!(:todo2) { create(:todo, user: user, author: author2) }
@@ -154,7 +152,7 @@ RSpec.describe TodosFinder do
context 'by groups' do
context 'with subgroups' do
- let(:subgroup) { create(:group, parent: group) }
+ let_it_be(:subgroup) { create(:group, parent: group) }
let!(:todo3) { create(:todo, user: user, group: subgroup, target: issue) }
it 'returns todos from subgroups when filtered by a group' do
@@ -167,17 +165,14 @@ RSpec.describe TodosFinder do
context 'filtering for multiple groups' do
let_it_be(:group2) { create(:group) }
let_it_be(:group3) { create(:group) }
+ let_it_be(:subgroup1) { create(:group, parent: group) }
+ let_it_be(:subgroup2) { create(:group, parent: group2) }
let!(:todo1) { create(:todo, user: user, project: project, target: issue) }
let!(:todo2) { create(:todo, user: user, group: group, target: merge_request) }
let!(:todo3) { create(:todo, user: user, group: group2, target: merge_request) }
-
- let(:subgroup1) { create(:group, parent: group) }
let!(:todo4) { create(:todo, user: user, group: subgroup1, target: issue) }
-
- let(:subgroup2) { create(:group, parent: group2) }
let!(:todo5) { create(:todo, user: user, group: subgroup2, target: issue) }
-
let!(:todo6) { create(:todo, user: user, group: group3, target: issue) }
it 'returns the expected groups' do
@@ -232,6 +227,29 @@ RSpec.describe TodosFinder do
expect(todos).to match_array([todo2, todo1])
end
end
+
+ context 'when filtering by target id' do
+ it 'returns the expected todos for the target' do
+ todos = finder.new(user, { type: 'Issue', target_id: issue.id }).execute
+
+ expect(todos).to match_array([todo1])
+ end
+
+ it 'returns the expected todos for multiple target ids' do
+ another_issue = create(:issue, project: project)
+ todo3 = create(:todo, user: user, project: project, target: another_issue)
+
+ todos = finder.new(user, { type: 'Issue', target_id: [issue.id, another_issue.id] }).execute
+
+ expect(todos).to match_array([todo1, todo3])
+ end
+
+ it 'returns the expected todos for empty target id collection' do
+ todos = finder.new(user, { target_id: [] }).execute
+
+ expect(todos).to match_array([todo1, todo2])
+ end
+ end
end
context 'external authorization' do
@@ -307,9 +325,9 @@ RSpec.describe TodosFinder do
it 'returns the expected types' do
expected_result =
if Gitlab.ee?
- %w[Epic Issue MergeRequest DesignManagement::Design]
+ %w[Epic Issue MergeRequest DesignManagement::Design AlertManagement::Alert]
else
- %w[Issue MergeRequest DesignManagement::Design]
+ %w[Issue MergeRequest DesignManagement::Design AlertManagement::Alert]
end
expect(described_class.todo_types).to contain_exactly(*expected_result)