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
1399dd2e
Commit
1399dd2e
authored
Jul 14, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename snippet_files to snippet_actions in snippet services
parent
27b98a2a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
66 deletions
+66
-66
app/graphql/mutations/snippets/create.rb
app/graphql/mutations/snippets/create.rb
+2
-2
app/graphql/mutations/snippets/update.rb
app/graphql/mutations/snippets/update.rb
+2
-2
app/services/snippets/base_service.rb
app/services/snippets/base_service.rb
+8
-8
app/services/snippets/create_service.rb
app/services/snippets/create_service.rb
+3
-3
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+4
-4
spec/requests/api/graphql/mutations/snippets/create_spec.rb
spec/requests/api/graphql/mutations/snippets/create_spec.rb
+1
-1
spec/services/snippets/create_service_spec.rb
spec/services/snippets/create_service_spec.rb
+12
-12
spec/services/snippets/update_service_spec.rb
spec/services/snippets/update_service_spec.rb
+34
-34
No files found.
app/graphql/mutations/snippets/create.rb
View file @
1399dd2e
...
@@ -85,9 +85,9 @@ module Mutations
...
@@ -85,9 +85,9 @@ module Mutations
def
create_params
(
args
)
def
create_params
(
args
)
args
.
tap
do
|
create_args
|
args
.
tap
do
|
create_args
|
# We need to rename `files` into `snippet_
file
s` because
# We need to rename `files` into `snippet_
action
s` because
# it's the expected key param
# it's the expected key param
create_args
[
:snippet_
file
s
]
=
create_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
create_args
[
:snippet_
action
s
]
=
create_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
# We need to rename `uploaded_files` into `files` because
# We need to rename `uploaded_files` into `files` because
# it's the expected key param
# it's the expected key param
...
...
app/graphql/mutations/snippets/update.rb
View file @
1399dd2e
...
@@ -56,9 +56,9 @@ module Mutations
...
@@ -56,9 +56,9 @@ module Mutations
def
update_params
(
args
)
def
update_params
(
args
)
args
.
tap
do
|
update_args
|
args
.
tap
do
|
update_args
|
# We need to rename `files` into `snippet_
file
s` because
# We need to rename `files` into `snippet_
action
s` because
# it's the expected key param
# it's the expected key param
update_args
[
:snippet_
file
s
]
=
update_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
update_args
[
:snippet_
action
s
]
=
update_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
end
end
end
end
end
end
...
...
app/services/snippets/base_service.rb
View file @
1399dd2e
...
@@ -6,15 +6,15 @@ module Snippets
...
@@ -6,15 +6,15 @@ module Snippets
CreateRepositoryError
=
Class
.
new
(
StandardError
)
CreateRepositoryError
=
Class
.
new
(
StandardError
)
attr_reader
:uploaded_assets
,
:snippet_
file
s
attr_reader
:uploaded_assets
,
:snippet_
action
s
def
initialize
(
project
,
user
=
nil
,
params
=
{})
def
initialize
(
project
,
user
=
nil
,
params
=
{})
super
super
@uploaded_assets
=
Array
(
@params
.
delete
(
:files
).
presence
)
@uploaded_assets
=
Array
(
@params
.
delete
(
:files
).
presence
)
input_actions
=
Array
(
@params
.
delete
(
:snippet_
file
s
).
presence
)
input_actions
=
Array
(
@params
.
delete
(
:snippet_
action
s
).
presence
)
@snippet_
file
s
=
SnippetInputActionCollection
.
new
(
input_actions
,
allowed_actions:
restricted_files_actions
)
@snippet_
action
s
=
SnippetInputActionCollection
.
new
(
input_actions
,
allowed_actions:
restricted_files_actions
)
filter_spam_check_params
filter_spam_check_params
end
end
...
@@ -32,18 +32,18 @@ module Snippets
...
@@ -32,18 +32,18 @@ module Snippets
end
end
def
valid_params?
def
valid_params?
return
true
if
snippet_
file
s
.
empty?
return
true
if
snippet_
action
s
.
empty?
(
params
.
keys
&
[
:content
,
:file_name
]).
none?
&&
snippet_
file
s
.
valid?
(
params
.
keys
&
[
:content
,
:file_name
]).
none?
&&
snippet_
action
s
.
valid?
end
end
def
invalid_params_error
(
snippet
)
def
invalid_params_error
(
snippet
)
if
snippet_
file
s
.
valid?
if
snippet_
action
s
.
valid?
[
:content
,
:file_name
].
each
do
|
key
|
[
:content
,
:file_name
].
each
do
|
key
|
snippet
.
errors
.
add
(
key
,
'and snippet files cannot be used together'
)
if
params
.
key?
(
key
)
snippet
.
errors
.
add
(
key
,
'and snippet files cannot be used together'
)
if
params
.
key?
(
key
)
end
end
else
else
snippet
.
errors
.
add
(
:snippet_
file
s
,
'have invalid data'
)
snippet
.
errors
.
add
(
:snippet_
action
s
,
'have invalid data'
)
end
end
snippet_error_response
(
snippet
,
403
)
snippet_error_response
(
snippet
,
403
)
...
@@ -75,7 +75,7 @@ module Snippets
...
@@ -75,7 +75,7 @@ module Snippets
end
end
def
files_to_commit
(
snippet
)
def
files_to_commit
(
snippet
)
snippet_
file
s
.
to_commit_actions
.
presence
||
build_actions_from_params
(
snippet
)
snippet_
action
s
.
to_commit_actions
.
presence
||
build_actions_from_params
(
snippet
)
end
end
def
build_actions_from_params
(
snippet
)
def
build_actions_from_params
(
snippet
)
...
...
app/services/snippets/create_service.rb
View file @
1399dd2e
...
@@ -37,13 +37,13 @@ module Snippets
...
@@ -37,13 +37,13 @@ module Snippets
end
end
end
end
# If the snippet_
file
s param is present
# If the snippet_
action
s param is present
# we need to fill content and file_name from
# we need to fill content and file_name from
# the model
# the model
def
create_params
def
create_params
return
params
if
snippet_
file
s
.
empty?
return
params
if
snippet_
action
s
.
empty?
params
.
merge
(
content:
snippet_
files
[
0
].
content
,
file_name:
snippet_file
s
[
0
].
file_path
)
params
.
merge
(
content:
snippet_
actions
[
0
].
content
,
file_name:
snippet_action
s
[
0
].
file_path
)
end
end
def
save_and_commit
def
save_and_commit
...
...
app/services/snippets/update_service.rb
View file @
1399dd2e
...
@@ -37,9 +37,9 @@ module Snippets
...
@@ -37,9 +37,9 @@ module Snippets
# is implemented.
# is implemented.
# Once we can perform different operations through this service
# Once we can perform different operations through this service
# we won't need to keep track of the `content` and `file_name` fields
# we won't need to keep track of the `content` and `file_name` fields
if
snippet_
file
s
.
any?
if
snippet_
action
s
.
any?
params
[
:content
]
=
snippet_
files
[
0
].
content
if
snippet_file
s
[
0
].
content
params
[
:content
]
=
snippet_
actions
[
0
].
content
if
snippet_action
s
[
0
].
content
params
[
:file_name
]
=
snippet_
file
s
[
0
].
file_path
params
[
:file_name
]
=
snippet_
action
s
[
0
].
file_path
end
end
snippet
.
assign_attributes
(
params
)
snippet
.
assign_attributes
(
params
)
...
@@ -109,7 +109,7 @@ module Snippets
...
@@ -109,7 +109,7 @@ module Snippets
end
end
def
committable_attributes?
def
committable_attributes?
(
params
.
stringify_keys
.
keys
&
COMMITTABLE_ATTRIBUTES
).
present?
||
snippet_
file
s
.
any?
(
params
.
stringify_keys
.
keys
&
COMMITTABLE_ATTRIBUTES
).
present?
||
snippet_
action
s
.
any?
end
end
def
build_actions_from_params
(
snippet
)
def
build_actions_from_params
(
snippet
)
...
...
spec/requests/api/graphql/mutations/snippets/create_spec.rb
View file @
1399dd2e
...
@@ -174,7 +174,7 @@ RSpec.describe 'Creating a Snippet' do
...
@@ -174,7 +174,7 @@ RSpec.describe 'Creating a Snippet' do
context
'when action is invalid'
do
context
'when action is invalid'
do
let
(
:file_1
)
{
{
filePath:
'example_file1'
}}
let
(
:file_1
)
{
{
filePath:
'example_file1'
}}
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Snippet
file
s have invalid data'
]
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Snippet
action
s have invalid data'
]
it_behaves_like
'does not create snippet'
it_behaves_like
'does not create snippet'
end
end
end
end
...
...
spec/services/snippets/create_service_spec.rb
View file @
1399dd2e
...
@@ -228,15 +228,15 @@ RSpec.describe Snippets::CreateService do
...
@@ -228,15 +228,15 @@ RSpec.describe Snippets::CreateService do
end
end
end
end
shared_examples
'when snippet_
file
s param is present'
do
shared_examples
'when snippet_
action
s param is present'
do
let
(
:file_path
)
{
'snippet_file_path.rb'
}
let
(
:file_path
)
{
'snippet_file_path.rb'
}
let
(
:content
)
{
'snippet_content'
}
let
(
:content
)
{
'snippet_content'
}
let
(
:snippet_
file
s
)
{
[{
action:
'create'
,
file_path:
file_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'create'
,
file_path:
file_path
,
content:
content
}]
}
let
(
:base_opts
)
do
let
(
:base_opts
)
do
{
{
title:
'Test snippet'
,
title:
'Test snippet'
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
,
snippet_
files:
snippet_file
s
snippet_
actions:
snippet_action
s
}
}
end
end
...
@@ -266,28 +266,28 @@ RSpec.describe Snippets::CreateService do
...
@@ -266,28 +266,28 @@ RSpec.describe Snippets::CreateService do
end
end
end
end
context
'when snippet_
file
s param is invalid'
do
context
'when snippet_
action
s param is invalid'
do
let
(
:snippet_
file
s
)
{
[{
action:
'invalid_action'
,
file_path:
'snippet_file_path.rb'
,
content:
'snippet_content'
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'invalid_action'
,
file_path:
'snippet_file_path.rb'
,
content:
'snippet_content'
}]
}
it
'a validation error is raised'
do
it
'a validation error is raised'
do
expect
(
subject
).
to
be_error
expect
(
subject
).
to
be_error
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
files
)).
to
eq
[
'Snippet file
s have invalid data'
]
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
actions
)).
to
eq
[
'Snippet action
s have invalid data'
]
expect
(
snippet
.
repository
.
exists?
).
to
be_falsey
expect
(
snippet
.
repository
.
exists?
).
to
be_falsey
end
end
end
end
context
'when snippet_
file
s contain an action different from "create"'
do
context
'when snippet_
action
s contain an action different from "create"'
do
let
(
:snippet_
file
s
)
{
[{
action:
'delete'
,
file_path:
'snippet_file_path.rb'
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'delete'
,
file_path:
'snippet_file_path.rb'
}]
}
it
'a validation error is raised'
do
it
'a validation error is raised'
do
expect
(
subject
).
to
be_error
expect
(
subject
).
to
be_error
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
files
)).
to
eq
[
'Snippet file
s have invalid data'
]
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
actions
)).
to
eq
[
'Snippet action
s have invalid data'
]
expect
(
snippet
.
repository
.
exists?
).
to
be_falsey
expect
(
snippet
.
repository
.
exists?
).
to
be_falsey
end
end
end
end
context
'when "create" operation does not have file_path or is empty'
do
context
'when "create" operation does not have file_path or is empty'
do
let
(
:snippet_
file
s
)
{
[{
action:
'create'
,
content:
content
},
{
action:
'create'
,
content:
content
,
file_path:
''
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'create'
,
content:
content
},
{
action:
'create'
,
content:
content
,
file_path:
''
}]
}
it
'generates the file path for the files'
do
it
'generates the file path for the files'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_success
...
@@ -311,7 +311,7 @@ RSpec.describe Snippets::CreateService do
...
@@ -311,7 +311,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like
'an error service response when save fails'
it_behaves_like
'an error service response when save fails'
it_behaves_like
'creates repository and files'
it_behaves_like
'creates repository and files'
it_behaves_like
'after_save callback to store_mentions'
,
ProjectSnippet
it_behaves_like
'after_save callback to store_mentions'
,
ProjectSnippet
it_behaves_like
'when snippet_
file
s param is present'
it_behaves_like
'when snippet_
action
s param is present'
context
'when uploaded files are passed to the service'
do
context
'when uploaded files are passed to the service'
do
let
(
:extra_opts
)
{
{
files:
[
'foo'
]
}
}
let
(
:extra_opts
)
{
{
files:
[
'foo'
]
}
}
...
@@ -338,7 +338,7 @@ RSpec.describe Snippets::CreateService do
...
@@ -338,7 +338,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like
'an error service response when save fails'
it_behaves_like
'an error service response when save fails'
it_behaves_like
'creates repository and files'
it_behaves_like
'creates repository and files'
it_behaves_like
'after_save callback to store_mentions'
,
PersonalSnippet
it_behaves_like
'after_save callback to store_mentions'
,
PersonalSnippet
it_behaves_like
'when snippet_
file
s param is present'
it_behaves_like
'when snippet_
action
s param is present'
context
'when the snippet description contains files'
do
context
'when the snippet description contains files'
do
include
FileMoverHelpers
include
FileMoverHelpers
...
...
spec/services/snippets/update_service_spec.rb
View file @
1399dd2e
...
@@ -302,22 +302,22 @@ RSpec.describe Snippets::UpdateService do
...
@@ -302,22 +302,22 @@ RSpec.describe Snippets::UpdateService do
end
end
end
end
shared_examples
'when snippet_
file
s param is present'
do
shared_examples
'when snippet_
action
s param is present'
do
let
(
:file_path
)
{
'CHANGELOG'
}
let
(
:file_path
)
{
'CHANGELOG'
}
let
(
:content
)
{
'snippet_content'
}
let
(
:content
)
{
'snippet_content'
}
let
(
:new_title
)
{
'New title'
}
let
(
:new_title
)
{
'New title'
}
let
(
:snippet_
file
s
)
{
[{
action:
'update'
,
previous_path:
file_path
,
file_path:
file_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'update'
,
previous_path:
file_path
,
file_path:
file_path
,
content:
content
}]
}
let
(
:base_opts
)
do
let
(
:base_opts
)
do
{
{
title:
new_title
,
title:
new_title
,
snippet_
files:
snippet_file
s
snippet_
actions:
snippet_action
s
}
}
end
end
it
'updates a snippet with the provided attributes'
do
it
'updates a snippet with the provided attributes'
do
file_path
=
'foo'
file_path
=
'foo'
snippet_
file
s
[
0
][
:action
]
=
'move'
snippet_
action
s
[
0
][
:action
]
=
'move'
snippet_
file
s
[
0
][
:file_path
]
=
file_path
snippet_
action
s
[
0
][
:file_path
]
=
file_path
response
=
subject
response
=
subject
snippet
=
response
.
payload
[
:snippet
]
snippet
=
response
.
payload
[
:snippet
]
...
@@ -350,7 +350,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -350,7 +350,7 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'when snippet_file content is not present'
do
context
'when snippet_file content is not present'
do
let
(
:snippet_
file
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
'new_file_path'
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
'new_file_path'
}]
}
it
'does not update snippet content'
do
it
'does not update snippet content'
do
content
=
snippet
.
content
content
=
snippet
.
content
...
@@ -361,15 +361,15 @@ RSpec.describe Snippets::UpdateService do
...
@@ -361,15 +361,15 @@ RSpec.describe Snippets::UpdateService do
end
end
end
end
context
'when snippet_
file
s param is invalid'
do
context
'when snippet_
action
s param is invalid'
do
let
(
:snippet_
file
s
)
{
[{
action:
'invalid_action'
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'invalid_action'
}]
}
it
'raises a validation error'
do
it
'raises a validation error'
do
response
=
subject
response
=
subject
snippet
=
response
.
payload
[
:snippet
]
snippet
=
response
.
payload
[
:snippet
]
expect
(
response
).
to
be_error
expect
(
response
).
to
be_error
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
files
)).
to
eq
[
'Snippet file
s have invalid data'
]
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
actions
)).
to
eq
[
'Snippet action
s have invalid data'
]
end
end
end
end
...
@@ -391,7 +391,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -391,7 +391,7 @@ RSpec.describe Snippets::UpdateService do
context
'commit actions'
do
context
'commit actions'
do
let
(
:new_path
)
{
'created_new_file'
}
let
(
:new_path
)
{
'created_new_file'
}
let
(
:base_opts
)
{
{
snippet_
files:
snippet_file
s
}
}
let
(
:base_opts
)
{
{
snippet_
actions:
snippet_action
s
}
}
shared_examples
'returns an error'
do
|
error_msg
|
shared_examples
'returns an error'
do
|
error_msg
|
specify
do
specify
do
...
@@ -403,7 +403,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -403,7 +403,7 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'update action'
do
context
'update action'
do
let
(
:snippet_
file
s
)
{
[{
action: :update
,
file_path:
file_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :update
,
file_path:
file_path
,
content:
content
}]
}
it
'updates the file content'
do
it
'updates the file content'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_success
...
@@ -414,7 +414,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -414,7 +414,7 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'when previous_path is present'
do
context
'when previous_path is present'
do
let
(
:snippet_
file
s
)
{
[{
action: :update
,
previous_path:
file_path
,
file_path:
file_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :update
,
previous_path:
file_path
,
file_path:
file_path
,
content:
content
}]
}
it
'updates the file content'
do
it
'updates the file content'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_success
...
@@ -426,13 +426,13 @@ RSpec.describe Snippets::UpdateService do
...
@@ -426,13 +426,13 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'when content is not present'
do
context
'when content is not present'
do
let
(
:snippet_
file
s
)
{
[{
action: :update
,
file_path:
file_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :update
,
file_path:
file_path
}]
}
it_behaves_like
'returns an error'
,
'Snippet
file
s have invalid data'
it_behaves_like
'returns an error'
,
'Snippet
action
s have invalid data'
end
end
context
'when file_path does not exist'
do
context
'when file_path does not exist'
do
let
(
:snippet_
file
s
)
{
[{
action: :update
,
file_path:
'makeup_name'
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :update
,
file_path:
'makeup_name'
,
content:
content
}]
}
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
end
end
...
@@ -440,13 +440,13 @@ RSpec.describe Snippets::UpdateService do
...
@@ -440,13 +440,13 @@ RSpec.describe Snippets::UpdateService do
context
'move action'
do
context
'move action'
do
context
'when file_path and previous_path are the same'
do
context
'when file_path and previous_path are the same'
do
let
(
:snippet_
file
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
file_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
file_path
}]
}
it_behaves_like
'returns an error'
,
'Snippet
file
s have invalid data'
it_behaves_like
'returns an error'
,
'Snippet
action
s have invalid data'
end
end
context
'when file_path and previous_path are different'
do
context
'when file_path and previous_path are different'
do
let
(
:snippet_
file
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
new_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
new_path
}]
}
it
'renames the file'
do
it
'renames the file'
do
old_blob
=
blob
(
file_path
)
old_blob
=
blob
(
file_path
)
...
@@ -461,13 +461,13 @@ RSpec.describe Snippets::UpdateService do
...
@@ -461,13 +461,13 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'when previous_path does not exist'
do
context
'when previous_path does not exist'
do
let
(
:snippet_
file
s
)
{
[{
action: :move
,
previous_path:
'makeup_name'
,
file_path:
new_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :move
,
previous_path:
'makeup_name'
,
file_path:
new_path
}]
}
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
end
end
context
'when user wants to rename the file and update content'
do
context
'when user wants to rename the file and update content'
do
let
(
:snippet_
file
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
new_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :move
,
previous_path:
file_path
,
file_path:
new_path
,
content:
content
}]
}
it
'performs both operations'
do
it
'performs both operations'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_success
...
@@ -481,7 +481,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -481,7 +481,7 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'delete action'
do
context
'delete action'
do
let
(
:snippet_
file
s
)
{
[{
action: :delete
,
file_path:
file_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :delete
,
file_path:
file_path
}]
}
shared_examples
'deletes the file'
do
shared_examples
'deletes the file'
do
specify
do
specify
do
...
@@ -496,32 +496,32 @@ RSpec.describe Snippets::UpdateService do
...
@@ -496,32 +496,32 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like
'deletes the file'
it_behaves_like
'deletes the file'
context
'when previous_path is present and same as file_path'
do
context
'when previous_path is present and same as file_path'
do
let
(
:snippet_
file
s
)
{
[{
action: :delete
,
previous_path:
file_path
,
file_path:
file_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :delete
,
previous_path:
file_path
,
file_path:
file_path
}]
}
it_behaves_like
'deletes the file'
it_behaves_like
'deletes the file'
end
end
context
'when previous_path is present and is different from file_path'
do
context
'when previous_path is present and is different from file_path'
do
let
(
:snippet_
file
s
)
{
[{
action: :delete
,
previous_path:
'foo'
,
file_path:
file_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :delete
,
previous_path:
'foo'
,
file_path:
file_path
}]
}
it_behaves_like
'deletes the file'
it_behaves_like
'deletes the file'
end
end
context
'when content is present'
do
context
'when content is present'
do
let
(
:snippet_
file
s
)
{
[{
action: :delete
,
file_path:
file_path
,
content:
'foo'
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :delete
,
file_path:
file_path
,
content:
'foo'
}]
}
it_behaves_like
'deletes the file'
it_behaves_like
'deletes the file'
end
end
context
'when file_path does not exist'
do
context
'when file_path does not exist'
do
let
(
:snippet_
file
s
)
{
[{
action: :delete
,
file_path:
'makeup_name'
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :delete
,
file_path:
'makeup_name'
}]
}
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
end
end
end
end
context
'create action'
do
context
'create action'
do
let
(
:snippet_
file
s
)
{
[{
action: :create
,
file_path:
new_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :create
,
file_path:
new_path
,
content:
content
}]
}
it
'creates the file'
do
it
'creates the file'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_success
...
@@ -532,13 +532,13 @@ RSpec.describe Snippets::UpdateService do
...
@@ -532,13 +532,13 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'when content is not present'
do
context
'when content is not present'
do
let
(
:snippet_
file
s
)
{
[{
action: :create
,
file_path:
new_path
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :create
,
file_path:
new_path
}]
}
it_behaves_like
'returns an error'
,
'Snippet
file
s have invalid data'
it_behaves_like
'returns an error'
,
'Snippet
action
s have invalid data'
end
end
context
'when file_path is not present or empty'
do
context
'when file_path is not present or empty'
do
let
(
:snippet_
file
s
)
{
[{
action: :create
,
content:
content
},
{
action: :create
,
file_path:
''
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :create
,
content:
content
},
{
action: :create
,
file_path:
''
,
content:
content
}]
}
it
'generates the file path for the files'
do
it
'generates the file path for the files'
do
expect
(
blob
(
'snippetfile1.txt'
)).
to
be_nil
expect
(
blob
(
'snippetfile1.txt'
)).
to
be_nil
...
@@ -552,13 +552,13 @@ RSpec.describe Snippets::UpdateService do
...
@@ -552,13 +552,13 @@ RSpec.describe Snippets::UpdateService do
end
end
context
'when file_path already exists in the repository'
do
context
'when file_path already exists in the repository'
do
let
(
:snippet_
file
s
)
{
[{
action: :create
,
file_path:
file_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :create
,
file_path:
file_path
,
content:
content
}]
}
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
it_behaves_like
'returns an error'
,
'Repository Error updating the snippet'
end
end
context
'when previous_path is present'
do
context
'when previous_path is present'
do
let
(
:snippet_
file
s
)
{
[{
action: :create
,
previous_path:
'foo'
,
file_path:
new_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action: :create
,
previous_path:
'foo'
,
file_path:
new_path
,
content:
content
}]
}
it
'creates the file'
do
it
'creates the file'
do
expect
(
subject
).
to
be_success
expect
(
subject
).
to
be_success
...
@@ -577,7 +577,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -577,7 +577,7 @@ RSpec.describe Snippets::UpdateService do
let
(
:move_previous_path
)
{
'VERSION'
}
let
(
:move_previous_path
)
{
'VERSION'
}
let
(
:move_file_path
)
{
'VERSION_new'
}
let
(
:move_file_path
)
{
'VERSION_new'
}
let
(
:snippet_
file
s
)
do
let
(
:snippet_
action
s
)
do
[
[
{
action: :create
,
file_path:
create_file_path
,
content:
content
},
{
action: :create
,
file_path:
create_file_path
,
content:
content
},
{
action: :update
,
file_path:
update_file_path
,
content:
content
},
{
action: :update
,
file_path:
update_file_path
,
content:
content
},
...
@@ -678,7 +678,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -678,7 +678,7 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like
'updates repository content'
it_behaves_like
'updates repository content'
it_behaves_like
'commit operation fails'
it_behaves_like
'commit operation fails'
it_behaves_like
'committable attributes'
it_behaves_like
'committable attributes'
it_behaves_like
'when snippet_
file
s param is present'
it_behaves_like
'when snippet_
action
s param is present'
it_behaves_like
'only file_name is present'
it_behaves_like
'only file_name is present'
it_behaves_like
'only content is present'
it_behaves_like
'only content is present'
it_behaves_like
'snippets spam check is performed'
do
it_behaves_like
'snippets spam check is performed'
do
...
@@ -705,7 +705,7 @@ RSpec.describe Snippets::UpdateService do
...
@@ -705,7 +705,7 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like
'updates repository content'
it_behaves_like
'updates repository content'
it_behaves_like
'commit operation fails'
it_behaves_like
'commit operation fails'
it_behaves_like
'committable attributes'
it_behaves_like
'committable attributes'
it_behaves_like
'when snippet_
file
s param is present'
it_behaves_like
'when snippet_
action
s param is present'
it_behaves_like
'only file_name is present'
it_behaves_like
'only file_name is present'
it_behaves_like
'only content is present'
it_behaves_like
'only content is present'
it_behaves_like
'snippets spam check is performed'
do
it_behaves_like
'snippets spam check is performed'
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