Commit 87064f42 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Michael Kozono

Remove duplicated with_request_store spec-metadata

The `with_request_store` metadata already lived inside `spec_helper`
so we don't need another one.

This also replaces the `before` and `after` blocks for handling the
request store with a single around block. The advantage of that is
that this `around` block would be wrapped around any `around` blocks
defined inside the specs. Which I think is more predictable behaviour.
parent 3c21e5e2
...@@ -63,14 +63,14 @@ class GeoNode < ApplicationRecord ...@@ -63,14 +63,14 @@ class GeoNode < ApplicationRecord
class << self class << self
# Set in gitlab.rb as external_url # Set in gitlab.rb as external_url
def current_node_url def current_node_url
RequestStore.fetch('geo_node:current_node_url') do Gitlab::SafeRequestStore.fetch('geo_node:current_node_url') do
Gitlab.config.gitlab.url Gitlab.config.gitlab.url
end end
end end
# Set in gitlab.rb as geo_node_name # Set in gitlab.rb as geo_node_name
def current_node_name def current_node_name
RequestStore.fetch('geo_node:current_node_name') do Gitlab::SafeRequestStore.fetch('geo_node:current_node_name') do
Gitlab.config.geo.node_name Gitlab.config.geo.node_name
end end
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe GeoNode, :geo, type: :model do describe GeoNode, :request_store, :geo, type: :model do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
include ::EE::GeoHelpers include ::EE::GeoHelpers
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe API::GeoNodes, :geo, :prometheus, api: true do describe API::GeoNodes, :request_store, :geo, :prometheus, api: true do
include ApiHelpers include ApiHelpers
include ::EE::GeoHelpers include ::EE::GeoHelpers
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe API::GeoReplication, :geo, :geo_fdw, api: true do describe API::GeoReplication, :request_store, :geo, :geo_fdw, api: true do
include ApiHelpers include ApiHelpers
include ::EE::GeoHelpers include ::EE::GeoHelpers
......
...@@ -187,7 +187,7 @@ describe 'GET /-/security/vulnerability_findings' do ...@@ -187,7 +187,7 @@ describe 'GET /-/security/vulnerability_findings' do
project_fingerprint: vulnerability.project_fingerprint) project_fingerprint: vulnerability.project_fingerprint)
end end
it 'avoids N+1 queries', :with_request_store do it 'avoids N+1 queries', :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)
......
# frozen_string_literal: true
RSpec.configure do |config|
config.before do
RequestStore.clear!
end
config.around(:each, :with_request_store) do |example|
RequestStore.begin!
example.run
RequestStore.end!
end
end
...@@ -68,7 +68,7 @@ RSpec.shared_examples ProjectVulnerabilityFindingsActions do ...@@ -68,7 +68,7 @@ RSpec.shared_examples ProjectVulnerabilityFindingsActions do
project_fingerprint: vulnerability.project_fingerprint) project_fingerprint: vulnerability.project_fingerprint)
end end
it 'avoids N+1 queries', :with_request_store do it 'avoids N+1 queries', :request_store do
control_count = ActiveRecord::QueryRecorder.new { subject } control_count = ActiveRecord::QueryRecorder.new { subject }
vulnerability = create(:vulnerabilities_occurrence, pipelines: [pipeline], project: vulnerable_project, report_type: :sast) vulnerability = create(:vulnerabilities_occurrence, pipelines: [pipeline], project: vulnerable_project, report_type: :sast)
......
...@@ -38,7 +38,7 @@ describe Gitlab::SafeRequestStore do ...@@ -38,7 +38,7 @@ describe Gitlab::SafeRequestStore do
describe '.clear!' do describe '.clear!' do
context 'when RequestStore is active', :request_store do context 'when RequestStore is active', :request_store do
it 'uses RequestStore' do it 'uses RequestStore' do
expect(RequestStore).to receive(:clear!).twice.and_call_original expect(RequestStore).to receive(:clear!).once.and_call_original
described_class.clear! described_class.clear!
end end
...@@ -56,7 +56,7 @@ describe Gitlab::SafeRequestStore do ...@@ -56,7 +56,7 @@ describe Gitlab::SafeRequestStore do
describe '.end!' do describe '.end!' do
context 'when RequestStore is active', :request_store do context 'when RequestStore is active', :request_store do
it 'uses RequestStore' do it 'uses RequestStore' do
expect(RequestStore).to receive(:end!).twice.and_call_original expect(RequestStore).to receive(:end!).once.and_call_original
described_class.end! described_class.end!
end end
......
...@@ -208,11 +208,11 @@ RSpec.configure do |config| ...@@ -208,11 +208,11 @@ RSpec.configure do |config|
example.run if config.inclusion_filter[:quarantine] example.run if config.inclusion_filter[:quarantine]
end end
config.before(:example, :request_store) do config.around(:example, :request_store) do |example|
RequestStore.begin! RequestStore.begin!
end
config.after(:example, :request_store) do example.run
RequestStore.end! RequestStore.end!
RequestStore.clear! RequestStore.clear!
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