-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jobs for queuing and delivering petition emails
- Loading branch information
Showing
11 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class DeliverPetitionEmailJob < ActiveJob::Base | ||
include EmailDelivery | ||
|
||
attr_reader :email | ||
|
||
def perform(**args) | ||
@email = args[:email] | ||
super | ||
end | ||
|
||
def create_email | ||
mailer.email_signer petition, signature, email | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class EmailPetitionersJob < ActiveJob::Base | ||
include EmailAllPetitionSignatories | ||
|
||
self.email_delivery_job_class = DeliverPetitionEmailJob | ||
self.timestamp_name = 'petition_email' | ||
|
||
attr_reader :email | ||
|
||
def perform(**args) | ||
@email = args[:email] | ||
super | ||
end | ||
|
||
private | ||
|
||
def mailer_arguments(signature) | ||
super.merge(email: email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
require_relative 'shared_examples' | ||
|
||
RSpec.describe DeliverPetitionEmailJob, type: :job do | ||
let(:requested_at) { Time.current.change(usec: 0) } | ||
let(:requested_at_as_string) { requested_at.getutc.iso8601(6) } | ||
|
||
let(:petition) { FactoryGirl.create(:debated_petition) } | ||
let(:signature) { FactoryGirl.create(:validated_signature, petition: petition) } | ||
let(:email) { FactoryGirl.create(:petition_email, petition: petition) } | ||
let(:timestamp_name) { 'petition_email' } | ||
|
||
let :arguments do | ||
{ | ||
signature: signature, | ||
timestamp_name: timestamp_name, | ||
petition: petition, | ||
requested_at: requested_at_as_string, | ||
email: email | ||
} | ||
end | ||
|
||
before do | ||
petition.set_email_requested_at_for(timestamp_name, to: requested_at) | ||
end | ||
|
||
it_behaves_like "a job to send an signatory email" | ||
|
||
it "uses the correct mailer method to generate the email" do | ||
expect(subject).to receive_message_chain(:mailer, :email_signer).with(petition, signature, email).and_return double.as_null_object | ||
subject.perform(**arguments) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rails_helper' | ||
require_relative 'shared_examples' | ||
|
||
RSpec.describe EmailPetitionersJob, type: :job do | ||
let(:email_requested_at) { Time.current } | ||
let(:petition) { FactoryGirl.create(:open_petition) } | ||
let(:signature) { FactoryGirl.create(:validated_signature, :petition => petition) } | ||
let(:email) { FactoryGirl.create(:petition_email, petition: petition) } | ||
let(:arguments) { { petition: petition, email: email } } | ||
|
||
before do | ||
petition.set_email_requested_at_for('petition_email', to: email_requested_at) | ||
allow(petition).to receive_message_chain(:signatures_to_email_for, :find_each).and_yield(signature) | ||
end | ||
|
||
it_behaves_like "job to enqueue signatory mailing jobs" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters