Fix bug in snippet edit page

We need to update the snippet edit form
to include the blob data and not the
snippet info.
parent 7b3eb170
...@@ -4,6 +4,11 @@ module SnippetsActions ...@@ -4,6 +4,11 @@ module SnippetsActions
extend ActiveSupport::Concern extend ActiveSupport::Concern
def edit def edit
# We need to load some info from the existing blob
snippet.content = blob.data
snippet.file_name = blob.path
render 'edit'
end end
def raw def raw
...@@ -25,6 +30,18 @@ module SnippetsActions ...@@ -25,6 +30,18 @@ module SnippetsActions
private private
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def blob
return unless snippet
@blob ||= if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
snippet.blobs.first
else
snippet.blob
end
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def convert_line_endings(content) def convert_line_endings(content)
params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n") params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
end end
......
...@@ -121,16 +121,6 @@ class Projects::SnippetsController < Projects::ApplicationController ...@@ -121,16 +121,6 @@ class Projects::SnippetsController < Projects::ApplicationController
alias_method :awardable, :snippet alias_method :awardable, :snippet
alias_method :spammable, :snippet alias_method :spammable, :snippet
def blob
return unless snippet
@blob ||= if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
snippet.blobs.first
else
snippet.blob
end
end
def spammable_path def spammable_path
project_snippet_path(@project, @snippet) project_snippet_path(@project, @snippet)
end end
......
...@@ -126,16 +126,6 @@ class SnippetsController < ApplicationController ...@@ -126,16 +126,6 @@ class SnippetsController < ApplicationController
alias_method :awardable, :snippet alias_method :awardable, :snippet
alias_method :spammable, :snippet alias_method :spammable, :snippet
def blob
return unless snippet
@blob ||= if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
snippet.blobs.first
else
snippet.blob
end
end
def spammable_path def spammable_path
snippet_path(@snippet) snippet_path(@snippet)
end end
......
---
title: Show the proper information in snippet edit form
merge_request: 27479
author:
type: fixed
...@@ -2,13 +2,17 @@ ...@@ -2,13 +2,17 @@
require 'spec_helper' require 'spec_helper'
describe 'Projects > Snippets > User updates a snippet' do describe 'Projects > Snippets > User updates a snippet', :js do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, namespace: user.namespace) } let_it_be(:project) { create(:project, namespace: user.namespace) }
let!(:snippet) { create(:project_snippet, project: project, author: user) } let_it_be(:snippet, reload: true) { create(:project_snippet, :repository, project: project, author: user) }
let(:version_snippet_enabled) { true }
before do before do
stub_feature_flags(snippets_vue: false) stub_feature_flags(snippets_vue: false)
stub_feature_flags(version_snippets: version_snippet_enabled)
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
...@@ -17,6 +21,29 @@ describe 'Projects > Snippets > User updates a snippet' do ...@@ -17,6 +21,29 @@ describe 'Projects > Snippets > User updates a snippet' do
page.within('.detail-page-header') do page.within('.detail-page-header') do
first(:link, 'Edit').click first(:link, 'Edit').click
end end
wait_for_all_requests
end
it 'displays the snippet blob path and content' do
blob = snippet.blobs.first
aggregate_failures do
expect(page.find_field('project_snippet_file_name').value).to eq blob.path
expect(page.find('.file-content')).to have_content(blob.data.strip)
expect(page.find('.snippet-file-content', visible: false).value).to eq blob.data
end
end
context 'when feature flag :version_snippets is disabled' do
let(:version_snippet_enabled) { false }
it 'displays the snippet file_name and content' do
aggregate_failures do
expect(page.find_field('project_snippet_file_name').value).to eq snippet.file_name
expect(page.find('.file-content')).to have_content(snippet.content)
expect(page.find('.snippet-file-content', visible: false).value).to eq snippet.content
end
end
end end
it 'updates a snippet' do it 'updates a snippet' do
......
...@@ -5,18 +5,43 @@ require 'spec_helper' ...@@ -5,18 +5,43 @@ require 'spec_helper'
describe 'User edits snippet', :js do describe 'User edits snippet', :js do
include DropzoneHelper include DropzoneHelper
let(:file_name) { 'test.rb' } let_it_be(:file_name) { 'test.rb' }
let(:content) { 'puts "test"' } let_it_be(:content) { 'puts "test"' }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, author: user) } let_it_be(:snippet, reload: true) { create(:personal_snippet, :repository, :public, file_name: file_name, content: content, author: user) }
let(:version_snippet_enabled) { true }
before do before do
stub_feature_flags(snippets_vue: false) stub_feature_flags(snippets_vue: false)
stub_feature_flags(version_snippets: version_snippet_enabled)
sign_in(user) sign_in(user)
visit edit_snippet_path(snippet) visit edit_snippet_path(snippet)
wait_for_requests wait_for_all_requests
end
it 'displays the snippet blob path and content' do
blob = snippet.blobs.first
aggregate_failures do
expect(page.find_field('personal_snippet_file_name').value).to eq blob.path
expect(page.find('.file-content')).to have_content(blob.data.strip)
expect(page.find('.snippet-file-content', visible: false).value).to eq blob.data
end
end
context 'when feature flag :version_snippets is disabled' do
let(:version_snippet_enabled) { false }
it 'displays the snippet file_name and content' do
aggregate_failures do
expect(page.find_field('personal_snippet_file_name').value).to eq file_name
expect(page.find('.file-content')).to have_content(content)
expect(page.find('.snippet-file-content', visible: false).value).to eq content
end
end
end end
it 'updates the snippet' do it 'updates the snippet' 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