Commit e6d31ce3 authored by Sean McGivern's avatar Sean McGivern

Merge branch '24860-actionview-template-error-undefined-method-size-for-nil-nilclass' into 'master'

Prevent error when submitting a merge request and pipeline is not defined

Closes #24860

See merge request !7707
parents 333e83a2 d9a2093e
......@@ -564,7 +564,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def define_pipelines_vars
@pipelines = @merge_request.all_pipelines
@pipeline = @merge_request.pipeline
@statuses = @pipeline.statuses.relevant if @pipeline.present?
@statuses_count = @pipeline.present? ? @pipeline.statuses.relevant.count : 0
end
def define_new_vars
......
......@@ -781,7 +781,7 @@ class MergeRequest < ActiveRecord::Base
end
def all_pipelines
return unless source_project
return Ci::Pipeline.none unless source_project
@all_pipelines ||= source_project.pipelines
.where(sha: all_commits_sha, ref: source_branch)
......
......@@ -34,10 +34,11 @@
= link_to url_for(params), data: {target: 'div#pipelines', action: 'pipelines', toggle: 'tab'} do
Pipelines
%span.badge= @pipelines.size
- if @pipeline.present?
%li.builds-tab
= link_to url_for(params), data: {target: 'div#builds', action: 'builds', toggle: 'tab'} do
Builds
%span.badge= @statuses.size
%span.badge= @statuses_count
%li.diffs-tab
= link_to url_for(params.merge(action: 'new_diffs')), data: {target: 'div#diffs', action: 'new/diffs', toggle: 'tab'} do
Changes
......@@ -48,9 +49,10 @@
= render "projects/merge_requests/show/commits"
#diffs.diffs.tab-pane
- # This tab is always loaded via AJAX
- if @pipelines.any?
- if @pipeline.present?
#builds.builds.tab-pane
= render "projects/merge_requests/show/builds"
- if @pipelines.any?
#pipelines.pipelines.tab-pane
= render "projects/merge_requests/show/pipelines"
......@@ -65,5 +67,5 @@
:javascript
var merge_request = new MergeRequest({
action: "#{(@show_changes_tab ? 'new/diffs' : 'new')}",
buildsLoaded: "#{@pipelines.any? ? 'true' : 'false'}"
buildsLoaded: "#{@pipeline.present? ? 'true' : 'false'}"
});
......@@ -59,15 +59,16 @@
= link_to commits_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#commits', action: 'commits', toggle: 'tab' } do
Commits
%span.badge= @commits_count
- if @pipeline
- if @pipelines.any?
%li.pipelines-tab
= link_to pipelines_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#pipelines', action: 'pipelines', toggle: 'tab' } do
Pipelines
%span.badge= @pipelines.size
- if @pipeline.present?
%li.builds-tab
= link_to builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#builds', action: 'builds', toggle: 'tab' } do
Builds
%span.badge= @statuses.size
%span.badge= @statuses_count
%li.diffs-tab
= link_to diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#diffs', action: 'diffs', toggle: 'tab' } do
Changes
......
---
title: Prevent error when submitting a merge request and pipeline is not defined
merge_request: 7707
author:
require 'spec_helper'
describe 'projects/merge_requests/_new_submit.html.haml', :view do
let(:merge_request) { create(:merge_request) }
let!(:pipeline) { create(:ci_empty_pipeline) }
before do
controller.prepend_view_path('app/views/projects')
assign(:merge_request, merge_request)
assign(:commits, merge_request.commits)
assign(:project, merge_request.target_project)
allow(view).to receive(:can?).and_return(true)
allow(view).to receive(:url_for).and_return('#')
allow(view).to receive(:current_user).and_return(merge_request.author)
end
context 'when there are pipelines for merge request but no pipeline for last commit' do
before do
assign(:pipelines, Ci::Pipeline.all)
assign(:pipeline, nil)
end
it 'shows <<Pipelines>> tab and hides <<Builds>> tab' do
render
expect(rendered).to have_text('Pipelines 1')
expect(rendered).not_to have_text('Builds')
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