Use :request_store hooks on specs

This commit is contained in:
Oswaldo Ferreira 2017-06-09 14:12:51 -03:00
parent ce37a209c6
commit 34ba80392d
10 changed files with 20 additions and 82 deletions

View File

@ -69,18 +69,11 @@ describe Projects::JobsController do
Ci::Build::AVAILABLE_STATUSES.each do |status|
create_build(status, status)
end
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
it "verifies number of queries" do
it 'verifies number of queries', :request_store do
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
def create_build(name, status)

View File

@ -119,10 +119,8 @@ describe Projects::MergeRequestsController do
end
end
context 'number of queries' do
context 'number of queries', :request_store do
it 'verifies number of queries' do
RequestStore.begin!
# pre-create objects
merge_request
@ -130,9 +128,6 @@ describe Projects::MergeRequestsController do
expect(recorded.count).to be_within(5).of(30)
expect(recorded.cached_count).to eq(0)
RequestStore.end!
RequestStore.clear!
end
end
end

View File

@ -49,21 +49,14 @@ describe Projects::PipelinesController do
expect(json_response['details']).to have_key 'stages'
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
RequestStore.begin!
create_build('build', 0, 'build')
create_build('test', 1, 'rspec 0')
create_build('deploy', 2, 'production')
create_build('post deploy', 3, 'pages 0')
end
after do
RequestStore.end!
RequestStore.clear!
end
let(:project) { create(:project) }
let(:pipeline) do
create(:ci_empty_pipeline, project: project, user: user, sha: project.commit.id)

View File

@ -47,16 +47,7 @@ describe Banzai::Filter::AbstractReferenceFilter do
end
end
context 'with RequestStore enabled' do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
context 'with RequestStore enabled', :request_store do
it 'returns a list of Projects for a list of paths' do
expect(filter.find_projects_for_paths([project.path_with_namespace])).
to eq([project])

View File

@ -29,16 +29,7 @@ describe Banzai::IssuableExtractor, lib: true do
expect(result).to eq(issue_link => issue, merge_request_link => merge_request)
end
describe 'caching' do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
describe 'caching', :request_store do
it 'saves records to cache' do
extractor.extract([issue_link, merge_request_link])

View File

@ -43,18 +43,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do
expect(subject.referenced_by([link])).to eq([user])
end
context 'when RequestStore is active' do
context 'when RequestStore is active', :request_store do
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
link['data-user'] = user.id.to_s

View File

@ -122,16 +122,7 @@ describe Group, 'Routable' do
it { expect(group.full_path).to eq(group.path) }
it { expect(nested_group.full_path).to eq("#{group.full_path}/#{nested_group.path}") }
context 'with RequestStore active' do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
context 'with RequestStore active', :request_store do
it 'does not load the route table more than once' do
expect(group).to receive(:uncached_full_path).once.and_call_original

View File

@ -389,16 +389,7 @@ describe ProjectTeam, models: true do
end
describe '#max_member_access_for_user_ids' do
context 'with RequestStore enabled' do
before do
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
context 'with RequestStore enabled', :request_store do
include_examples 'max member access for users'
def access_levels(users)

View File

@ -102,18 +102,11 @@ describe PipelineSerializer do
Ci::Pipeline::AVAILABLE_STATUSES.each do |status|
create_pipeline(status)
end
RequestStore.begin!
end
after do
RequestStore.end!
RequestStore.clear!
end
it "verifies number of queries" do
it 'verifies number of queries', :request_store do
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)
end

View File

@ -74,6 +74,15 @@ RSpec.configure do |config|
TestEnv.cleanup
end
config.before(:example, :request_store) do
RequestStore.begin!
end
config.after(:example, :request_store) do
RequestStore.end!
RequestStore.clear!
end
if ENV['CI']
# Retry only on feature specs that use JS
config.around :each, :js do |ex|