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`.
19 lines
474 B
Ruby
19 lines
474 B
Ruby
require "rails_helper"
|
|
|
|
describe "rake db:dev_seed" do
|
|
before { Rake::Task["db:dev_seed"].reenable }
|
|
|
|
it "seeds the database without errors" do
|
|
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
|