Allow seeding a specific tenant with db:dev_seed
Until now, running `db:dev_seed` created development data for the default tenant but it was impossible to create this data for other tenants. Now the tenant can be provided as a parameter. Note that, in order to be able to execute this task twice while running the tests, we need to use `load` instead of `require_relative`, since `require_relative` doesn't load the file again if it's already loaded. Also note that having two optional parameters in a rake task results in a cumbersome syntax to execute it. To avoid this, we're simply removing the `print_log` parameter, which was used mainly for the test environment. Now we use a different logic to get the same result. From now on it won't be possible to pass the option to avoid the log in the development environment. I don't know a developer who's ever used this option, though, and it can always be done using `> /dev/null`.
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "rake db:dev_seed" do
|
||||
let :run_rake_task do
|
||||
Rake.application.invoke_task("db:dev_seed[avoid_log]")
|
||||
end
|
||||
before { Rake::Task["db:dev_seed"].reenable }
|
||||
|
||||
it "seeds the database without errors" do
|
||||
expect { run_rake_task }.not_to raise_error
|
||||
expect { Rake.application.invoke_task("db:dev_seed") }.not_to raise_error
|
||||
end
|
||||
|
||||
it "can seed a tenant" do
|
||||
create(:tenant, schema: "democracy")
|
||||
|
||||
Rake.application.invoke_task("db:dev_seed[democracy]")
|
||||
|
||||
expect(Debate.count).to eq 0
|
||||
Tenant.switch("democracy") { expect(Debate.count).not_to eq 0 }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user