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
20174068
Commit
20174068
authored
May 29, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add update validations to SnippetInputAction
parent
951fd679
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletion
+15
-1
app/models/snippet_input_action.rb
app/models/snippet_input_action.rb
+8
-1
changelogs/unreleased/fj-add-validations-snippet-input-action.yml
...gs/unreleased/fj-add-validations-snippet-input-action.yml
+5
-0
spec/models/snippet_input_action_spec.rb
spec/models/snippet_input_action_spec.rb
+2
-0
No files found.
app/models/snippet_input_action.rb
View file @
20174068
...
@@ -16,7 +16,8 @@ class SnippetInputAction
...
@@ -16,7 +16,8 @@ class SnippetInputAction
validates
:action
,
inclusion:
{
in:
ACTIONS
,
message:
"%{value} is not a valid action"
}
validates
:action
,
inclusion:
{
in:
ACTIONS
,
message:
"%{value} is not a valid action"
}
validates
:previous_path
,
presence:
true
,
if: :move_action?
validates
:previous_path
,
presence:
true
,
if: :move_action?
validates
:file_path
,
presence:
true
validates
:file_path
,
presence:
true
validates
:content
,
presence:
true
,
if: :create_action?
validates
:content
,
presence:
true
,
if:
->
(
action
)
{
action
.
create_action?
||
action
.
update_action?
}
validate
:ensure_same_file_path_and_previous_path
,
if: :update_action?
def
initialize
(
action:
nil
,
previous_path:
nil
,
file_path:
nil
,
content:
nil
)
def
initialize
(
action:
nil
,
previous_path:
nil
,
file_path:
nil
,
content:
nil
)
@action
=
action
@action
=
action
...
@@ -41,4 +42,10 @@ class SnippetInputAction
...
@@ -41,4 +42,10 @@ class SnippetInputAction
previous_path
.
presence
||
file_path
previous_path
.
presence
||
file_path
end
end
def
ensure_same_file_path_and_previous_path
return
if
previous_path
==
file_path
errors
.
add
(
:file_path
,
"can't be different from the previous_path attribute"
)
end
end
end
changelogs/unreleased/fj-add-validations-snippet-input-action.yml
0 → 100644
View file @
20174068
---
title
:
Add update validations to SnippetInputAction
merge_request
:
33379
author
:
type
:
changed
spec/models/snippet_input_action_spec.rb
View file @
20174068
...
@@ -20,6 +20,8 @@ describe SnippetInputAction do
...
@@ -20,6 +20,8 @@ describe SnippetInputAction do
'create'
|
'foobar'
|
''
|
'foobar'
|
false
'create'
|
'foobar'
|
''
|
'foobar'
|
false
'create'
|
nil
|
'foobar'
|
'foobar'
|
false
'create'
|
nil
|
'foobar'
|
'foobar'
|
false
'create'
|
''
|
'foobar'
|
'foobar'
|
false
'create'
|
''
|
'foobar'
|
'foobar'
|
false
'update'
|
'foobar'
|
nil
|
'foobar'
|
false
'update'
|
'other'
|
'foobar'
|
'foobar'
|
false
end
end
with_them
do
with_them
do
...
...
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