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
54c57605
Commit
54c57605
authored
Nov 13, 2020
by
Mathieu Parent
Committed by
Kerri Miller
Mar 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Debian FindOrCreatePackageService
parent
01cfa570
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
0 deletions
+87
-0
app/services/packages/debian/find_or_create_package_service.rb
...ervices/packages/debian/find_or_create_package_service.rb
+33
-0
spec/services/packages/debian/find_or_create_package_service_spec.rb
...es/packages/debian/find_or_create_package_service_spec.rb
+54
-0
No files found.
app/services/packages/debian/find_or_create_package_service.rb
0 → 100644
View file @
54c57605
# frozen_string_literal: true
module
Packages
module
Debian
class
FindOrCreatePackageService
<
::
Packages
::
CreatePackageService
include
Gitlab
::
Utils
::
StrongMemoize
def
execute
package
=
project
.
packages
.
debian
.
with_name
(
params
[
:name
])
.
with_version
(
params
[
:version
])
.
with_debian_codename
(
params
[
:distribution_name
])
.
first
package
||=
create_package!
(
:debian
,
debian_publication_attributes:
{
distribution_id:
distribution
.
id
}
)
ServiceResponse
.
success
(
payload:
{
package:
package
})
end
private
def
distribution
strong_memoize
(
:distribution
)
do
Packages
::
Debian
::
DistributionsFinder
.
new
(
project
,
codename:
params
[
:distribution_name
]).
execute
.
last!
end
end
end
end
end
spec/services/packages/debian/find_or_create_package_service_spec.rb
0 → 100644
View file @
54c57605
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Packages
::
Debian
::
FindOrCreatePackageService
do
let_it_be
(
:distribution
)
{
create
(
:debian_project_distribution
)
}
let_it_be
(
:project
)
{
distribution
.
project
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
{
name:
'foo'
,
version:
'1.0+debian'
,
distribution_name:
distribution
.
codename
}
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
describe
'#execute'
do
subject
{
service
.
execute
}
let
(
:package
)
{
subject
.
payload
[
:package
]
}
context
'run once'
do
it
'creates a new package'
,
:aggregate_failures
do
expect
{
subject
}.
to
change
{
::
Packages
::
Package
.
count
}.
by
(
1
)
expect
(
subject
).
to
be_success
expect
(
package
).
to
be_valid
expect
(
package
.
project_id
).
to
eq
(
project
.
id
)
expect
(
package
.
creator_id
).
to
eq
(
user
.
id
)
expect
(
package
.
name
).
to
eq
(
'foo'
)
expect
(
package
.
version
).
to
eq
(
'1.0+debian'
)
expect
(
package
).
to
be_debian
expect
(
package
.
debian_publication
.
distribution
).
to
eq
(
distribution
)
end
end
context
'run twice'
do
let
(
:subject2
)
{
service
.
execute
}
let
(
:package2
)
{
service
.
execute
.
payload
[
:package
]
}
it
'returns the same object'
do
expect
{
subject
}.
to
change
{
::
Packages
::
Package
.
count
}.
by
(
1
)
expect
{
package2
}.
not_to
change
{
::
Packages
::
Package
.
count
}
expect
(
package2
.
id
).
to
eq
(
package
.
id
)
end
end
context
'with non-existing distribution'
do
let
(
:params
)
{
{
name:
'foo'
,
version:
'1.0+debian'
,
distribution_name:
'not-existing'
}
}
it
'raises ActiveRecord::RecordNotFound'
do
expect
{
package
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
end
end
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