Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6ba6299d
Commit
6ba6299d
authored
Jun 18, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validation for move action in SnippetInputAction
parent
e874bbb9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
2 deletions
+20
-2
app/models/snippet_input_action.rb
app/models/snippet_input_action.rb
+7
-0
changelogs/unreleased/fj-218516-add-validation-to-move-action.yml
...gs/unreleased/fj-218516-add-validation-to-move-action.yml
+5
-0
spec/models/snippet_input_action_spec.rb
spec/models/snippet_input_action_spec.rb
+8
-2
No files found.
app/models/snippet_input_action.rb
View file @
6ba6299d
...
...
@@ -18,6 +18,7 @@ class SnippetInputAction
validates
:file_path
,
presence:
true
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?
validate
:ensure_allowed_action
def
initialize
(
action:
nil
,
previous_path:
nil
,
file_path:
nil
,
content:
nil
,
allowed_actions:
nil
)
...
...
@@ -52,6 +53,12 @@ class SnippetInputAction
errors
.
add
(
:file_path
,
"can't be different from the previous_path attribute"
)
end
def
ensure_different_file_path_and_previous_path
return
if
previous_path
!=
file_path
errors
.
add
(
:file_path
,
'must be different from the previous_path attribute'
)
end
def
ensure_allowed_action
return
if
@allowed_actions
.
empty?
...
...
changelogs/unreleased/fj-218516-add-validation-to-move-action.yml
0 → 100644
View file @
6ba6299d
---
title
:
Add validation for move action in SnippetInputAction
merge_request
:
34911
author
:
type
:
other
spec/models/snippet_input_action_spec.rb
View file @
6ba6299d
...
...
@@ -8,12 +8,12 @@ describe SnippetInputAction do
where
(
:action
,
:file_path
,
:content
,
:previous_path
,
:allowed_actions
,
:is_valid
,
:invalid_field
)
do
:create
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
:move
|
'foobar'
|
'foobar'
|
'foo
bar'
|
nil
|
true
|
nil
:move
|
'foobar'
|
'foobar'
|
'foo
1'
|
nil
|
true
|
nil
:delete
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
:update
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
:foo
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
false
|
:action
'create'
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
'move'
|
'foobar'
|
'foobar'
|
'foo
bar'
|
nil
|
true
|
nil
'move'
|
'foobar'
|
'foobar'
|
'foo
1'
|
nil
|
true
|
nil
'delete'
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
'update'
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
'foo'
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
false
|
:action
...
...
@@ -21,6 +21,12 @@ describe SnippetInputAction do
''
|
'foobar'
|
'foobar'
|
'foobar'
|
nil
|
false
|
:action
: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
|
'foobar'
|
nil
|
'foo1'
|
nil
|
true
|
nil
:move
|
'foobar'
|
''
|
'foo1'
|
nil
|
true
|
nil
:create
|
'foobar'
|
nil
|
'foobar'
|
nil
|
false
|
:content
:create
|
'foobar'
|
''
|
'foobar'
|
nil
|
false
|
:content
:create
|
nil
|
'foobar'
|
'foobar'
|
nil
|
false
|
:file_path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment