Commit ca786c4f authored by Jarka Košanová's avatar Jarka Košanová

Improve specs and system note service

parent 086b0ef1
......@@ -69,8 +69,11 @@ module EE
create_note(NoteSummary.new(object_epic, nil, user, body, action: action))
end
def issue_promoted(noteable, noteable_ref, author)
direction = noteable.is_a?(Epic) ? :from : :to
def issue_promoted(noteable, noteable_ref, author, direction:)
unless [:to, :from].include?(direction)
raise ArgumentError, "Invalid direction `#{direction}`"
end
project = noteable.project
cross_reference = noteable_ref.to_reference(project || noteable.group)
......
......@@ -33,11 +33,11 @@ module Epics
end
def add_note_from
SystemNoteService.issue_promoted(new_entity, original_entity, current_user)
SystemNoteService.issue_promoted(new_entity, original_entity, current_user, direction: :from)
end
def add_note_to
SystemNoteService.issue_promoted(original_entity, new_entity, current_user)
SystemNoteService.issue_promoted(original_entity, new_entity, current_user, direction: :to)
end
end
end
......@@ -16,9 +16,7 @@ describe Epics::IssuePromoteService do
subject { described_class.new(issue.project, user) }
def epic
Epic.last
end
let(:epic) { Epic.last }
describe '#execute' do
context 'when epics are not enabled' do
......@@ -52,7 +50,7 @@ describe Epics::IssuePromoteService do
other_issue = create(:issue, project: create(:project))
expect { subject.execute(other_issue) }
.to raise_error(Epics::IssuePromoteService::PromoteError, /group/)
.to raise_error(Epics::IssuePromoteService::PromoteError, /group/)
end
end
......@@ -70,7 +68,7 @@ describe Epics::IssuePromoteService do
end
it 'copies group labels assigned to the issue' do
expect(Epic.last.labels).to eq([label1])
expect(epic.labels).to eq([label1])
end
it 'creates a system note on the issue' do
......
......@@ -99,7 +99,7 @@ describe SystemNoteService do
context '.issue_promoted' do
context 'note on the epic' do
subject { described_class.issue_promoted(epic, issue, author) }
subject { described_class.issue_promoted(epic, issue, author, direction: :from) }
it_behaves_like 'a system note' do
let(:action) { 'moved' }
......@@ -112,7 +112,7 @@ describe SystemNoteService do
end
context 'note on the issue' do
subject { described_class.issue_promoted(issue, epic, author) }
subject { described_class.issue_promoted(issue, epic, author, direction: :to) }
it_behaves_like 'a system note' do
let(:action) { 'moved' }
......
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