Remove redirection when snippet blob is binary

parent 844dc3e0
......@@ -14,8 +14,6 @@ module SnippetsActions
skip_before_action :verify_authenticity_token,
if: -> { action_name == 'show' && js_request? }
before_action :redirect_if_binary, only: [:edit, :update]
respond_to :html
end
......@@ -134,10 +132,4 @@ module SnippetsActions
recaptcha_check_with_fallback(errors.empty?) { render action }
end
def redirect_if_binary
return if Feature.enabled?(:snippets_binary_blob)
redirect_to gitlab_snippet_path(snippet) if blob&.binary?
end
end
---
title: Remove redirection when snippet has a binary blob
merge_request: 39858
author:
type: changed
......@@ -190,20 +190,6 @@ RSpec.describe Projects::SnippetsController do
snippet.reload
end
it_behaves_like 'updating snippet checks blob is binary' do
let_it_be(:title) { 'Foo' }
let(:params) do
{
namespace_id: project.namespace.to_param,
project_id: project,
id: snippet.id,
project_snippet: { title: title }
}
end
subject { put :update, params: params }
end
context 'when the snippet is spam' do
before do
allow_next_instance_of(Spam::AkismetService) do |instance|
......@@ -611,19 +597,4 @@ RSpec.describe Projects::SnippetsController do
end
end
end
describe 'GET #edit' do
it_behaves_like 'editing snippet checks blob is binary' do
let(:snippet) { create(:project_snippet, :private, project: project, author: user) }
let(:params) do
{
namespace_id: project.namespace,
project_id: project,
id: snippet
}
end
subject { get :edit, params: params }
end
end
end
......@@ -334,12 +334,6 @@ RSpec.describe SnippetsController do
snippet.reload
end
it_behaves_like 'updating snippet checks blob is binary' do
let_it_be(:title) { 'Foo' }
subject { put :update, params: { id: snippet, personal_snippet: { title: title } } }
end
context 'when the snippet is spam' do
before do
allow_next_instance_of(Spam::AkismetService) do |instance|
......@@ -746,12 +740,4 @@ RSpec.describe SnippetsController do
end
end
end
describe 'GET #edit' do
it_behaves_like 'editing snippet checks blob is binary' do
let_it_be(:snippet) { create(:personal_snippet, :public, :repository, author: user) }
subject { get :edit, params: { id: snippet } }
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'editing snippet checks blob is binary' do
let(:snippets_binary_blob_value) { true }
before do
sign_in(user)
allow_next_instance_of(Blob) do |blob|
allow(blob).to receive(:binary?).and_return(binary)
end
stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value)
subject
end
context 'when blob is text' do
let(:binary) { false }
it 'responds with status 200' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
end
context 'when blob is binary' do
let(:binary) { true }
it 'responds with status 200' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
context 'when feature flag :snippets_binary_blob is disabled' do
let(:snippets_binary_blob_value) { false }
it 'redirects away' do
expect(response).to redirect_to(gitlab_snippet_path(snippet))
end
end
end
end
RSpec.shared_examples 'updating snippet checks blob is binary' do
let(:snippets_binary_blob_value) { true }
before do
sign_in(user)
allow_next_instance_of(Blob) do |blob|
allow(blob).to receive(:binary?).and_return(binary)
end
stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value)
subject
end
context 'when blob is text' do
let(:binary) { false }
it 'updates successfully' do
expect(snippet.reload.title).to eq title
expect(response).to redirect_to(gitlab_snippet_path(snippet))
end
end
context 'when blob is binary' do
let(:binary) { true }
it 'updates successfully' do
expect(snippet.reload.title).to eq title
expect(response).to redirect_to(gitlab_snippet_path(snippet))
end
context 'when feature flag :snippets_binary_blob is disabled' do
let(:snippets_binary_blob_value) { false }
it 'redirects away without updating' do
expect(response).to redirect_to(gitlab_snippet_path(snippet))
expect(snippet.reload.title).not_to eq title
end
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