Commit a375d80e authored by Shinya Maeda's avatar Shinya Maeda

Use detailed_status effectively. Remove unnecesarry context(nest). Add new...

Use detailed_status effectively. Remove unnecesarry context(nest). Add new context in merge_requests_controller_spec.rb and fix a bug. Correct description of spec.
parent 6dcd2d59
...@@ -474,6 +474,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -474,6 +474,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def pipeline_status def pipeline_status
render json: {} and return unless @merge_request.head_pipeline.present?
render json: PipelineSerializer render json: PipelineSerializer
.new(project: @project, user: @current_user) .new(project: @project, user: @current_user)
.represent_status(@merge_request.head_pipeline) .represent_status(@merge_request.head_pipeline)
......
...@@ -11,27 +11,23 @@ describe Projects::BuildsController do ...@@ -11,27 +11,23 @@ describe Projects::BuildsController do
end end
describe 'GET status.json' do describe 'GET status.json' do
context 'when accessing status' do let(:pipeline) { create(:ci_pipeline, project: project) }
let(:status) do let(:build) { create(:ci_build, pipeline: pipeline) }
Gitlab::Ci::Status::Success.new(double('object'), double('user')) let(:status) { build.detailed_status(double('user')) }
end
before do before do
pipeline = create(:ci_pipeline, project: project) get :status, namespace_id: project.namespace,
build = create(:ci_build, pipeline: pipeline, status: :success) project_id: project,
get :status, namespace_id: project.namespace, id: build.id,
project_id: project, format: :json
id: build.id, end
format: :json
end
it 'return a correct pipeline status' do it 'return a detailed build status in json' do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(json_response['text']).to eq status.text expect(json_response['text']).to eq status.text
expect(json_response['label']).to eq status.label expect(json_response['label']).to eq status.label
expect(json_response['icon']).to eq status.icon expect(json_response['icon']).to eq status.icon
expect(json_response['favicon']).to eq status.favicon expect(json_response['favicon']).to eq status.favicon
end
end end
end end
end end
...@@ -1180,23 +1180,18 @@ describe Projects::MergeRequestsController do ...@@ -1180,23 +1180,18 @@ describe Projects::MergeRequestsController do
end end
describe 'GET pipeline_status.json' do describe 'GET pipeline_status.json' do
context 'when accessing pipeline_status' do context 'when head_pipeline exists' do
let(:status) do let!(:pipeline) do
Gitlab::Ci::Status::Success.new(double('object'), double('user'))
end
before do
create(:ci_pipeline, project: merge_request.source_project, create(:ci_pipeline, project: merge_request.source_project,
ref: merge_request.source_branch, ref: merge_request.source_branch,
sha: merge_request.diff_head_sha, sha: merge_request.diff_head_sha)
status: :success)
get :pipeline_status, namespace_id: project.namespace,
project_id: project,
id: merge_request.iid,
format: :json
end end
it 'return a correct pipeline status' do let(:status) { pipeline.detailed_status(double('user')) }
before { get_pipeline_status }
it 'return a detailed head_pipeline status in json' do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(json_response['text']).to eq status.text expect(json_response['text']).to eq status.text
expect(json_response['label']).to eq status.label expect(json_response['label']).to eq status.label
...@@ -1204,5 +1199,21 @@ describe Projects::MergeRequestsController do ...@@ -1204,5 +1199,21 @@ describe Projects::MergeRequestsController do
expect(json_response['favicon']).to eq status.favicon expect(json_response['favicon']).to eq status.favicon
end end
end end
context 'when head_pipeline does not exist' do
before { get_pipeline_status }
it 'return empty' do
expect(response).to have_http_status(:ok)
expect(json_response).to be_empty
end
end
def get_pipeline_status
get :pipeline_status, namespace_id: project.namespace,
project_id: project,
id: merge_request.iid,
format: :json
end
end end
end end
...@@ -71,26 +71,22 @@ describe Projects::PipelinesController do ...@@ -71,26 +71,22 @@ describe Projects::PipelinesController do
end end
describe 'GET status.json' do describe 'GET status.json' do
context 'when accessing status' do let(:pipeline) { create(:ci_pipeline, project: project) }
let(:status) do let(:status) { pipeline.detailed_status(double('user')) }
Gitlab::Ci::Status::Success.new(double('object'), double('user'))
end
before do before do
pipeline = create(:ci_pipeline, project: project, status: :success) get :status, namespace_id: project.namespace,
get :status, namespace_id: project.namespace, project_id: project,
project_id: project, id: pipeline.id,
id: pipeline.id, format: :json
format: :json end
end
it 'return a correct pipeline status' do it 'return a detailed pipeline status in json' do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(json_response['text']).to eq status.text expect(json_response['text']).to eq status.text
expect(json_response['label']).to eq status.label expect(json_response['label']).to eq status.label
expect(json_response['icon']).to eq status.icon expect(json_response['icon']).to eq status.icon
expect(json_response['favicon']).to eq status.favicon expect(json_response['favicon']).to eq status.favicon
end
end end
end end
end end
...@@ -29,10 +29,8 @@ describe BuildSerializer do ...@@ -29,10 +29,8 @@ describe BuildSerializer do
describe '#represent_status' do describe '#represent_status' do
context 'when represents only status' do context 'when represents only status' do
let(:status) do let(:resource) { create(:ci_build) }
Gitlab::Ci::Status::Success.new(double('object'), double('user')) let(:status) { resource.detailed_status(double('user')) }
end
let(:resource) { create(:ci_build, status: :success) }
subject { serializer.represent_status(resource) } subject { serializer.represent_status(resource) }
......
...@@ -97,10 +97,8 @@ describe PipelineSerializer do ...@@ -97,10 +97,8 @@ describe PipelineSerializer do
describe '#represent_status' do describe '#represent_status' do
context 'when represents only status' do context 'when represents only status' do
let(:status) do let(:resource) { create(:ci_pipeline) }
Gitlab::Ci::Status::Success.new(double('object'), double('user')) let(:status) { resource.detailed_status(double('user')) }
end
let(:resource) { create(:ci_pipeline, status: :success) }
subject { serializer.represent_status(resource) } subject { serializer.represent_status(resource) }
......
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