Commit 3b1dbd53 authored by Victor Zagorodny's avatar Victor Zagorodny

Improve scope handling in finder class

parent 9c65354b
...@@ -64,12 +64,15 @@ module Security ...@@ -64,12 +64,15 @@ module Security
end end
def init_collection(scope) def init_collection(scope)
if scope == :all case scope
when :all
vulnerable.all_vulnerabilities vulnerable.all_vulnerabilities
elsif scope == :with_sha when :with_sha
vulnerable.latest_vulnerabilities_with_sha vulnerable.latest_vulnerabilities_with_sha
else when :latest
vulnerable.latest_vulnerabilities vulnerable.latest_vulnerabilities
else
raise ArgumentError, "invalid value for 'scope': #{scope}"
end end
end end
end end
......
...@@ -130,5 +130,31 @@ describe Security::VulnerabilityFindingsFinder do ...@@ -130,5 +130,31 @@ describe Security::VulnerabilityFindingsFinder do
end end
end end
end end
describe 'scope specifiers' do
using RSpec::Parameterized::TableSyntax
where(:scope) do
[
[:all],
[:with_sha],
[:latest]
]
end
with_them do
it 'accepts the scope specifier as valid' do
expect { described_class.new(group).execute(scope) }.not_to raise_error
end
end
context 'with an invalid scope specifier' do
it 'raises error' do
expect { described_class.new(group).execute(:invalid) }.to(
raise_error(ArgumentError, "invalid value for 'scope': invalid")
)
end
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment