Allow specifying the tenant in budget tasks
The `budgets📧selected` and `budgets📧unselected` tasks are supposed to be run manually because they only make sense at a specific point during the life of a budget. However, they would only run on the default tenant, and it was impossible to run them on a different tenant. So we're introducing an argument in the rake task accepting the name of the tenant whose users we want to send emails to.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
namespace :budgets do
|
||||
namespace :email do
|
||||
desc "Sends emails to authors of selected investments"
|
||||
task selected: :environment do
|
||||
Budget.current.email_selected
|
||||
task :selected, [:tenant] => :environment do |_, args|
|
||||
Tenant.switch(args[:tenant]) { Budget.current.email_selected }
|
||||
end
|
||||
|
||||
desc "Sends emails to authors of unselected investments"
|
||||
task unselected: :environment do
|
||||
Budget.current.email_unselected
|
||||
task :unselected, [:tenant] => :environment do |_, args|
|
||||
Tenant.switch(args[:tenant]) { Budget.current.email_unselected }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,20 @@ describe "budget tasks" do
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||
expect(ActionMailer::Base.deliveries.last.to).to eq ["selectme@consul.dev"]
|
||||
end
|
||||
|
||||
it "accepts specifying the tenant" do
|
||||
create(:budget_investment, :selected, author: create(:user, email: "default@consul.dev"))
|
||||
create(:tenant, schema: "different")
|
||||
|
||||
Tenant.switch("different") do
|
||||
create(:budget_investment, :selected, author: create(:user, email: "different@consul.dev"))
|
||||
end
|
||||
|
||||
Rake.application.invoke_task("budgets:email:selected[different]")
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||
expect(ActionMailer::Base.deliveries.last.to).to eq ["different@consul.dev"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "rake budgets:email:unselected" do
|
||||
@@ -27,5 +41,19 @@ describe "budget tasks" do
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||
expect(ActionMailer::Base.deliveries.last.to).to eq ["ignorme@consul.dev"]
|
||||
end
|
||||
|
||||
it "accepts specifying the tenant" do
|
||||
create(:budget_investment, author: create(:user, email: "default@consul.dev"))
|
||||
create(:tenant, schema: "different")
|
||||
|
||||
Tenant.switch("different") do
|
||||
create(:budget_investment, author: create(:user, email: "different@consul.dev"))
|
||||
end
|
||||
|
||||
Rake.application.invoke_task("budgets:email:unselected[different]")
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||
expect(ActionMailer::Base.deliveries.last.to).to eq ["different@consul.dev"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user