diff options
author | Felipe Artur <felipefac@gmail.com> | 2018-01-11 23:18:01 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2018-01-15 16:53:40 +0300 |
commit | ca4a59e3df2a8cd64c4055528dde9cb8dd58a369 (patch) | |
tree | ed3ea6228c8bf17cf1197dedba31feb3dcd7c849 | |
parent | 34760245bcb4156e21ca463b82b1fab84508b842 (diff) |
Fix error on changes tab when merge request cannot be created
4 files changed, 36 insertions, 23 deletions
diff --git a/app/controllers/projects/merge_requests/creations_controller.rb b/app/controllers/projects/merge_requests/creations_controller.rb index 3d2926d5d75..0df80fa700f 100644 --- a/app/controllers/projects/merge_requests/creations_controller.rb +++ b/app/controllers/projects/merge_requests/creations_controller.rb @@ -43,11 +43,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap end def diffs - @diffs = if @merge_request.can_be_created - @merge_request.diffs(diff_options) - else - [] - end + @diffs = @merge_request.diffs(diff_options) if @merge_request.can_be_created @diff_notes_disabled = true diff --git a/app/views/projects/merge_requests/creations/_diffs.html.haml b/app/views/projects/merge_requests/creations/_diffs.html.haml index 627fc4e9671..5b70e894b39 100644 --- a/app/views/projects/merge_requests/creations/_diffs.html.haml +++ b/app/views/projects/merge_requests/creations/_diffs.html.haml @@ -1 +1,5 @@ -= render "projects/diffs/diffs", diffs: @diffs, environment: @environment, show_whitespace_toggle: false +- if @merge_request.can_be_created + = render "projects/diffs/diffs", diffs: @diffs, environment: @environment, show_whitespace_toggle: false +- else + .nothing-here-block + This merge request cannot be created. diff --git a/changelogs/unreleased/issue_41460.yml b/changelogs/unreleased/issue_41460.yml new file mode 100644 index 00000000000..24d3eae6bf8 --- /dev/null +++ b/changelogs/unreleased/issue_41460.yml @@ -0,0 +1,5 @@ +--- +title: Fix error on changes tab when merge request cannot be created +merge_request: +author: +type: fixed diff --git a/spec/controllers/projects/merge_requests/creations_controller_spec.rb b/spec/controllers/projects/merge_requests/creations_controller_spec.rb index 7e2366847f4..92db7284e0e 100644 --- a/spec/controllers/projects/merge_requests/creations_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/creations_controller_spec.rb @@ -4,6 +4,16 @@ describe Projects::MergeRequests::CreationsController do let(:project) { create(:project, :repository) } let(:user) { project.owner } let(:fork_project) { create(:forked_project_with_submodules) } + let(:get_diff_params) do + { + namespace_id: fork_project.namespace.to_param, + project_id: fork_project, + merge_request: { + source_branch: 'remove-submodule', + target_branch: 'master' + } + } + end before do fork_project.add_master(user) @@ -13,18 +23,23 @@ describe Projects::MergeRequests::CreationsController do describe 'GET new' do context 'merge request that removes a submodule' do - render_views - it 'renders new merge request widget template' do - get :new, - namespace_id: fork_project.namespace.to_param, - project_id: fork_project, - merge_request: { - source_branch: 'remove-submodule', - target_branch: 'master' - } + get :new, get_diff_params + + expect(response).to be_success + end + end + end + + describe 'GET diffs' do + context 'when merge request cannot be created' do + it 'does not assign diffs var' do + allow_any_instance_of(MergeRequest).to receive(:can_be_created).and_return(false) + + get :diffs, get_diff_params.merge(format: 'json') expect(response).to be_success + expect(assigns[:diffs]).to be_nil end end end @@ -37,14 +52,7 @@ describe Projects::MergeRequests::CreationsController do end it 'renders JSON including serialized pipelines' do - get :pipelines, - namespace_id: fork_project.namespace.to_param, - project_id: fork_project, - merge_request: { - source_branch: 'remove-submodule', - target_branch: 'master' - }, - format: :json + get :pipelines, get_diff_params.merge(format: 'json') expect(response).to be_ok expect(json_response).to have_key 'pipelines' |