Commit 248970ab authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Addresses aesthetic details on text and naming

parent 9d389de0
...@@ -7,10 +7,10 @@ module Projects ...@@ -7,10 +7,10 @@ module Projects
end end
def create def create
opts = params.slice(:issue_references) create_params = params.slice(:issue_references)
result = IssueLinks::CreateService.new(issue, current_user, opts).execute result = IssueLinks::CreateService.new(issue, current_user, create_params).execute
render json: { result: result, issues: issues }, status: result[:http_status] render json: { message: result[:message], issues: issues }, status: result[:http_status]
end end
def destroy def destroy
...@@ -18,9 +18,9 @@ module Projects ...@@ -18,9 +18,9 @@ module Projects
return render_403 unless can?(current_user, :admin_issue_link, issue_link.target.project) return render_403 unless can?(current_user, :admin_issue_link, issue_link.target.project)
result = IssueLinks::DestroyService.new(issue_link, current_user).execute IssueLinks::DestroyService.new(issue_link, current_user).execute
render json: { result: result, issues: issues } render json: { issues: issues }
end end
private private
......
...@@ -10,7 +10,7 @@ class IssueLink < ActiveRecord::Base ...@@ -10,7 +10,7 @@ class IssueLink < ActiveRecord::Base
private private
def check_self_relation def check_self_relation
return unless source || target return unless source && target
if source == target if source == target
errors.add(:source, 'cannot be related to itself') errors.add(:source, 'cannot be related to itself')
......
...@@ -2,7 +2,8 @@ class SystemNoteMetadata < ActiveRecord::Base ...@@ -2,7 +2,8 @@ class SystemNoteMetadata < ActiveRecord::Base
ICON_TYPES = %w[ ICON_TYPES = %w[
commit description merge confidential visible label assignee cross_reference commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved opened closed merged title time_tracking branch milestone discussion task moved opened closed merged
outdated approved unapproved relate unrelate outdated
approved unapproved relate unrelate
].freeze ].freeze
validates :note, presence: true validates :note, presence: true
......
...@@ -9,13 +9,13 @@ module IssueLinks ...@@ -9,13 +9,13 @@ module IssueLinks
return error('No Issue found for given reference', 401) return error('No Issue found for given reference', 401)
end end
create_issue_link create_issue_links
success success
end end
private private
def create_issue_link def create_issue_links
referenced_issues.each do |referenced_issue| referenced_issues.each do |referenced_issue|
create_notes(referenced_issue) if relate_issues(referenced_issue) create_notes(referenced_issue) if relate_issues(referenced_issue)
end end
......
...@@ -8,19 +8,19 @@ module IssueLinks ...@@ -8,19 +8,19 @@ module IssueLinks
end end
def execute def execute
remove_relation! remove_relation
create_notes! create_notes
success(message: 'Relation was removed') success(message: 'Relation was removed')
end end
private private
def remove_relation! def remove_relation
@issue_link.destroy! @issue_link.destroy!
end end
def create_notes! def create_notes
SystemNoteService.unrelate_issue(@issue, @referenced_issue, current_user) SystemNoteService.unrelate_issue(@issue, @referenced_issue, current_user)
SystemNoteService.unrelate_issue(@referenced_issue, @issue, current_user) SystemNoteService.unrelate_issue(@referenced_issue, @issue, current_user)
end end
......
...@@ -18,8 +18,20 @@ describe IssueLink do ...@@ -18,8 +18,20 @@ describe IssueLink do
end end
context 'self relation' do context 'self relation' do
let(:issue) { create :issue }
context 'cannot be validated' do
it 'does not invalidate object with self relation error' do
issue_link = build :issue_link, source: issue, target: nil
issue_link.valid?
expect(issue_link.errors[:source]).to be_empty
end
end
context 'can be invalidated' do
it 'invalidates object' do it 'invalidates object' do
issue = create :issue
issue_link = build :issue_link, source: issue, target: issue issue_link = build :issue_link, source: issue, target: issue
expect(issue_link).to be_invalid expect(issue_link).to be_invalid
...@@ -27,4 +39,5 @@ describe IssueLink do ...@@ -27,4 +39,5 @@ describe IssueLink do
end end
end end
end end
end
end end
...@@ -19,17 +19,10 @@ describe Projects::IssueLinksController do ...@@ -19,17 +19,10 @@ describe Projects::IssueLinksController do
login_as user login_as user
end end
subject do
get namespace_project_issue_links_path(namespace_id: issue.project.namespace,
project_id: issue.project,
issue_id: issue,
format: :json)
end
it 'returns JSON response' do it 'returns JSON response' do
list_service_response = IssueLinks::ListService.new(issue, user).execute list_service_response = IssueLinks::ListService.new(issue, user).execute
subject get namespace_project_issue_links_path(issue_links_params)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to eq(list_service_response.as_json) expect(json_response).to eq(list_service_response.as_json)
...@@ -38,87 +31,70 @@ describe Projects::IssueLinksController do ...@@ -38,87 +31,70 @@ describe Projects::IssueLinksController do
describe 'POST /*namespace_id/:project_id/issues/:issue_id/links' do describe 'POST /*namespace_id/:project_id/issues/:issue_id/links' do
let(:issue_b) { create :issue, project: project } let(:issue_b) { create :issue, project: project }
let(:issue_references) { [issue_b.to_reference] }
let(:user_role) { :developer }
before do before do
project.team << [user, user_role] project.team << [user, user_role]
login_as user login_as user
end end
subject do
post namespace_project_issue_links_path(namespace_id: issue.project.namespace,
project_id: issue.project,
issue_id: issue,
issue_references: issue_references,
format: :json)
end
context 'with success' do context 'with success' do
let(:user_role) { :developer }
let(:issue_references) { [issue_b.to_reference] }
it 'returns success JSON' do it 'returns success JSON' do
subject post namespace_project_issue_links_path(issue_links_params(issue_references: issue_references))
list_service_response = IssueLinks::ListService.new(issue, user).execute list_service_response = IssueLinks::ListService.new(issue, user).execute
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['result']).to eq('status' => 'success') expect(json_response).to eq('message' => nil,
expect(json_response['issues']).to eq(list_service_response.as_json) 'issues' => list_service_response.as_json)
end end
end end
context 'with failure' do context 'with failure' do
context 'when unauthorized' do context 'when unauthorized' do
let(:user_role) { :guest } let(:user_role) { :guest }
let(:issue_references) { [issue_b.to_reference] }
it 'returns 403' do it 'returns 403' do
subject post namespace_project_issue_links_path(issue_links_params(issue_references: issue_references))
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context 'when failing service result' do context 'when failing service result' do
let(:user_role) { :developer }
let(:issue_references) { ['#999'] } let(:issue_references) { ['#999'] }
it 'returns failure JSON' do it 'returns failure JSON' do
subject post namespace_project_issue_links_path(issue_links_params(issue_references: issue_references))
list_service_response = IssueLinks::ListService.new(issue, user).execute list_service_response = IssueLinks::ListService.new(issue, user).execute
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
expect(json_response['result']).to eq('message' => 'No Issue found for given reference', expect(json_response).to eq('message' => 'No Issue found for given reference', 'issues' => list_service_response.as_json)
'status' => 'error',
'http_status' => 401)
expect(json_response['issues']).to eq(list_service_response.as_json)
end end
end end
end end
end end
describe 'DELETE /*namespace_id/:project_id/issues/:issue_id/link/:id' do describe 'DELETE /*namespace_id/:project_id/issues/:issue_id/link/:id' do
let(:referenced_issue) { create :issue, project: project }
let(:issue_link) { create :issue_link, target: referenced_issue } let(:issue_link) { create :issue_link, target: referenced_issue }
let(:current_project_user_role) { :developer }
subject do
delete namespace_project_issue_link_path(namespace_id: issue.project.namespace,
project_id: issue.project,
issue_id: issue,
id: issue_link.id,
format: :json)
end
before do before do
project.team << [user, current_project_user_role] project.team << [user, user_role]
login_as user login_as user
end end
context 'when unauthorized' do context 'when unauthorized' do
context 'when no authorization on current project' do context 'when no authorization on current project' do
let(:current_project_user_role) { :guest } let(:referenced_issue) { create :issue, project: project }
let(:user_role) { :guest }
it 'returns 403' do it 'returns 403' do
subject delete namespace_project_issue_link_path(issue_links_params(id: issue_link.id))
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
...@@ -127,10 +103,10 @@ describe Projects::IssueLinksController do ...@@ -127,10 +103,10 @@ describe Projects::IssueLinksController do
context 'when no authorization on the related issue project' do context 'when no authorization on the related issue project' do
# unauthorized project issue # unauthorized project issue
let(:referenced_issue) { create :issue } let(:referenced_issue) { create :issue }
let(:current_project_user_role) { :developer } let(:user_role) { :developer }
it 'returns 403' do it 'returns 403' do
subject delete namespace_project_issue_link_path(issue_links_params(id: issue_link.id))
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
...@@ -138,16 +114,23 @@ describe Projects::IssueLinksController do ...@@ -138,16 +114,23 @@ describe Projects::IssueLinksController do
end end
context 'when authorized' do context 'when authorized' do
let(:current_project_user_role) { :developer } let(:referenced_issue) { create :issue, project: project }
let(:user_role) { :developer }
it 'returns success JSON' do it 'returns success JSON' do
subject delete namespace_project_issue_link_path(issue_links_params(id: issue_link.id))
list_service_response = IssueLinks::ListService.new(issue, user).execute list_service_response = IssueLinks::ListService.new(issue, user).execute
expect(json_response['result']).to eq('message' => 'Relation was removed', 'status' => 'success') expect(json_response).to eq('issues' => list_service_response.as_json)
expect(json_response['issues']).to eq(list_service_response.as_json) end
end end
end end
def issue_links_params(opts = {})
opts.reverse_merge(namespace_id: issue.project.namespace,
project_id: issue.project,
issue_id: issue,
format: :json)
end end
end end
...@@ -19,7 +19,7 @@ describe IssueLinks::CreateService, service: true do ...@@ -19,7 +19,7 @@ describe IssueLinks::CreateService, service: true do
subject { described_class.new(issue, user, params).execute } subject { described_class.new(issue, user, params).execute }
context 'when empty reference list' do context 'when the reference list is empty' do
let(:params) do let(:params) do
{ issue_references: [] } { issue_references: [] }
end end
...@@ -61,7 +61,7 @@ describe IssueLinks::CreateService, service: true do ...@@ -61,7 +61,7 @@ describe IssueLinks::CreateService, service: true do
end end
end end
context 'when any Issue to relate' do context 'when there is an 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 }
...@@ -84,7 +84,7 @@ describe IssueLinks::CreateService, service: true do ...@@ -84,7 +84,7 @@ describe IssueLinks::CreateService, service: true do
expect(IssueLink.find_by!(target: another_project_issue)).to have_attributes(source: issue) expect(IssueLink.find_by!(target: another_project_issue)).to have_attributes(source: issue)
end end
it 'returns success message with Issue reference' do it 'returns success status' do
is_expected.to eq(status: :success) is_expected.to eq(status: :success)
end end
...@@ -117,7 +117,7 @@ describe IssueLinks::CreateService, service: true do ...@@ -117,7 +117,7 @@ describe IssueLinks::CreateService, service: true do
{ issue_references: [issue_b.to_reference, issue_a.to_reference] } { issue_references: [issue_b.to_reference, issue_a.to_reference] }
end end
it 'returns success' do it 'returns success status' do
is_expected.to eq(status: :success) is_expected.to eq(status: :success)
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