debian-mirror-gitlab/spec/serializers/merge_request_widget_entity_spec.rb

188 lines
5.6 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
describe MergeRequestWidgetEntity do
2018-12-13 13:39:08 +05:30
include ProjectForksHelper
2018-03-17 18:26:18 +05:30
let(:project) { create :project, :repository }
let(:resource) { create(:merge_request, source_project: project, target_project: project) }
let(:user) { create(:user) }
let(:request) { double('request', current_user: user, project: project) }
subject do
described_class.new(resource, request: request).as_json
end
2018-11-18 11:00:15 +05:30
describe 'source_project_full_path' do
it 'includes the full path of the source project' do
expect(subject[:source_project_full_path]).to be_present
end
context 'when the source project is missing' do
it 'returns `nil` for the source project' do
resource.allow_broken = true
resource.update!(source_project: nil)
expect(subject[:source_project_full_path]).to be_nil
end
end
end
2019-09-04 21:01:54 +05:30
describe 'issues links' do
it 'includes issues links when requested' do
data = described_class.new(resource, request: request, issues_links: true).as_json
expect(data).to include(:issues_links)
expect(data[:issues_links]).to include(:assign_to_closing, :closing, :mentioned_but_not_closing)
end
it 'omits issue links by default' do
expect(subject).not_to include(:issues_links)
end
end
2018-03-17 18:26:18 +05:30
it 'has email_patches_path' do
expect(subject[:email_patches_path])
2020-03-13 15:44:24 +05:30
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.patch")
2018-03-17 18:26:18 +05:30
end
it 'has plain_diff_path' do
expect(subject[:plain_diff_path])
2020-03-13 15:44:24 +05:30
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff")
end
describe 'merge_request_add_ci_config_path' do
before do
project.add_role(user, role)
end
context 'when there are pipelines' do
let(:role) { :developer }
before do
create(:ci_empty_pipeline, project: project, sha: resource.all_commit_shas.first, ref: resource.source_branch)
end
it 'no ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when there are no pipelines' do
context 'when user has permissions' do
let(:role) { :developer }
it 'has add ci config path' do
2020-04-08 14:13:33 +05:30
expected_path = "/#{resource.project.full_path}/-/new/#{resource.source_branch}?commit_message=Add+.gitlab-ci.yml&file_name=.gitlab-ci.yml&suggest_gitlab_ci_yml=true"
expect(subject[:merge_request_add_ci_config_path]).to eq(expected_path)
2020-03-13 15:44:24 +05:30
end
context 'when source project is missing' do
before do
resource.source_project = nil
end
it 'returns a blank ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when there are no commits' do
before do
allow(resource).to receive(:commits_count).and_return(0)
end
it 'returns a blank ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when ci_config_path is customized' do
it 'has no path if ci_config_path is not set to our default setting' do
project.ci_config_path = 'not_default'
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
it 'has a path if ci_config_path unset' do
expect(subject[:merge_request_add_ci_config_path]).not_to be_nil
end
it 'has a path if ci_config_path is an empty string' do
project.ci_config_path = ''
expect(subject[:merge_request_add_ci_config_path]).not_to be_nil
end
it 'has a path if ci_config_path is set to our default file' do
project.ci_config_path = Gitlab::FileDetector::PATTERNS[:gitlab_ci]
expect(subject[:merge_request_add_ci_config_path]).not_to be_nil
end
end
2020-04-08 14:13:33 +05:30
context 'when build feature is disabled' do
before do
project.project_feature.update(builds_access_level: ProjectFeature::DISABLED)
end
it 'has no path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when creating the pipeline is not allowed' do
before do
user.state = 'blocked'
end
it 'has no path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
2020-03-13 15:44:24 +05:30
end
context 'when user does not have permissions' do
let(:role) { :reporter }
it 'has add ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
end
end
it 'has human access' do
project.add_maintainer(user)
expect(subject[:human_access])
.to eq('Maintainer')
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
it 'has new pipeline path for project' do
project.add_maintainer(user)
expect(subject[:new_project_pipeline_path])
.to eq("/#{resource.project.full_path}/pipelines/new")
end
2018-03-17 18:26:18 +05:30
describe 'when source project is deleted' do
let(:project) { create(:project, :repository) }
2018-12-13 13:39:08 +05:30
let(:forked_project) { fork_project(project) }
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
2018-03-17 18:26:18 +05:30
it 'returns a blank rebase_path' do
allow(merge_request).to receive(:should_be_rebased?).and_return(true)
2018-12-13 13:39:08 +05:30
forked_project.destroy
2018-03-17 18:26:18 +05:30
merge_request.reload
entity = described_class.new(merge_request, request: request).as_json
expect(entity[:rebase_path]).to be_nil
end
end
end