debian-mirror-gitlab/spec/controllers/projects/merge_requests/content_controller_spec.rb

107 lines
3.3 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::MergeRequests::ContentController do
2019-09-30 21:07:59 +05:30
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, target_project: project, source_project: project) }
before do
sign_in(user)
end
2021-04-29 21:17:54 +05:30
def do_request(action = :cached_widget, params = {})
2019-10-12 21:52:04 +05:30
get action, params: {
2019-09-30 21:07:59 +05:30
namespace_id: project.namespace.to_param,
project_id: project,
id: merge_request.iid,
format: :json
2021-04-29 21:17:54 +05:30
}.merge(params)
2019-09-30 21:07:59 +05:30
end
2019-10-12 21:52:04 +05:30
context 'user has access to the project' do
before do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
project.add_maintainer(user)
end
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
describe 'GET cached_widget' do
2019-09-30 21:07:59 +05:30
it 'renders widget MR entity as json' do
do_request
2019-10-12 21:52:04 +05:30
expect(response).to match_response_schema('entities/merge_request_poll_cached_widget')
2019-09-30 21:07:59 +05:30
end
2019-10-12 21:52:04 +05:30
it 'closes an MR with moved source project' do
merge_request.update_column(:source_project_id, nil)
expect { do_request }.to change { merge_request.reload.open? }.from(true).to(false)
end
end
describe 'GET widget' do
2021-04-29 21:17:54 +05:30
before do
merge_request.mark_as_unchecked!
end
2019-09-30 21:07:59 +05:30
it 'checks whether the MR can be merged' do
controller.instance_variable_set(:@merge_request, merge_request)
expect(merge_request).to receive(:check_mergeability)
2019-10-12 21:52:04 +05:30
do_request(:widget)
2020-11-24 15:15:51 +05:30
expect(response).to match_response_schema('entities/merge_request_poll_widget')
expect(response.headers['Poll-Interval']).to eq('10000')
2019-09-30 21:07:59 +05:30
end
2019-10-12 21:52:04 +05:30
context 'merged merge request' do
let(:merge_request) do
create(:merged_merge_request, :with_test_reports, target_project: project, source_project: project)
end
2019-09-30 21:07:59 +05:30
2020-11-24 15:15:51 +05:30
it 'renders widget MR entity as json' do
do_request(:widget)
expect(response).to match_response_schema('entities/merge_request_poll_widget')
expect(response.headers['Poll-Interval']).to eq('300000')
end
end
context 'with coverage data' do
let(:merge_request) { create(:merge_request, target_project: project, source_project: project, head_pipeline: head_pipeline) }
let!(:base_pipeline) { create(:ci_empty_pipeline, project: project, ref: merge_request.target_branch, sha: merge_request.diff_base_sha) }
let!(:head_pipeline) { create(:ci_empty_pipeline, project: project) }
let!(:rspec_base) { create(:ci_build, name: 'rspec', coverage: 93.1, pipeline: base_pipeline) }
let!(:rspec_head) { create(:ci_build, name: 'rspec', coverage: 97.1, pipeline: head_pipeline) }
2019-10-12 21:52:04 +05:30
it 'renders widget MR entity as json' do
do_request(:widget)
expect(response).to match_response_schema('entities/merge_request_poll_widget')
end
2019-09-30 21:07:59 +05:30
end
end
2019-10-12 21:52:04 +05:30
end
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
context 'user does not have access to the project' do
describe 'GET cached_widget' do
it 'returns 404' do
2019-09-30 21:07:59 +05:30
do_request
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-09-30 21:07:59 +05:30
end
end
2019-10-12 21:52:04 +05:30
describe 'GET widget' do
it 'returns 404' do
do_request(:widget)
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-10-12 21:52:04 +05:30
end
end
2019-09-30 21:07:59 +05:30
end
end