Commit 75a5e6aa authored by Douwe Maan's avatar Douwe Maan

Merge branch 'use-request-store-helper-instead-actual-code' into 'master'

Use :request_store hooks on specs

See merge request !12058
parents 39f3fe76 34ba8039
...@@ -69,18 +69,11 @@ describe Projects::JobsController do ...@@ -69,18 +69,11 @@ describe Projects::JobsController do
Ci::Build::AVAILABLE_STATUSES.each do |status| Ci::Build::AVAILABLE_STATUSES.each do |status|
create_build(status, status) create_build(status, status)
end end
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end end
it "verifies number of queries" do it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { get_index } recorded = ActiveRecord::QueryRecorder.new { get_index }
expect(recorded.count).to be_within(5).of(8) expect(recorded.count).to be_within(5).of(7)
end end
def create_build(name, status) def create_build(name, status)
......
...@@ -119,10 +119,8 @@ describe Projects::MergeRequestsController do ...@@ -119,10 +119,8 @@ describe Projects::MergeRequestsController do
end end
end end
context 'number of queries' do context 'number of queries', :request_store do
it 'verifies number of queries' do it 'verifies number of queries' do
RequestStore.begin!
# pre-create objects # pre-create objects
merge_request merge_request
...@@ -130,9 +128,6 @@ describe Projects::MergeRequestsController do ...@@ -130,9 +128,6 @@ describe Projects::MergeRequestsController do
expect(recorded.count).to be_within(5).of(30) expect(recorded.count).to be_within(5).of(30)
expect(recorded.cached_count).to eq(0) expect(recorded.cached_count).to eq(0)
RequestStore.end!
RequestStore.clear!
end end
end end
end end
......
...@@ -49,21 +49,14 @@ describe Projects::PipelinesController do ...@@ -49,21 +49,14 @@ describe Projects::PipelinesController do
expect(json_response['details']).to have_key 'stages' expect(json_response['details']).to have_key 'stages'
end end
context 'when the pipeline has multiple stages and groups' do context 'when the pipeline has multiple stages and groups', :request_store do
before do before do
RequestStore.begin!
create_build('build', 0, 'build') create_build('build', 0, 'build')
create_build('test', 1, 'rspec 0') create_build('test', 1, 'rspec 0')
create_build('deploy', 2, 'production') create_build('deploy', 2, 'production')
create_build('post deploy', 3, 'pages 0') create_build('post deploy', 3, 'pages 0')
end end
after do
RequestStore.end!
RequestStore.clear!
end
let(:project) { create(:project) } let(:project) { create(:project) }
let(:pipeline) do let(:pipeline) do
create(:ci_empty_pipeline, project: project, user: user, sha: project.commit.id) create(:ci_empty_pipeline, project: project, user: user, sha: project.commit.id)
......
...@@ -47,16 +47,7 @@ describe Banzai::Filter::AbstractReferenceFilter do ...@@ -47,16 +47,7 @@ describe Banzai::Filter::AbstractReferenceFilter do
end end
end end
context 'with RequestStore enabled' do context 'with RequestStore enabled', :request_store do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
it 'returns a list of Projects for a list of paths' do it 'returns a list of Projects for a list of paths' do
expect(filter.find_projects_for_paths([project.path_with_namespace])). expect(filter.find_projects_for_paths([project.path_with_namespace])).
to eq([project]) to eq([project])
......
...@@ -29,16 +29,7 @@ describe Banzai::IssuableExtractor, lib: true do ...@@ -29,16 +29,7 @@ describe Banzai::IssuableExtractor, lib: true do
expect(result).to eq(issue_link => issue, merge_request_link => merge_request) expect(result).to eq(issue_link => issue, merge_request_link => merge_request)
end end
describe 'caching' do describe 'caching', :request_store do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
it 'saves records to cache' do it 'saves records to cache' do
extractor.extract([issue_link, merge_request_link]) extractor.extract([issue_link, merge_request_link])
......
...@@ -43,18 +43,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do ...@@ -43,18 +43,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do
expect(subject.referenced_by([link])).to eq([user]) expect(subject.referenced_by([link])).to eq([user])
end end
context 'when RequestStore is active' do context 'when RequestStore is active', :request_store do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
it 'does not return users from the first call in the second' do it 'does not return users from the first call in the second' do
link['data-user'] = user.id.to_s link['data-user'] = user.id.to_s
......
...@@ -122,16 +122,7 @@ describe Group, 'Routable' do ...@@ -122,16 +122,7 @@ describe Group, 'Routable' do
it { expect(group.full_path).to eq(group.path) } it { expect(group.full_path).to eq(group.path) }
it { expect(nested_group.full_path).to eq("#{group.full_path}/#{nested_group.path}") } it { expect(nested_group.full_path).to eq("#{group.full_path}/#{nested_group.path}") }
context 'with RequestStore active' do context 'with RequestStore active', :request_store do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
it 'does not load the route table more than once' do it 'does not load the route table more than once' do
expect(group).to receive(:uncached_full_path).once.and_call_original expect(group).to receive(:uncached_full_path).once.and_call_original
......
...@@ -389,16 +389,7 @@ describe ProjectTeam, models: true do ...@@ -389,16 +389,7 @@ describe ProjectTeam, models: true do
end end
describe '#max_member_access_for_user_ids' do describe '#max_member_access_for_user_ids' do
context 'with RequestStore enabled' do context 'with RequestStore enabled', :request_store do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
include_examples 'max member access for users' include_examples 'max member access for users'
def access_levels(users) def access_levels(users)
......
...@@ -102,18 +102,11 @@ describe PipelineSerializer do ...@@ -102,18 +102,11 @@ describe PipelineSerializer do
Ci::Pipeline::AVAILABLE_STATUSES.each do |status| Ci::Pipeline::AVAILABLE_STATUSES.each do |status|
create_pipeline(status) create_pipeline(status)
end end
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end end
it "verifies number of queries" do it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(1).of(60) expect(recorded.count).to be_within(1).of(57)
expect(recorded.cached_count).to eq(0) expect(recorded.cached_count).to eq(0)
end end
......
...@@ -74,6 +74,15 @@ RSpec.configure do |config| ...@@ -74,6 +74,15 @@ RSpec.configure do |config|
TestEnv.cleanup TestEnv.cleanup
end end
config.before(:example, :request_store) do
RequestStore.begin!
end
config.after(:example, :request_store) do
RequestStore.end!
RequestStore.clear!
end
if ENV['CI'] if ENV['CI']
# Retry only on feature specs that use JS # Retry only on feature specs that use JS
config.around :each, :js do |ex| config.around :each, :js do |ex|
......
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