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
36978866
Commit
36978866
authored
Nov 16, 2020
by
Mathieu Parent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Packages::Debian::DistributionFinder
parent
b5b1eab1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
0 deletions
+179
-0
app/finders/packages/debian/distributions_finder.rb
app/finders/packages/debian/distributions_finder.rb
+52
-0
app/models/concerns/packages/debian/distribution.rb
app/models/concerns/packages/debian/distribution.rb
+1
-0
spec/finders/packages/debian/distributions_finder_spec.rb
spec/finders/packages/debian/distributions_finder_spec.rb
+28
-0
spec/support/shared_examples/finders/packages/debian/distributions_finder_shared_examples.rb
...s/packages/debian/distributions_finder_shared_examples.rb
+79
-0
spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb
...es/models/packages/debian/distribution_shared_examples.rb
+19
-0
No files found.
app/finders/packages/debian/distributions_finder.rb
0 → 100644
View file @
36978866
# frozen_string_literal: true
module
Packages
module
Debian
class
DistributionsFinder
def
initialize
(
container
,
params
=
{})
@container
,
@params
=
container
,
params
end
def
execute
collection
=
relation
.
with_container
(
container
)
collection
=
by_codename
(
collection
)
collection
=
by_suite
(
collection
)
collection
=
by_codename_or_suite
(
collection
)
collection
end
private
attr_reader
:container
,
:params
def
relation
case
container
when
Project
Packages
::
Debian
::
ProjectDistribution
when
Group
Packages
::
Debian
::
GroupDistribution
else
raise
ArgumentError
,
"Unexpected container type of '
#{
container
.
class
}
'"
end
end
def
by_codename
(
collection
)
return
collection
unless
params
[
:codename
].
present?
collection
.
with_codename
(
params
[
:codename
])
end
def
by_suite
(
collection
)
return
collection
unless
params
[
:suite
].
present?
collection
.
with_suite
(
params
[
:suite
])
end
def
by_codename_or_suite
(
collection
)
return
collection
unless
params
[
:codename_or_suite
].
present?
collection
.
with_codename_or_suite
(
params
[
:codename_or_suite
])
end
end
end
end
app/models/concerns/packages/debian/distribution.rb
View file @
36978866
...
...
@@ -70,6 +70,7 @@ module Packages
scope
:with_container
,
->
(
subject
)
{
where
(
container_type
=>
subject
)
}
scope
:with_codename
,
->
(
codename
)
{
where
(
codename:
codename
)
}
scope
:with_suite
,
->
(
suite
)
{
where
(
suite:
suite
)
}
scope
:with_codename_or_suite
,
->
(
codename_or_suite
)
{
with_codename
(
codename_or_suite
).
or
(
with_suite
(
codename_or_suite
))
}
attr_encrypted
:signing_keys
,
mode: :per_attribute_iv
,
...
...
spec/finders/packages/debian/distributions_finder_spec.rb
0 → 100644
View file @
36978866
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Packages
::
Debian
::
DistributionsFinder
do
it_behaves_like
'Debian Distributions Finder'
,
:debian_project_distribution
,
true
it_behaves_like
'Debian Distributions Finder'
,
:debian_group_distribution
,
false
context
'with nil container'
do
let
(
:service
)
{
described_class
.
new
(
nil
)
}
subject
{
service
.
execute
.
to_a
}
it
'raises error'
do
expect
{
subject
}.
to
raise_error
ArgumentError
,
"Unexpected container type of 'NilClass'"
end
end
context
'with unexpected container type'
do
let
(
:service
)
{
described_class
.
new
(
:invalid
)
}
subject
{
service
.
execute
.
to_a
}
it
'raises error'
do
expect
{
subject
}.
to
raise_error
ArgumentError
,
"Unexpected container type of 'Symbol'"
end
end
end
spec/support/shared_examples/finders/packages/debian/distributions_finder_shared_examples.rb
0 → 100644
View file @
36978866
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
shared_examples
'Debian Distributions Finder'
do
|
factory
,
can_freeze
|
let_it_be
(
:distribution_with_suite
,
freeze:
can_freeze
)
{
create
(
factory
,
suite:
'mysuite'
)
}
let_it_be
(
:container
)
{
distribution_with_suite
.
container
}
let_it_be
(
:distribution_with_same_container
,
freeze:
can_freeze
)
{
create
(
factory
,
container:
container
)
}
let_it_be
(
:distribution_with_same_codename
,
freeze:
can_freeze
)
{
create
(
factory
,
codename:
distribution_with_suite
.
codename
)
}
let_it_be
(
:distribution_with_same_suite
,
freeze:
can_freeze
)
{
create
(
factory
,
suite:
distribution_with_suite
.
suite
)
}
let_it_be
(
:distribution_with_codename_and_suite_flipped
,
freeze:
can_freeze
)
{
create
(
factory
,
codename:
distribution_with_suite
.
suite
,
suite:
distribution_with_suite
.
codename
)
}
let
(
:params
)
{
{}
}
let
(
:service
)
{
described_class
.
new
(
container
,
params
)
}
subject
{
service
.
execute
.
to_a
}
context
'by codename'
do
context
'with existing codename'
do
let
(
:params
)
{
{
codename:
distribution_with_suite
.
codename
}
}
it
'finds distributions by codename'
do
is_expected
.
to
contain_exactly
(
distribution_with_suite
)
end
end
context
'with non-existing codename'
do
let
(
:params
)
{
{
codename:
'does_not_exists'
}
}
it
'finds nothing'
do
is_expected
.
to
be_empty
end
end
end
context
'by suite'
do
context
'with existing suite'
do
let
(
:params
)
{
{
suite:
'mysuite'
}
}
it
'finds distribution by suite'
do
is_expected
.
to
contain_exactly
(
distribution_with_suite
)
end
end
context
'with non-existing suite'
do
let
(
:params
)
{
{
suite:
'does_not_exists'
}
}
it
'finds nothing'
do
is_expected
.
to
be_empty
end
end
end
context
'by codename_or_suite'
do
context
'with existing codename'
do
let
(
:params
)
{
{
codename_or_suite:
distribution_with_suite
.
codename
}
}
it
'finds distribution by codename'
do
is_expected
.
to
contain_exactly
(
distribution_with_suite
)
end
end
context
'with existing suite'
do
let
(
:params
)
{
{
codename_or_suite:
'mysuite'
}
}
it
'finds distribution by suite'
do
is_expected
.
to
contain_exactly
(
distribution_with_suite
)
end
end
context
'with non-existing suite'
do
let
(
:params
)
{
{
codename_or_suite:
'does_not_exists'
}
}
it
'finds nothing'
do
is_expected
.
to
be_empty
end
end
end
end
spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb
View file @
36978866
...
...
@@ -7,6 +7,7 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze|
let_it_be
(
:distribution_with_same_container
,
freeze:
can_freeze
)
{
create
(
factory
,
container:
distribution_with_suite
.
container
)
}
let_it_be
(
:distribution_with_same_codename
,
freeze:
can_freeze
)
{
create
(
factory
,
codename:
distribution_with_suite
.
codename
)
}
let_it_be
(
:distribution_with_same_suite
,
freeze:
can_freeze
)
{
create
(
factory
,
suite:
distribution_with_suite
.
suite
)
}
let_it_be
(
:distribution_with_codename_and_suite_flipped
,
freeze:
can_freeze
)
{
create
(
factory
,
codename:
distribution_with_suite
.
suite
,
suite:
distribution_with_suite
.
codename
)
}
let_it_be_with_refind
(
:distribution
)
{
create
(
factory
,
container:
distribution_with_suite
.
container
)
}
...
...
@@ -166,6 +167,24 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze|
expect
(
subject
).
to
match_array
([
distribution_with_suite
,
distribution_with_same_suite
])
end
end
describe
'.with_codename_or_suite'
do
describe
'passing codename'
do
subject
{
described_class
.
with_codename_or_suite
(
distribution_with_suite
.
codename
)
}
it
'does not return other distributions'
do
expect
(
subject
.
to_a
).
to
eq
([
distribution_with_suite
,
distribution_with_same_codename
,
distribution_with_codename_and_suite_flipped
])
end
end
describe
'passing suite'
do
subject
{
described_class
.
with_codename_or_suite
(
distribution_with_suite
.
suite
)
}
it
'does not return other distributions'
do
expect
(
subject
.
to_a
).
to
eq
([
distribution_with_suite
,
distribution_with_same_suite
,
distribution_with_codename_and_suite_flipped
])
end
end
end
end
describe
'#needs_update?'
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