Send enterprise confirmation emails asynchronously

This commit is contained in:
Rohan Mitchell
2015-04-21 16:19:02 +10:00
parent 9d225142c8
commit 700cb73b8f
2 changed files with 10 additions and 8 deletions

View File

@@ -8,6 +8,8 @@ class Enterprise < ActiveRecord::Base
preference :shopfront_taxon_order, :string, default: ""
devise :confirmable, reconfirmable: true, confirmation_keys: [ :id, :email ]
handle_asynchronously :send_confirmation_instructions
handle_asynchronously :send_on_create_confirmation_instructions
self.inheritance_column = nil

View File

@@ -10,10 +10,10 @@ describe Enterprise do
context "when the email address has not already been confirmed" do
it "sends a confirmation email" do
mail_message = double "Mail::Message"
expect(EnterpriseMailer).to receive(:confirmation_instructions).and_return mail_message
mail_message.should_receive :deliver
create(:enterprise, owner: user, email: "unknown@email.com", confirmed_at: nil )
expect do
create(:enterprise, owner: user, email: "unknown@email.com", confirmed_at: nil )
end.to enqueue_job Delayed::PerformableMethod
Delayed::Job.last.payload_object.method_name.should == :send_on_create_confirmation_instructions_without_delay
end
it "does not send a welcome email" do
@@ -41,10 +41,10 @@ describe Enterprise do
let!(:enterprise) { create(:enterprise, owner: user) }
it "when the email address has not already been confirmed" do
mail_message = double "Mail::Message"
expect(EnterpriseMailer).to receive(:confirmation_instructions).and_return mail_message
mail_message.should_receive :deliver
enterprise.update_attributes(email: "unknown@email.com")
expect do
enterprise.update_attributes(email: "unknown@email.com")
end.to enqueue_job Delayed::PerformableMethod
Delayed::Job.last.payload_object.method_name.should == :send_confirmation_instructions_without_delay
end
it "when the email address has already been confirmed" do