Commit 3568c68e authored by Felipe Artur's avatar Felipe Artur

Extract EE specific files/lines for Discussion spec/services

Part of moving GitLab into single codebase
parent 39d4ee8c
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe SystemNoteService do describe SystemNoteService do
...@@ -6,7 +8,7 @@ describe SystemNoteService do ...@@ -6,7 +8,7 @@ describe SystemNoteService do
include RepoHelpers include RepoHelpers
set(:group) { create(:group) } set(:group) { create(:group) }
let(:project) { create(:project, :repository, group: group) } set(:project) { create(:project, :repository, group: group) }
set(: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 }
...@@ -36,6 +38,68 @@ describe SystemNoteService do ...@@ -36,6 +38,68 @@ describe SystemNoteService do
it_behaves_like 'a system note' it_behaves_like 'a system note'
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
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
end
end
describe '.approve_mr' do
let(:noteable) { create(:merge_request, source_project: project) }
subject { described_class.approve_mr(noteable, author) }
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
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' }
end
context 'when merge request approved' do
it 'sets the note text' do
expect(subject.note).to eq "unapproved this merge request"
end
end
end
describe '.change_weight_note' do describe '.change_weight_note' do
context 'when weight changed' do context 'when weight changed' do
let(:noteable) { create(:issue, project: project, title: 'Lorem ipsum', weight: 4) } let(:noteable) { create(:issue, project: project, title: 'Lorem ipsum', weight: 4) }
...@@ -124,4 +188,73 @@ describe SystemNoteService do ...@@ -124,4 +188,73 @@ describe SystemNoteService do
end end
end 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 end
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe SystemNoteService do describe SystemNoteService do
...@@ -7,11 +9,10 @@ describe SystemNoteService do ...@@ -7,11 +9,10 @@ describe SystemNoteService do
include AssetsHelpers include AssetsHelpers
set(:group) { create(:group) } set(:group) { create(:group) }
let(:project) { create(:project, :repository, group: group) } set(:project) { create(:project, :repository, group: group) }
set(: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 }
let(:epic) { create(:epic) }
shared_examples_for 'a system note' do shared_examples_for 'a system note' do
let(:expected_noteable) { noteable } let(:expected_noteable) { noteable }
...@@ -898,68 +899,6 @@ describe SystemNoteService do ...@@ -898,68 +899,6 @@ describe SystemNoteService do
end end
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
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
end
end
describe '.approve_mr' do
let(:noteable) { create(:merge_request, source_project: project) }
subject { described_class.approve_mr(noteable, author) }
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
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' }
end
context 'when merge request approved' do
it 'sets the note text' do
expect(subject.note).to eq "unapproved this merge request"
end
end
end
describe '.change_time_estimate' do describe '.change_time_estimate' do
subject { described_class.change_time_estimate(noteable, project, author) } subject { described_class.change_time_estimate(noteable, project, author) }
...@@ -1271,73 +1210,4 @@ describe SystemNoteService do ...@@ -1271,73 +1210,4 @@ describe SystemNoteService do
end end
end 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 end
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