mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
Merge pull request #5031 from tgxworld/introduce_multisite_tests
Introduce multisite tests for better coverage.
This commit is contained in:
commit
1f07050d12
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -36,6 +36,7 @@ config/discourse.conf
|
|||
*.sql.gz
|
||||
/db/*.sqlite3
|
||||
/db/structure.sql
|
||||
/db/schema.rb
|
||||
|
||||
# Ignore all logfiles and tempfiles.
|
||||
/log/*.log
|
||||
|
|
|
@ -18,7 +18,7 @@ development:
|
|||
test:
|
||||
prepared_statements: false
|
||||
adapter: postgresql
|
||||
database: discourse_test
|
||||
database: discourse_test<%= ENV['MULTISITE'] ? "_#{ENV['MULTISITE']}" : '' %>
|
||||
min_messages: warning
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
|
|
@ -53,6 +53,7 @@ class SiteSettings::DefaultsProvider
|
|||
@defaults.each { |_, hash| hash.delete(name) }
|
||||
@defaults[DEFAULT_LOCALE.to_sym][name] = value
|
||||
value, type = @site_setting.type_supervisor.to_db_value(name, value)
|
||||
@defaults[self.site_locale.to_sym] ||= {}
|
||||
@defaults[self.site_locale.to_sym][name] = @site_setting.type_supervisor.to_rb_value(name, value, type)
|
||||
else
|
||||
raise ArgumentError.new("No setting named '#{name}' exists")
|
||||
|
|
|
@ -3,10 +3,28 @@ task 'set_locale' do
|
|||
I18n.locale = (SiteSetting.default_locale || :en) rescue :en
|
||||
end
|
||||
|
||||
task 'db:create', [:multisite] => [:load_config] do |_, args|
|
||||
if Rails.env.test? && !args[:multisite]
|
||||
system("MULTISITE=multisite rake db:create['true']")
|
||||
end
|
||||
end
|
||||
|
||||
task 'db:drop', [:multisite] => [:load_config] do |_, args|
|
||||
if Rails.env.test? && !args[:multisite]
|
||||
system("MULTISITE=multisite rake db:drop['true']")
|
||||
end
|
||||
end
|
||||
|
||||
# we need to run seed_fu every time we run rake db:migrate
|
||||
task 'db:migrate' => ['environment', 'set_locale'] do
|
||||
task 'db:migrate', [:multisite] => ['environment', 'set_locale'] do |_, args|
|
||||
SeedFu.seed
|
||||
Jobs::Onceoff.enqueue_all
|
||||
|
||||
if Rails.env.test? && !args[:multisite]
|
||||
system("rake db:schema:dump")
|
||||
system("MULTISITE=multisite rake db:schema:load")
|
||||
system("MULTISITE=multisite rake db:migrate['multisite']")
|
||||
end
|
||||
end
|
||||
|
||||
task 'test:prepare' => 'environment' do
|
||||
|
|
5
spec/fixtures/multisite/two_dbs.yml
vendored
Normal file
5
spec/fixtures/multisite/two_dbs.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
second:
|
||||
adapter: postgresql
|
||||
database: discourse_test_multisite
|
||||
host_names:
|
||||
- test2.localhost
|
52
spec/multisite/site_settings_spec.rb
Normal file
52
spec/multisite/site_settings_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Multisite SiteSettings' 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"
|
||||
conn.load_settings!
|
||||
end
|
||||
|
||||
after do
|
||||
['default', 'second'].each do |db|
|
||||
conn.with_connection(db) { SiteSetting.destroy_all }
|
||||
end
|
||||
|
||||
conn.clear_settings!
|
||||
|
||||
[:@@db_spec_cache, :@@host_spec_cache, :@@default_spec].each do |class_variable|
|
||||
conn.remove_class_variable(class_variable)
|
||||
end
|
||||
|
||||
SiteSetting.provider = @original_provider
|
||||
end
|
||||
|
||||
describe '#default_locale' do
|
||||
it 'should return the right locale' do
|
||||
conn.with_connection('default') do
|
||||
expect(SiteSetting.default_locale).to eq('en')
|
||||
end
|
||||
|
||||
conn.with_connection('second') do
|
||||
SiteSetting.default_locale = 'zh_TW'
|
||||
|
||||
expect(SiteSetting.default_locale).to eq('zh_TW')
|
||||
end
|
||||
|
||||
conn.with_connection('default') do
|
||||
expect(SiteSetting.default_locale).to eq('en')
|
||||
|
||||
SiteSetting.default_locale = 'ja'
|
||||
|
||||
expect(SiteSetting.default_locale).to eq('ja')
|
||||
end
|
||||
|
||||
conn.with_connection('second') do
|
||||
expect(SiteSetting.default_locale).to eq('zh_TW')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user