Files
nairobi/spec/lib/tasks/dashboards_spec.rb
Javi Martín 7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00

85 lines
2.8 KiB
Ruby

require "rails_helper"
require "rake"
describe "Dashboards Rake" do
describe "#send_notifications" do
before do
Rake.application.rake_require "tasks/dashboards"
Rake::Task.define_task(:environment)
Setting["dashboard.emails"] = true
ActionMailer::Base.deliveries.clear
end
let :run_rake_task do
Rake::Task["dashboards:send_notifications"].reenable
Rake.application.invoke_task "dashboards:send_notifications"
end
describe "Not send notifications to proposal author" do
let!(:action) { create(:dashboard_action, :proposed_action, :active, day_offset: 1) }
let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 1) }
it "when there are not news actions actived for published proposals" do
create(:proposal)
action.update!(published_proposal: true)
resource.update!(published_proposal: true)
expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0)
end
it "when there are not news actions actived for draft proposals" do
create(:proposal, :draft)
action.update!(published_proposal: false)
resource.update!(published_proposal: false)
expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0)
end
it "when there are news actions actived for archived proposals" do
create(:proposal, :archived)
action.update!(day_offset: 0, published_proposal: true)
resource.update!(day_offset: 0, published_proposal: true)
expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0)
end
end
describe "Send notifications to proposal author" do
let!(:action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0) }
let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0) }
it " when there are news actions actived for published proposals" do
proposal = create(:proposal)
action.update!(published_proposal: true)
resource.update!(published_proposal: true)
run_rake_task
email = open_last_email
expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
expect(email).to deliver_to(proposal.author)
expect(email).to have_subject("More news about your citizen proposal")
end
it "when there are news actions actived for draft proposals" do
proposal = create(:proposal, :draft)
action.update!(published_proposal: false)
resource.update!(published_proposal: false)
run_rake_task
email = open_last_email
expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
expect(email).to deliver_to(proposal.author)
expect(email).to have_subject("More news about your citizen proposal")
end
end
end
end