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