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
6e102b0f
Commit
6e102b0f
authored
Jun 12, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SnippetInputAction to accept actions as symbols
parent
33ddf71a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
11 deletions
+20
-11
app/models/snippet_input_action.rb
app/models/snippet_input_action.rb
+4
-3
spec/models/snippet_input_action_spec.rb
spec/models/snippet_input_action_spec.rb
+16
-8
No files found.
app/models/snippet_input_action.rb
View file @
6e102b0f
...
...
@@ -3,7 +3,7 @@
class
SnippetInputAction
include
ActiveModel
::
Validations
ACTIONS
=
%
w
[create update delete move]
.
freeze
ACTIONS
=
%
i
[create update delete move]
.
freeze
ACTIONS
.
each
do
|
action_const
|
define_method
"
#{
action_const
}
_action?"
do
...
...
@@ -20,7 +20,7 @@ class SnippetInputAction
validate
:ensure_same_file_path_and_previous_path
,
if: :update_action?
def
initialize
(
action:
nil
,
previous_path:
nil
,
file_path:
nil
,
content:
nil
)
@action
=
action
@action
=
action
&
.
to_sym
@previous_path
=
previous_path
@file_path
=
file_path
@content
=
content
...
...
@@ -28,7 +28,7 @@ class SnippetInputAction
def
to_commit_action
{
action:
action
&
.
to_sym
,
action:
action
,
previous_path:
build_previous_path
,
file_path:
file_path
,
content:
content
...
...
@@ -44,6 +44,7 @@ class SnippetInputAction
end
def
ensure_same_file_path_and_previous_path
return
if
previous_path
.
blank?
||
file_path
.
blank?
return
if
previous_path
==
file_path
errors
.
add
(
:file_path
,
"can't be different from the previous_path attribute"
)
...
...
spec/models/snippet_input_action_spec.rb
View file @
6e102b0f
...
...
@@ -7,6 +7,11 @@ describe SnippetInputAction do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:action
,
:file_path
,
:content
,
:previous_path
,
:is_valid
,
:invalid_field
)
do
:create
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
:move
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
:delete
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
:update
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
:foo
|
'foobar'
|
'foobar'
|
'foobar'
|
false
|
:action
'create'
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
'move'
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
'delete'
|
'foobar'
|
'foobar'
|
'foobar'
|
true
|
nil
...
...
@@ -14,14 +19,17 @@ describe SnippetInputAction do
'foo'
|
'foobar'
|
'foobar'
|
'foobar'
|
false
|
:action
nil
|
'foobar'
|
'foobar'
|
'foobar'
|
false
|
:action
''
|
'foobar'
|
'foobar'
|
'foobar'
|
false
|
:action
'move'
|
'foobar'
|
'foobar'
|
nil
|
false
|
:previous_path
'move'
|
'foobar'
|
'foobar'
|
''
|
false
|
:previous_path
'create'
|
'foobar'
|
nil
|
'foobar'
|
false
|
:content
'create'
|
'foobar'
|
''
|
'foobar'
|
false
|
:content
'create'
|
nil
|
'foobar'
|
'foobar'
|
false
|
:file_path
'create'
|
''
|
'foobar'
|
'foobar'
|
false
|
:file_path
'update'
|
'foobar'
|
nil
|
'foobar'
|
false
|
:content
'update'
|
'other'
|
'foobar'
|
'foobar'
|
false
|
:file_path
:move
|
'foobar'
|
'foobar'
|
nil
|
false
|
:previous_path
:move
|
'foobar'
|
'foobar'
|
''
|
false
|
:previous_path
:create
|
'foobar'
|
nil
|
'foobar'
|
false
|
:content
:create
|
'foobar'
|
''
|
'foobar'
|
false
|
:content
:create
|
nil
|
'foobar'
|
'foobar'
|
false
|
:file_path
:create
|
''
|
'foobar'
|
'foobar'
|
false
|
:file_path
:update
|
'foobar'
|
nil
|
'foobar'
|
false
|
:content
:update
|
'foobar'
|
''
|
'foobar'
|
false
|
:content
:update
|
'other'
|
'foobar'
|
'foobar'
|
false
|
:file_path
:update
|
'foobar'
|
'foobar'
|
nil
|
true
|
nil
:update
|
'foobar'
|
'foobar'
|
''
|
true
|
nil
end
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