Extract EE specific files/lines for Discussion spec/services
We have the following files containing EE specific code. We should move them to ee/
spec/services/system_note_service_spec.rb
diff --git a/spec/services/system_note_service_spec.rb b/home/felipe/development/gitlab-development-kit/gitlab/spec/services/system_note_service_spec.rb
index 4f633d24175..b917de14b2e 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/home/felipe/development/gitlab-development-kit/gitlab/spec/services/system_note_service_spec.rb
@@ -1,17 +1,15 @@
require 'spec_helper'
describe SystemNoteService do
- include ProjectForksHelper
include Gitlab::Routing
include RepoHelpers
include AssetsHelpers
set(:group) { create(:group) }
- let(:project) { create(:project, :repository, group: group) }
+ set(:project) { create(:project, :repository, group: group) }
set(:author) { create(:user) }
let(:noteable) { create(:issue, project: project) }
let(:issue) { noteable }
- let(:epic) { create(:epic) }
shared_examples_for 'a system note' do
let(:expected_noteable) { noteable }
@@ -621,7 +619,7 @@ describe SystemNoteService do
context 'commit with cross-reference from fork' do
let(:author2) { create(:project_member, :reporter, user: create(:user), project: project).user }
- let(:forked_project) { fork_project(project, author2, repository: true) }
+ let(:forked_project) { Projects::ForkService.new(project, author2).execute }
let(:commit2) { forked_project.commit }
before do
@@ -898,65 +896,29 @@ describe SystemNoteService do
end
end
- describe '.relate_issue' do
- let(:noteable_ref) { create(:issue) }
-
- subject { described_class.relate_issue(noteable, noteable_ref, author) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'relate' }
- end
-
- context 'when issue marks another as related' do
- it 'sets the note text' do
- expect(subject.note).to eq "marked this issue as related to #{noteable_ref.to_reference(project)}"
- end
- end
- end
-
- describe '.unrelate_issue' do
- let(:noteable_ref) { create(:issue) }
-
- subject { described_class.unrelate_issue(noteable, noteable_ref, author) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'unrelate' }
- end
+ describe '.discussion_continued_in_issue' do
+ let(:discussion) { create(:diff_note_on_merge_request, project: project).to_discussion }
+ let(:merge_request) { discussion.noteable }
+ let(:issue) { create(:issue, project: project) }
- context 'when issue relation is removed' do
- it 'sets the note text' do
- expect(subject.note).to eq "removed the relation with #{noteable_ref.to_reference(project)}"
- end
+ def reloaded_merge_request
+ MergeRequest.find(merge_request.id)
end
- end
- describe '.approve_mr' do
- let(:noteable) { create(:merge_request, source_project: project) }
- subject { described_class.approve_mr(noteable, author) }
+ subject { described_class.discussion_continued_in_issue(discussion, project, author, issue) }
it_behaves_like 'a system note' do
- let(:action) { 'approved' }
- end
-
- context 'when merge request approved' do
- it 'sets the note text' do
- expect(subject.note).to eq "approved this merge request"
- end
+ let(:expected_noteable) { discussion.first_note.noteable }
+ let(:action) { 'discussion' }
end
- end
- describe '.unapprove_mr' do
- let(:noteable) { create(:merge_request, source_project: project) }
- subject { described_class.unapprove_mr(noteable, author) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'unapproved' }
+ it 'creates a new note in the discussion' do
+ # we need to completely rebuild the merge request object, or the `@discussions` on the merge request are not reloaded.
+ expect { subject }.to change { reloaded_merge_request.discussions.first.notes.size }.by(1)
end
- context 'when merge request approved' do
- it 'sets the note text' do
- expect(subject.note).to eq "unapproved this merge request"
- end
+ it 'mentions the created issue in the system note' do
+ expect(subject.note).to include(issue.to_reference)
end
end
@@ -982,32 +944,6 @@ describe SystemNoteService do
end
end
- describe '.discussion_continued_in_issue' do
- let(:discussion) { create(:diff_note_on_merge_request, project: project).to_discussion }
- let(:merge_request) { discussion.noteable }
- let(:issue) { create(:issue, project: project) }
-
- def reloaded_merge_request
- MergeRequest.find(merge_request.id)
- end
-
- subject { described_class.discussion_continued_in_issue(discussion, project, author, issue) }
-
- it_behaves_like 'a system note' do
- let(:expected_noteable) { discussion.first_note.noteable }
- let(:action) { 'discussion' }
- end
-
- it 'creates a new note in the discussion' do
- # we need to completely rebuild the merge request object, or the `@discussions` on the merge request are not reloaded.
- expect { subject }.to change { reloaded_merge_request.discussions.first.notes.size }.by(1)
- end
-
- it 'mentions the created issue in the system note' do
- expect(subject.note).to include(issue.to_reference)
- end
- end
-
describe '.change_time_spent' do
# We need a custom noteable in order to the shared examples to be green.
let(:noteable) do
@@ -1271,73 +1207,4 @@ describe SystemNoteService do
end
end
end
-
- describe '.epic_issue' do
- let(:noteable) { epic }
- let(:project) { nil }
-
- context 'issue added to an epic' do
- subject { described_class.epic_issue(epic, issue, author, :added) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'epic_issue_added' }
- end
-
- it 'creates the note text correctly' do
- expect(subject.note).to eq("added issue #{issue.to_reference(epic.group)}")
- end
- end
-
- context 'issue removed from an epic' do
- subject { described_class.epic_issue(epic, issue, author, :removed) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'epic_issue_removed' }
- end
-
- it 'creates the note text correctly' do
- expect(subject.note).to eq("removed issue #{issue.to_reference(epic.group)}")
- end
- end
-
- context 'invalid type' do
- it 'raises an error' do
- expect { described_class.issue_on_epic(issue, epic, author, :invalid) }
- .not_to change { Note.count }
- end
- end
- end
-
- describe '.issue_on_epic' do
- context 'issue added to an epic' do
- subject { described_class.issue_on_epic(issue, epic, author, :added) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'issue_added_to_epic' }
- end
-
- it 'creates the note text correctly' do
- expect(subject.note).to eq("added to epic #{epic.to_reference(issue.project)}")
- end
- end
-
- context 'issue removed from an epic' do
- subject { described_class.issue_on_epic(issue, epic, author, :removed) }
-
- it_behaves_like 'a system note' do
- let(:action) { 'issue_removed_from_epic' }
- end
-
- it 'creates the note text correctly' do
- expect(subject.note).to eq("removed from epic #{epic.to_reference(issue.project)}")
- end
- end
-
- context 'invalid type' do
- it 'does not create a new note' do
- expect { described_class.issue_on_epic(issue, epic, author, :invalid) }
- .not_to change { Note.count }
- end
- end
- end
end
Edited by Felipe Artur