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
adc07290
Commit
adc07290
authored
Mar 30, 2020
by
David Fernandez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up code
Using `let_it_be` vars and re-using them as much as possible.
parent
f0d2d2a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
29 deletions
+16
-29
ee/spec/requests/api/maven_packages_spec.rb
ee/spec/requests/api/maven_packages_spec.rb
+16
-29
No files found.
ee/spec/requests/api/maven_packages_spec.rb
View file @
adc07290
...
...
@@ -2,18 +2,19 @@
require
'spec_helper'
describe
API
::
MavenPackages
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let
(
:package
)
{
create
(
:maven_package
,
project:
project
)
}
let
(
:maven_metadatum
)
{
package
.
maven_metadatum
}
let
(
:package_file
)
{
package
.
package_files
.
find_by
(
'file_name like ?'
,
'%.xml'
)
}
let
(
:jar_file
)
{
package
.
package_files
.
find_by
(
'file_name like ?'
,
'%.jar'
)
}
let
(
:personal_access_token
)
{
create
(
:personal_access_token
,
user:
user
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let_it_be
(
:package
,
reload:
true
)
{
create
(
:maven_package
,
project:
project
,
name:
project
.
full_path
)
}
let_it_be
(
:maven_metadatum
,
reload:
true
)
{
package
.
maven_metadatum
}
let_it_be
(
:package_file
)
{
package
.
package_files
.
with_file_name_like
(
'%.xml'
).
first
}
let_it_be
(
:jar_file
)
{
package
.
package_files
.
with_file_name_like
(
'%.jar'
).
first
}
let_it_be
(
:personal_access_token
)
{
create
(
:personal_access_token
,
user:
user
)
}
let_it_be
(
:job
)
{
create
(
:ci_build
,
user:
user
)
}
let
(
:workhorse_token
)
{
JWT
.
encode
({
'iss'
=>
'gitlab-workhorse'
},
Gitlab
::
Workhorse
.
secret
,
'HS256'
)
}
let
(
:headers
)
{
{
'GitLab-Workhorse'
=>
'1.0'
,
Gitlab
::
Workhorse
::
INTERNAL_API_REQUEST_HEADER
=>
workhorse_token
}
}
let
(
:headers_with_token
)
{
headers
.
merge
(
'Private-Token'
=>
personal_access_token
.
token
)
}
let
(
:job
)
{
create
(
:ci_build
,
user:
user
)
}
let
(
:version
)
{
'1.0-SNAPSHOT'
}
before
do
...
...
@@ -23,7 +24,7 @@ describe API::MavenPackages do
shared_examples
'tracking the file download event'
do
context
'with jar file'
do
let
(
:package_file
)
{
jar_file
}
let
_it_be
(
:package_file
)
{
jar_file
}
it_behaves_like
'a gitlab tracking event'
,
described_class
.
name
,
'pull_package'
end
...
...
@@ -78,8 +79,6 @@ describe API::MavenPackages do
end
describe
'GET /api/v4/packages/maven/*path/:file_name'
do
let
(
:package
)
{
create
(
:maven_package
,
project:
project
,
name:
project
.
full_path
)
}
context
'a public project'
do
subject
{
download_file
(
package_file
.
file_name
)
}
...
...
@@ -179,7 +178,9 @@ describe API::MavenPackages do
end
context
'project name is different from a package name'
do
let
(
:package
)
{
create
(
:maven_package
,
project:
project
)
}
before
do
maven_metadatum
.
update!
(
path:
"wrong_name/
#{
package
.
version
}
"
)
end
it
'rejects request'
do
download_file
(
package_file
.
file_name
)
...
...
@@ -198,9 +199,6 @@ describe API::MavenPackages do
end
describe
'HEAD /api/v4/packages/maven/*path/:file_name'
do
let_it_be
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:package
)
{
create
(
:maven_package
,
project:
project
,
name:
project
.
full_path
)
}
let_it_be
(
:package_file
)
{
package
.
package_files
.
where
(
'file_name like ?'
,
'%.xml'
).
first
}
let
(
:url
)
{
"/packages/maven/
#{
package
.
maven_metadatum
.
path
}
/
#{
package_file
.
file_name
}
"
}
it_behaves_like
'processing HEAD requests'
...
...
@@ -320,10 +318,6 @@ describe API::MavenPackages do
end
describe
'HEAD /api/v4/groups/:id/-/packages/maven/*path/:file_name'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let_it_be
(
:package
)
{
create
(
:maven_package
,
project:
project
,
name:
project
.
full_path
)
}
let_it_be
(
:package_file
)
{
package
.
package_files
.
where
(
'file_name like ?'
,
'%.xml'
).
first
}
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/-/packages/maven/
#{
package
.
maven_metadatum
.
path
}
/
#{
package_file
.
file_name
}
"
}
it_behaves_like
'processing HEAD requests'
...
...
@@ -408,9 +402,6 @@ describe API::MavenPackages do
end
describe
'HEAD /api/v4/projects/:id/packages/maven/*path/:file_name'
do
let_it_be
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:package
)
{
create
(
:maven_package
,
project:
project
,
name:
project
.
full_path
)
}
let_it_be
(
:package_file
)
{
package
.
package_files
.
where
(
'file_name like ?'
,
'%.xml'
).
first
}
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/maven/
#{
package
.
maven_metadatum
.
path
}
/
#{
package_file
.
file_name
}
"
}
it_behaves_like
'processing HEAD requests'
...
...
@@ -499,8 +490,6 @@ describe API::MavenPackages do
end
context
'when params from workhorse are correct'
do
let
(
:package
)
{
project
.
packages
.
reload
.
last
}
let
(
:package_file
)
{
package
.
package_files
.
reload
.
last
}
let
(
:params
)
do
{
'file.path'
=>
file_upload
.
path
,
...
...
@@ -521,8 +510,6 @@ describe API::MavenPackages do
end
context
'event tracking'
do
let
(
:package_file
)
{
jar_file
}
subject
{
upload_file_with_token
(
params
)
}
it_behaves_like
'a gitlab tracking event'
,
described_class
.
name
,
'push_package'
...
...
@@ -534,14 +521,14 @@ describe API::MavenPackages do
.
and
change
{
Packages
::
PackageFile
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
package
_file
.
file_name
).
to
eq
(
file_upload
.
original_filename
)
expect
(
jar
_file
.
file_name
).
to
eq
(
file_upload
.
original_filename
)
end
it
'allows upload with job token'
do
upload_file
(
params
.
merge
(
job_token:
job
.
token
))
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
p
ackage
.
build_info
.
pipeline
).
to
eq
job
.
pipeline
expect
(
p
roject
.
reload
.
packages
.
last
.
build_info
.
pipeline
).
to
eq
job
.
pipeline
end
context
'version is not correct'
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