Run DB rake tasks on all tenants
Some tasks don't have to run on every tenant. The task to calculate the TSV is only done for records which were present before we added the TSV column, and that isn't going to happen in any tenants because we added the TSV column before adding the tenants table. Similarly, the migration needed for existing polls isn't necessary because there weren't any tenants before we allowed to set the starting/ending time to polls. We aren't adding any tests for these tasks because tests for rake tasks are slow and tests creating tenants are also slow, making the combination of the two even slower, particularly if we add tests for every single task we're changing. We're adding tests for the `.run_on_each` method instead.
This commit is contained in:
@@ -133,6 +133,27 @@ describe Tenant do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".run_on_each" do
|
||||
it "runs the code on all tenants, including the default one" do
|
||||
create(:tenant, schema: "andromeda")
|
||||
create(:tenant, schema: "milky-way")
|
||||
|
||||
Tenant.run_on_each do
|
||||
Setting["org_name"] = "oh-my-#{Tenant.current_schema}"
|
||||
end
|
||||
|
||||
expect(Setting["org_name"]).to eq "oh-my-public"
|
||||
|
||||
Tenant.switch("andromeda") do
|
||||
expect(Setting["org_name"]).to eq "oh-my-andromeda"
|
||||
end
|
||||
|
||||
Tenant.switch("milky-way") do
|
||||
expect(Setting["org_name"]).to eq "oh-my-milky-way"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
let(:tenant) { build(:tenant) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user