From 85620abb710741ed83c42565b1033c492a756aeb Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 11 Sep 2018 10:15:06 +0800 Subject: [PATCH] DEV: Clear connections after multisite specs. --- spec/multisite/distributed_cache_spec.rb | 11 +---------- spec/multisite/jobs_spec.rb | 21 ++++----------------- spec/multisite/site_settings_spec.rb | 5 +---- spec/rails_helper.rb | 11 +++++++++++ 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/spec/multisite/distributed_cache_spec.rb b/spec/multisite/distributed_cache_spec.rb index a6080c75767..cdd25dbfaf8 100644 --- a/spec/multisite/distributed_cache_spec.rb +++ b/spec/multisite/distributed_cache_spec.rb @@ -1,17 +1,8 @@ require 'rails_helper' -RSpec.describe 'Multisite SiteSettings' do +RSpec.describe 'Multisite SiteSettings', type: :multisite do let(:conn) { RailsMultisite::ConnectionManagement } - before do - conn.config_filename = "spec/fixtures/multisite/two_dbs.yml" - end - - after do - conn.clear_settings! - ActiveRecord::Base.establish_connection - end - def cache(name, namespace: true) DistributedCache.new(name, namespace: namespace) end diff --git a/spec/multisite/jobs_spec.rb b/spec/multisite/jobs_spec.rb index 0ffd9f47a5b..943f33642ca 100644 --- a/spec/multisite/jobs_spec.rb +++ b/spec/multisite/jobs_spec.rb @@ -1,24 +1,11 @@ require 'rails_helper' -RSpec.describe "Running Sidekiq Jobs in Multisite" do +RSpec.describe "Running Sidekiq Jobs in Multisite", type: :multisite do let(:conn) { RailsMultisite::ConnectionManagement } - before do - conn.config_filename = "spec/fixtures/multisite/two_dbs.yml" - end - - after do - conn.clear_settings! - ActiveRecord::Base.establish_connection - end - it 'should revert back to the default connection' do - expect(RailsMultisite::ConnectionManagement.current_db) - .to eq('default') - - Jobs::DestroyOldDeletionStubs.new.perform({}) - - expect(RailsMultisite::ConnectionManagement.current_db) - .to eq('default') + expect do + Jobs::DestroyOldDeletionStubs.new.perform({}) + end.to_not change { RailsMultisite::ConnectionManagement.current_db } end end diff --git a/spec/multisite/site_settings_spec.rb b/spec/multisite/site_settings_spec.rb index bfecad7fd36..5a0d7b4719f 100644 --- a/spec/multisite/site_settings_spec.rb +++ b/spec/multisite/site_settings_spec.rb @@ -1,12 +1,11 @@ require 'rails_helper' -RSpec.describe 'Multisite SiteSettings' do +RSpec.describe 'Multisite SiteSettings', type: :multisite do let(:conn) { RailsMultisite::ConnectionManagement } before do @original_provider = SiteSetting.provider SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting) - conn.config_filename = "spec/fixtures/multisite/two_dbs.yml" end after do @@ -14,9 +13,7 @@ RSpec.describe 'Multisite SiteSettings' do conn.with_connection(db) { SiteSetting.where(name: 'default_locale').destroy_all } end - conn.clear_settings! SiteSetting.provider = @original_provider - ActiveRecord::Base.establish_connection end describe '#default_locale' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index b267a16e0ef..c1ac4760774 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -175,6 +175,17 @@ RSpec.configure do |config| end end + config.before(:each, type: :multisite) do + RailsMultisite::ConnectionManagement.config_filename = + "spec/fixtures/multisite/two_dbs.yml" + end + + config.after(:each, type: :multisite) do + RailsMultisite::ConnectionManagement.clear_settings! + ActiveRecord::Base.clear_active_connections! + ActiveRecord::Base.establish_connection + end + class TestCurrentUserProvider < Auth::DefaultCurrentUserProvider def log_on_user(user, session, cookies) session[:current_user_id] = user.id