Commit 258e4e97 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Use CreateRelatedIssueService on RelatedIssuesController#create

parent 086ad4d7
...@@ -2,13 +2,17 @@ module Projects ...@@ -2,13 +2,17 @@ module Projects
class RelatedIssuesController < ApplicationController class RelatedIssuesController < ApplicationController
include IssuesHelper include IssuesHelper
before_action :authorize_read_issue!, only: [:index] before_action :authorize_read_issue!, only: [:index, :create]
def index def index
render json: serialize_as_json render json: serialize_as_json
end end
def create def create
opts = { issue_references: params[:issue_references] }
result = CreateRelatedIssueService.new(issue, current_user, opts).execute
render json: result, status: result['http_status']
end end
private private
......
...@@ -5,7 +5,7 @@ describe Projects::RelatedIssuesController, type: :controller do ...@@ -5,7 +5,7 @@ describe Projects::RelatedIssuesController, type: :controller do
let(:project) { create(:project_empty_repo) } let(:project) { create(:project_empty_repo) }
let(:issue) { create :issue, project: project } let(:issue) { create :issue, project: project }
describe "GET #index" do describe 'GET #index' do
let(:issue_b) { create :issue, project: project } let(:issue_b) { create :issue, project: project }
let(:issue_c) { create :issue, project: project } let(:issue_c) { create :issue, project: project }
let(:issue_d) { create :issue, project: project } let(:issue_d) { create :issue, project: project }
...@@ -28,7 +28,7 @@ describe Projects::RelatedIssuesController, type: :controller do ...@@ -28,7 +28,7 @@ describe Projects::RelatedIssuesController, type: :controller do
created_at: Date.today) created_at: Date.today)
end end
it "returns related issues JSON" do it 'returns related issues JSON' do
sign_in user sign_in user
project.team << [user, :developer] project.team << [user, :developer]
...@@ -70,10 +70,45 @@ describe Projects::RelatedIssuesController, type: :controller do ...@@ -70,10 +70,45 @@ describe Projects::RelatedIssuesController, type: :controller do
end end
end end
xdescribe "GET #create" do describe 'POST #create' do
it "returns http success" do let(:service) { double(CreateRelatedIssueService, execute: service_response) }
get :create let(:service_response) { { 'message' => 'yay' } }
expect(response).to have_http_status(:success) let(:issue_references) { double }
before do
project.team << [user, :developer]
allow(CreateRelatedIssueService).to receive(:new)
.with(issue, user, { issue_references: issue_references })
.and_return(service)
end
subject do
sign_in user
post :create, namespace_id: issue.project.namespace,
project_id: issue.project,
issue_id: issue,
issue_references: issue_references,
format: :json
end
context 'with success' do
it 'returns success JSON' do
is_expected.to have_http_status(200)
expect(json_response).to eq(service_response)
end
end
context 'with failure' do
context 'when failure service result' do
let(:service_response) { { 'http_status' => 401 } }
it 'returns failure JSON' do
is_expected.to have_http_status(401)
expect(json_response).to eq(service_response)
end
end
end 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