summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPatrick Derichs <pderichs@gitlab.com>2019-06-15 07:10:58 +0200
committerPatrick Derichs <pderichs@gitlab.com>2019-06-19 10:56:55 +0200
commit932a9a0c77a02e1d948f45cffe5e936e915ae0bc (patch)
treecb1766d65bc00f56c83a044b6fc19712a9473f69 /spec
parentba952d53c5782e49b59ba3e5dd89c2c1eca02c80 (diff)
downloadgitlab-ce-932a9a0c77a02e1d948f45cffe5e936e915ae0bc.tar.gz
Use NotesFinder to fetch notes on API and Controllers
Fix missing iid query on NotesFinder Changed parameters of find_noteable, so changes across a few files were needed. MergeRequest also requires iid instead of id query Make NotesFinder fail with RecordNotFound again Add specs for target_iid Using RSpec tablesyntax for target_iid specs Revert "Using RSpec tablesyntax for target_iid specs" This reverts commit ba45c7f569a. Allow find_by! here Fix variable name Add readable check Revert "Add readable check" This reverts commit 9e3a1a7aa39. Remove unnecessary assignment Add required changes for EE Fix parameter count Reduce code duplication by extracting a noteable module method The call to find_noteable was redundant so multiple files and lines have changed in that commit to use the newly introduced module method `noteable`. Replace casecmp with include check Add parent_type parameter Revert "Reduce code duplication by extracting a noteable module method" This reverts commit 8c0923babff16. Method is no longer needed Check whether noteable can be read by user
Diffstat (limited to 'spec')
-rw-r--r--spec/finders/notes_finder_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb
index 0a685152cf9..87bde4ca2f6 100644
--- a/spec/finders/notes_finder_spec.rb
+++ b/spec/finders/notes_finder_spec.rb
@@ -292,5 +292,31 @@ describe NotesFinder do
expect(subject.target).to eq(commit)
end
end
+
+ context 'target_iid' do
+ let(:issue) { create(:issue, project: project) }
+ let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
+
+ it 'finds issues by iid' do
+ iid_params = { target_type: 'issue', target_iid: issue.iid }
+ expect(described_class.new(project, user, iid_params).target).to eq(issue)
+ end
+
+ it 'finds merge requests by iid' do
+ iid_params = { target_type: 'merge_request', target_iid: merge_request.iid }
+ expect(described_class.new(project, user, iid_params).target).to eq(merge_request)
+ end
+
+ it 'returns nil if both target_id and target_iid are not given' do
+ params_without_any_id = { target_type: 'issue' }
+ expect(described_class.new(project, user, params_without_any_id).target).to be_nil
+ end
+
+ it 'prioritizes target_id over target_iid' do
+ issue2 = create(:issue, project: project)
+ iid_params = { target_type: 'issue', target_id: issue2.id, target_iid: issue.iid }
+ expect(described_class.new(project, user, iid_params).target).to eq(issue2)
+ end
+ end
end
end