Commit ac331996 authored by Stan Hu's avatar Stan Hu

Fix 500 error in BlobController#delete

If a validation or other error occurs in `BlobController#delete`, it
previously tried to render the `show` view, but that would render a 500
because the view assumes certain instance variables to be present
(e.g. `@last_commit`). Fix this by redirecting back to the blob in
question.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/220168
parent e7631cb4
......@@ -94,7 +94,6 @@ class Projects::BlobController < Projects::ApplicationController
def destroy
create_commit(Files::DeleteService, success_notice: _("The file has been successfully deleted."),
success_path: -> { after_delete_path },
failure_view: :show,
failure_path: project_blob_path(@project, @id))
end
......
---
title: Fix 500 error in BlobController#delete
merge_request: 34367
author:
type: fixed
......@@ -378,6 +378,22 @@ RSpec.describe Projects::BlobController do
expect(response).to redirect_to(after_delete_path)
end
context 'when a validation failure occurs' do
let(:failure_path) { project_blob_path(project, default_params[:id]) }
render_views
it 'redirects to a valid page' do
expect_next_instance_of(Files::DeleteService) do |instance|
expect(instance).to receive(:validate!).and_raise(Commits::CreateService::ValidationError, "validation error")
end
delete :destroy, params: default_params
expect(response).to redirect_to(failure_path)
end
end
end
context 'if deleted file is the last one in a subdirectory' 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