Commit 654744b9 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'fj-fix-snippet-edit-page' into 'master'

Fix bug in snippet edit page

See merge request gitlab-org/gitlab!27479
parents f8f2353d 80aec1b1
......@@ -4,6 +4,11 @@ module SnippetsActions
extend ActiveSupport::Concern
def edit
# We need to load some info from the existing blob
snippet.content = blob.data
snippet.file_name = blob.path
render 'edit'
end
def raw
......@@ -25,6 +30,18 @@ module SnippetsActions
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)
params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
end
......
......@@ -121,16 +121,6 @@ class Projects::SnippetsController < Projects::ApplicationController
alias_method :awardable, :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
project_snippet_path(@project, @snippet)
end
......
......@@ -126,16 +126,6 @@ class SnippetsController < ApplicationController
alias_method :awardable, :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
snippet_path(@snippet)
end
......
---
title: Show the proper information in snippet edit form
merge_request: 27479
author:
type: fixed
......@@ -2,13 +2,17 @@
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(: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
stub_feature_flags(snippets_vue: false)
stub_feature_flags(version_snippets: version_snippet_enabled)
project.add_maintainer(user)
sign_in(user)
......@@ -17,6 +21,29 @@ describe 'Projects > Snippets > User updates a snippet' do
page.within('.detail-page-header') do
first(:link, 'Edit').click
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
it 'updates a snippet' do
......
......@@ -5,18 +5,43 @@ require 'spec_helper'
describe 'User edits snippet', :js do
include DropzoneHelper
let(:file_name) { 'test.rb' }
let(:content) { 'puts "test"' }
let_it_be(:file_name) { 'test.rb' }
let_it_be(:content) { 'puts "test"' }
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
stub_feature_flags(snippets_vue: false)
stub_feature_flags(version_snippets: version_snippet_enabled)
sign_in(user)
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
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