BigW Consortium Gitlab

Commit 49ac0146 by Sean McGivern Committed by James Lopez

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
parent 9f0f38e9
......@@ -25,8 +25,17 @@ class Projects::CompareController < Projects::ApplicationController
end
def create
redirect_to namespace_project_compare_path(@project.namespace, @project,
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,
params[:from], params[:to])
end
end
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
expect(assigns(:diffs)).to eq(nil)
expect(assigns(:commits)).to eq(nil)
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
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