Commit bf4ec606 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'backstage/gb/optimize-system-note-service-specs' into 'master'

Optimize system note service specs

See merge request !13958
parents 14462b99 f212210d
...@@ -3,9 +3,9 @@ require 'spec_helper' ...@@ -3,9 +3,9 @@ require 'spec_helper'
describe SystemNoteService do describe SystemNoteService do
include Gitlab::Routing include Gitlab::Routing
let(:group) { create(:group) } set(:group) { create(:group) }
let(:project) { create(:project, group: group) } set(:project) { create(:project, :repository, group: group) }
let(:author) { create(:user) } set(:author) { create(:user) }
let(:noteable) { create(:issue, project: project) } let(:noteable) { create(:issue, project: project) }
let(:issue) { noteable } let(:issue) { noteable }
...@@ -29,8 +29,7 @@ describe SystemNoteService do ...@@ -29,8 +29,7 @@ describe SystemNoteService do
describe '.add_commits' do describe '.add_commits' do
subject { described_class.add_commits(noteable, project, author, new_commits, old_commits, oldrev) } subject { described_class.add_commits(noteable, project, author, new_commits, old_commits, oldrev) }
let(:project) { create(:project, :repository) } let(:noteable) { create(:merge_request, source_project: project, target_project: project) }
let(:noteable) { create(:merge_request, source_project: project) }
let(:new_commits) { noteable.commits } let(:new_commits) { noteable.commits }
let(:old_commits) { [] } let(:old_commits) { [] }
let(:oldrev) { nil } let(:oldrev) { nil }
...@@ -185,7 +184,7 @@ describe SystemNoteService do ...@@ -185,7 +184,7 @@ describe SystemNoteService do
describe '.change_label' do describe '.change_label' do
subject { described_class.change_label(noteable, project, author, added, removed) } subject { described_class.change_label(noteable, project, author, added, removed) }
let(:labels) { create_list(:label, 2) } let(:labels) { create_list(:label, 2, project: project) }
let(:added) { [] } let(:added) { [] }
let(:removed) { [] } let(:removed) { [] }
...@@ -294,7 +293,6 @@ describe SystemNoteService do ...@@ -294,7 +293,6 @@ describe SystemNoteService do
end end
describe '.merge_when_pipeline_succeeds' do describe '.merge_when_pipeline_succeeds' do
let(:project) { create(:project, :repository) }
let(:pipeline) { build(:ci_pipeline_without_jobs )} let(:pipeline) { build(:ci_pipeline_without_jobs )}
let(:noteable) do let(:noteable) do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
...@@ -312,7 +310,6 @@ describe SystemNoteService do ...@@ -312,7 +310,6 @@ describe SystemNoteService do
end end
describe '.cancel_merge_when_pipeline_succeeds' do describe '.cancel_merge_when_pipeline_succeeds' do
let(:project) { create(:project, :repository) }
let(:noteable) do let(:noteable) do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
end end
...@@ -390,7 +387,6 @@ describe SystemNoteService do ...@@ -390,7 +387,6 @@ describe SystemNoteService do
describe '.change_branch' do describe '.change_branch' do
subject { described_class.change_branch(noteable, project, author, 'target', old_branch, new_branch) } subject { described_class.change_branch(noteable, project, author, 'target', old_branch, new_branch) }
let(:project) { create(:project, :repository) }
let(:old_branch) { 'old_branch'} let(:old_branch) { 'old_branch'}
let(:new_branch) { 'new_branch'} let(:new_branch) { 'new_branch'}
...@@ -408,8 +404,6 @@ describe SystemNoteService do ...@@ -408,8 +404,6 @@ describe SystemNoteService do
describe '.change_branch_presence' do describe '.change_branch_presence' do
subject { described_class.change_branch_presence(noteable, project, author, :source, 'feature', :delete) } subject { described_class.change_branch_presence(noteable, project, author, :source, 'feature', :delete) }
let(:project) { create(:project, :repository) }
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'branch' } let(:action) { 'branch' }
end end
...@@ -424,8 +418,6 @@ describe SystemNoteService do ...@@ -424,8 +418,6 @@ describe SystemNoteService do
describe '.new_issue_branch' do describe '.new_issue_branch' do
subject { described_class.new_issue_branch(noteable, project, author, "1-mepmep") } subject { described_class.new_issue_branch(noteable, project, author, "1-mepmep") }
let(:project) { create(:project, :repository) }
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'branch' } let(:action) { 'branch' }
end end
...@@ -491,7 +483,6 @@ describe SystemNoteService do ...@@ -491,7 +483,6 @@ describe SystemNoteService do
context 'within the same project' do context 'within the same project' do
context 'from Commit' do context 'from Commit' do
let(:project) { create(:project, :repository) }
let(:mentioner) { project.repository.commit } let(:mentioner) { project.repository.commit }
it 'references the mentioning commit' do it 'references the mentioning commit' do
...@@ -533,7 +524,6 @@ describe SystemNoteService do ...@@ -533,7 +524,6 @@ describe SystemNoteService do
end end
context 'when mentioner is a MergeRequest' do context 'when mentioner is a MergeRequest' do
let(:project) { create(:project, :repository) }
let(:mentioner) { create(:merge_request, :simple, source_project: project) } let(:mentioner) { create(:merge_request, :simple, source_project: project) }
let(:noteable) { project.commit } let(:noteable) { project.commit }
...@@ -561,7 +551,6 @@ describe SystemNoteService do ...@@ -561,7 +551,6 @@ describe SystemNoteService do
end end
describe '.cross_reference_exists?' do describe '.cross_reference_exists?' do
let(:project) { create(:project, :repository) }
let(:commit0) { project.commit } let(:commit0) { project.commit }
let(:commit1) { project.commit('HEAD~2') } let(:commit1) { project.commit('HEAD~2') }
...@@ -899,9 +888,8 @@ describe SystemNoteService do ...@@ -899,9 +888,8 @@ describe SystemNoteService do
end end
describe '.discussion_continued_in_issue' do describe '.discussion_continued_in_issue' do
let(:discussion) { create(:diff_note_on_merge_request).to_discussion } let(:discussion) { create(:diff_note_on_merge_request, project: project).to_discussion }
let(:merge_request) { discussion.noteable } let(:merge_request) { discussion.noteable }
let(:project) { merge_request.source_project }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
def reloaded_merge_request def reloaded_merge_request
...@@ -1023,7 +1011,6 @@ describe SystemNoteService do ...@@ -1023,7 +1011,6 @@ describe SystemNoteService do
end end
describe '.add_merge_request_wip_from_commit' do describe '.add_merge_request_wip_from_commit' do
let(:project) { create(:project, :repository) }
let(:noteable) do let(:noteable) do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
end end
...@@ -1078,9 +1065,8 @@ describe SystemNoteService do ...@@ -1078,9 +1065,8 @@ describe SystemNoteService do
end end
describe '.diff_discussion_outdated' do describe '.diff_discussion_outdated' do
let(:discussion) { create(:diff_note_on_merge_request).to_discussion } let(:discussion) { create(:diff_note_on_merge_request, project: project).to_discussion }
let(:merge_request) { discussion.noteable } let(:merge_request) { discussion.noteable }
let(:project) { merge_request.source_project }
let(:change_position) { discussion.position } let(:change_position) { discussion.position }
def reloaded_merge_request def reloaded_merge_request
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment