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
4d48ee01
Commit
4d48ee01
authored
Jan 15, 2021
by
Mathieu Parent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Packages::Debian::DestroyDistributionService
parent
8d80c18f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
app/services/packages/debian/destroy_distribution_service.rb
app/services/packages/debian/destroy_distribution_service.rb
+33
-0
spec/services/packages/debian/destroy_distribution_service_spec.rb
...ices/packages/debian/destroy_distribution_service_spec.rb
+69
-0
No files found.
app/services/packages/debian/destroy_distribution_service.rb
0 → 100644
View file @
4d48ee01
# frozen_string_literal: true
module
Packages
module
Debian
class
DestroyDistributionService
def
initialize
(
distribution
)
@distribution
=
distribution
end
def
execute
destroy_distribution
end
private
def
destroy_distribution
if
@distribution
.
destroy
success
else
error
(
"Unable to destroy Debian
#{
@distribution
.
model_name
.
human
.
downcase
}
"
)
end
end
def
success
ServiceResponse
.
success
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
,
payload:
{
distribution:
@distribution
})
end
end
end
end
spec/services/packages/debian/destroy_distribution_service_spec.rb
0 → 100644
View file @
4d48ee01
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Packages
::
Debian
::
DestroyDistributionService
do
RSpec
.
shared_examples
'Destroy Debian Distribution'
do
|
expected_message
|
it
'returns ServiceResponse'
,
:aggregate_failures
do
if
expected_message
.
nil?
expect
{
response
}
.
to
change
{
container
.
debian_distributions
.
klass
.
all
.
count
}
.
from
(
1
).
to
(
0
)
.
and
change
{
container
.
debian_distributions
.
count
}
.
from
(
1
).
to
(
0
)
.
and
change
{
component1
.
class
.
all
.
count
}
.
from
(
2
).
to
(
0
)
.
and
change
{
architecture1
.
class
.
all
.
count
}
.
from
(
3
).
to
(
0
)
else
expect
{
response
}
.
to
not_change
{
container
.
debian_distributions
.
klass
.
all
.
count
}
.
and
not_change
{
container
.
debian_distributions
.
count
}
.
and
not_change
{
component1
.
class
.
all
.
count
}
.
and
not_change
{
architecture1
.
class
.
all
.
count
}
end
expect
(
response
).
to
be_a
(
ServiceResponse
)
expect
(
response
.
success?
).
to
eq
(
expected_message
.
nil?
)
expect
(
response
.
error?
).
to
eq
(
!
expected_message
.
nil?
)
expect
(
response
.
message
).
to
eq
(
expected_message
)
if
expected_message
.
nil?
expect
(
response
.
payload
).
to
eq
({})
else
expect
(
response
.
payload
).
to
eq
(
distribution:
distribution
)
end
end
end
RSpec
.
shared_examples
'Debian Destroy Distribution Service'
do
|
container_type
,
can_freeze
|
context
"with a Debian
#{
container_type
}
distribution"
do
let_it_be
(
:container
,
freeze:
can_freeze
)
{
create
(
container_type
)
}
# rubocop:disable Rails/SaveBang
let_it_be
(
:distribution
,
freeze:
can_freeze
)
{
create
(
"debian_
#{
container_type
}
_distribution"
,
container:
container
)
}
let_it_be
(
:component1
,
freeze:
can_freeze
)
{
create
(
"debian_
#{
container_type
}
_component"
,
distribution:
distribution
,
name:
'component1'
)
}
let_it_be
(
:component2
,
freeze:
can_freeze
)
{
create
(
"debian_
#{
container_type
}
_component"
,
distribution:
distribution
,
name:
'component2'
)
}
let_it_be
(
:architecture0
,
freeze:
true
)
{
create
(
"debian_
#{
container_type
}
_architecture"
,
distribution:
distribution
,
name:
'all'
)
}
let_it_be
(
:architecture1
,
freeze:
can_freeze
)
{
create
(
"debian_
#{
container_type
}
_architecture"
,
distribution:
distribution
,
name:
'architecture1'
)
}
let_it_be
(
:architecture2
,
freeze:
can_freeze
)
{
create
(
"debian_
#{
container_type
}
_architecture"
,
distribution:
distribution
,
name:
'architecture2'
)
}
subject
{
described_class
.
new
(
distribution
)
}
let
(
:response
)
{
subject
.
execute
}
context
'with a distribution'
do
it_behaves_like
'Destroy Debian Distribution'
end
context
'when destroy fails'
do
before
do
expect
(
distribution
).
to
receive
(
:destroy
).
and_return
(
false
)
end
it_behaves_like
'Destroy Debian Distribution'
,
"Unable to destroy Debian
#{
container_type
}
distribution"
end
end
end
it_behaves_like
'Debian Destroy Distribution Service'
,
:project
,
true
it_behaves_like
'Debian Destroy Distribution Service'
,
:group
,
false
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