DEV: Clear connections after multisite specs.

This commit is contained in:
Guo Xiang Tan 2018-09-11 10:15:06 +08:00
parent 244948497a
commit 85620abb71
4 changed files with 17 additions and 31 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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