Commit 3fdccc12 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Adjust Issue references pluralization on success message

parent a2f93a75
...@@ -15,7 +15,7 @@ module RelatedIssues ...@@ -15,7 +15,7 @@ module RelatedIssues
return error(exception.message, 401) return error(exception.message, 401)
end end
success(message: "#{issues_sentence(referenced_issues)} were successfully related") success_message
end end
private private
...@@ -50,6 +50,12 @@ module RelatedIssues ...@@ -50,6 +50,12 @@ module RelatedIssues
end end
end end
def success_message
verb = referenced_issues.size > 1 ? 'were' : 'was'
success(message: "#{issues_sentence(referenced_issues)} #{verb} successfully related")
end
def issues_sentence(issues) def issues_sentence(issues)
issues.map { |issue| issue.to_reference(@issue.project) }.sort.to_sentence issues.map { |issue| issue.to_reference(@issue.project) }.sort.to_sentence
end end
......
...@@ -16,7 +16,7 @@ describe RelatedIssues::CreateService, service: true do ...@@ -16,7 +16,7 @@ describe RelatedIssues::CreateService, service: true do
subject { described_class.new(issue, user, params).execute } subject { described_class.new(issue, user, params).execute }
context 'when issue not found' do context 'when Issue not found' do
let(:params) do let(:params) do
{ issue_references: ['#999'] } { issue_references: ['#999'] }
end end
...@@ -46,7 +46,7 @@ describe RelatedIssues::CreateService, service: true do ...@@ -46,7 +46,7 @@ describe RelatedIssues::CreateService, service: true do
end end
end end
context 'when all Issue references are valid' do context 'when any Issue to relate' do
let(:issue_a) { create :issue, project: project } let(:issue_a) { create :issue, project: project }
let(:another_project) { create :empty_project, namespace: project.namespace } let(:another_project) { create :empty_project, namespace: project.namespace }
let(:another_project_issue) { create :issue, project: another_project } let(:another_project_issue) { create :issue, project: another_project }
...@@ -69,7 +69,7 @@ describe RelatedIssues::CreateService, service: true do ...@@ -69,7 +69,7 @@ describe RelatedIssues::CreateService, service: true do
expect(RelatedIssue.last).to have_attributes(issue: issue, related_issue: another_project_issue) expect(RelatedIssue.last).to have_attributes(issue: issue, related_issue: another_project_issue)
end end
it 'returns success message with Issue references' do it 'returns success message with Issue reference' do
is_expected.to eq(message: "#{issue_a_ref} and #{another_project_issue_ref} were successfully related", status: :success) is_expected.to eq(message: "#{issue_a_ref} and #{another_project_issue_ref} were successfully related", status: :success)
end end
...@@ -90,6 +90,39 @@ describe RelatedIssues::CreateService, service: true do ...@@ -90,6 +90,39 @@ describe RelatedIssues::CreateService, service: true do
end end
end end
context 'success message' do
let(:issue_a) { create :issue, project: project }
let(:another_project) { create :empty_project, namespace: project.namespace }
let(:another_project_issue) { create :issue, project: another_project }
let(:issue_a_ref) { issue_a.to_reference }
let(:another_project_issue_ref) { another_project_issue.to_reference(project) }
before do
another_project.team << [user, :developer]
end
context 'multiple Issues relation' do
let(:params) do
{ issue_references: [issue_a_ref, another_project_issue_ref] }
end
it 'returns success message with Issue reference' do
is_expected.to eq(message: "#{issue_a_ref} and #{another_project_issue_ref} were successfully related", status: :success)
end
end
context 'single Issue relation' do
let(:params) do
{ issue_references: [issue_a_ref] }
end
it 'returns success message with Issue reference' do
is_expected.to eq(message: "#{issue_a_ref} was successfully related", status: :success)
end
end
end
context 'when relation already exists' do context 'when relation already exists' do
let(:issue_a) { create :issue, project: project } let(:issue_a) { create :issue, project: project }
let(:issue_b) { create :issue, project: project } let(:issue_b) { create :issue, project: project }
......
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