From 700cb73b8fa4ceb4653a655d8de1a1cba45857aa Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 21 Apr 2015 16:19:02 +1000 Subject: [PATCH] Send enterprise confirmation emails asynchronously --- app/models/enterprise.rb | 2 ++ spec/models/enterprise_spec.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 9b81405489..1aa76b88a8 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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 diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 97a4b988d8..69ba68569f 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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