Commit 3692ff11 authored by Avielle Wolfe's avatar Avielle Wolfe

Move test setup and execution to before

(where possible)
parent 6268189d
...@@ -45,17 +45,19 @@ shared_examples VulnerabilitiesActions do ...@@ -45,17 +45,19 @@ shared_examples VulnerabilitiesActions do
context 'when a specific page is requested' do context 'when a specific page is requested' do
let(:params) { vulnerable_params.merge(page: 2) } let(:params) { vulnerable_params.merge(page: 2) }
it 'returns the list of vulnerabilities that are on the requested page' do before do
create_list(:vulnerabilities_occurrence, 35, pipelines: [pipeline], project: project) create_list(:vulnerabilities_occurrence, 35, pipelines: [pipeline], project: project)
subject subject
end
it 'returns the list of vulnerabilities that are on the requested page' do
expect(json_response.length).to eq 15 expect(json_response.length).to eq 15
end end
end end
context 'when the vulnerabilities have feedback' do context 'when the vulnerabilities have feedback' do
it 'avoids N+1 queries', :with_request_store do before do
vulnerability = create(:vulnerabilities_occurrence, pipelines: [pipeline], project: project, report_type: :sast) vulnerability = create(:vulnerabilities_occurrence, pipelines: [pipeline], project: project, report_type: :sast)
create(:vulnerability_feedback, create(:vulnerability_feedback,
:sast, :sast,
...@@ -64,7 +66,9 @@ shared_examples VulnerabilitiesActions do ...@@ -64,7 +66,9 @@ shared_examples VulnerabilitiesActions do
issue: create(:issue, project: project), issue: create(:issue, project: project),
project: project, project: project,
project_fingerprint: vulnerability.project_fingerprint) project_fingerprint: vulnerability.project_fingerprint)
end
it 'avoids N+1 queries', :with_request_store do
control_count = ActiveRecord::QueryRecorder.new { subject } control_count = ActiveRecord::QueryRecorder.new { subject }
vulnerability = create(:vulnerabilities_occurrence, pipelines: [pipeline], project: project, report_type: :sast) vulnerability = create(:vulnerabilities_occurrence, pipelines: [pipeline], project: project, report_type: :sast)
...@@ -209,11 +213,13 @@ shared_examples VulnerabilitiesActions do ...@@ -209,11 +213,13 @@ shared_examples VulnerabilitiesActions do
context 'with a report type filter' do context 'with a report type filter' do
let(:params) { vulnerable_params.merge(report_type: %w[sast]) } let(:params) { vulnerable_params.merge(report_type: %w[sast]) }
it 'returns filtered history if filters are enabled' do before do
travel_to(Time.zone.parse('2019-02-11')) do travel_to(Time.zone.parse('2019-02-11')) do
subject subject
end end
end
it 'returns filtered history if filters are enabled' do
expect(json_response['total']).to eq({ '2018-11-12' => 1 }) expect(json_response['total']).to eq({ '2018-11-12' => 1 })
expect(json_response['critical']).to eq({ '2018-11-12' => 1 }) expect(json_response['critical']).to eq({ '2018-11-12' => 1 })
expect(json_response['low']).to eq({}) expect(json_response['low']).to eq({})
......
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