Commit 5339dcec authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '239341-fj-allow-snippet-move-action-without-file-path' into 'master'

Allow snippet move actions without an existing file name

See merge request gitlab-org/gitlab!40343
parents 0cf58f79 c0845073
......@@ -15,7 +15,7 @@ class SnippetInputAction
validates :action, inclusion: { in: ACTIONS, message: "%{value} is not a valid action" }
validates :previous_path, presence: true, if: :move_action?
validates :file_path, presence: true, unless: :create_action?
validates :file_path, presence: true, if: -> (action) { action.update_action? || action.delete_action? }
validates :content, presence: true, if: -> (action) { action.create_action? || action.update_action? }
validate :ensure_same_file_path_and_previous_path, if: :update_action?
validate :ensure_different_file_path_and_previous_path, if: :move_action?
......
---
title: Allow snippet move action without an existing file name
merge_request: 40343
author:
type: fixed
......@@ -22,9 +22,9 @@ RSpec.describe SnippetInputAction do
:move | 'foobar' | 'foobar' | nil | nil | false | :previous_path
:move | 'foobar' | 'foobar' | '' | nil | false | :previous_path
:move | 'foobar' | 'foobar' | 'foobar' | nil | false | :file_path
:move | nil | 'foobar' | 'foobar' | nil | false | :file_path
:move | '' | 'foobar' | 'foobar' | nil | false | :file_path
:move | nil | 'foobar' | 'foo1' | nil | false | :file_path
:move | nil | 'foobar' | 'foobar' | nil | true | nil
:move | '' | 'foobar' | 'foobar' | nil | true | nil
:move | nil | 'foobar' | 'foo1' | nil | true | nil
:move | 'foobar' | nil | 'foo1' | nil | true | nil
:move | 'foobar' | '' | 'foo1' | nil | true | nil
:create | 'foobar' | nil | 'foobar' | nil | false | :content
......
......@@ -479,6 +479,22 @@ RSpec.describe Snippets::UpdateService do
expect(blob.data).to eq content
end
end
context 'when the file_path is not present' do
let(:snippet_actions) { [{ action: :move, previous_path: file_path }] }
it 'generates the name for the renamed file' do
old_blob = blob(file_path)
expect(blob('snippetfile1.txt')).to be_nil
expect(subject).to be_success
new_blob = blob('snippetfile1.txt')
expect(new_blob).to be_present
expect(new_blob.data).to eq old_blob.data
end
end
end
context 'delete action' 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