Commit cdf0af66 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'i-#25814-500-error' into 'master'

Fix Compare page throws 500 error when any branch/reference is not selected

Closes #25814

See merge request !8523
parents f5ff5dc2 856003cf
...@@ -25,9 +25,18 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -25,9 +25,18 @@ class Projects::CompareController < Projects::ApplicationController
end end
def create def create
if params[:from].blank? || params[:to].blank?
flash[:alert] = "You must select from and to branches"
from_to_vars = {
from: params[:from].presence,
to: params[:to].presence
}
redirect_to namespace_project_compare_index_path(@project.namespace, @project, from_to_vars)
else
redirect_to namespace_project_compare_path(@project.namespace, @project, redirect_to namespace_project_compare_path(@project.namespace, @project,
params[:from], params[:to]) params[:from], params[:to])
end end
end
private private
......
---
title: Fix Compare page throws 500 error when any branch/reference is not selected
merge_request: 8492
author: Martin Cabrera
...@@ -64,6 +64,36 @@ describe Projects::CompareController do ...@@ -64,6 +64,36 @@ describe Projects::CompareController do
expect(assigns(:diffs)).to eq(nil) expect(assigns(:diffs)).to eq(nil)
expect(assigns(:commits)).to eq(nil) expect(assigns(:commits)).to eq(nil)
end end
it 'redirects back to index when params[:from] is empty and preserves params[:to]' do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
from: '',
to: 'master')
expect(response).to redirect_to(namespace_project_compare_index_path(project.namespace, project, to: 'master'))
end
it 'redirects back to index when params[:to] is empty and preserves params[:from]' do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
from: 'master',
to: '')
expect(response).to redirect_to(namespace_project_compare_index_path(project.namespace, project, from: 'master'))
end
it 'redirects back to index when params[:from] and params[:to] are empty' do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
from: '',
to: '')
expect(response).to redirect_to(namespace_project_compare_index_path)
end
end end
describe 'GET diff_for_path' do describe 'GET diff_for_path' do
......
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