Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 47 lines (40 sloc) 1.33 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
require 'spec_helper'

require 'action_mailer'
class MyMailer < ActionMailer::Base
  def signup(email)
    mail :to => email, :subject => "Delaying Emails"
  end
end

describe ActionMailer::Base do
  describe "delay" do
    it "should enqueue a PerformableEmail job" do
      lambda {
        job = MyMailer.delay.signup('john@example.com')
        job.payload_object.class.should == Delayed::PerformableMailer
        job.payload_object.method_name.should == :signup
        job.payload_object.args.should == ['john@example.com']
      }.should change { Delayed::Job.count }.by(1)
    end
  end

  describe "delay on a mail object" do
    it "should raise an exception" do
      lambda {
        MyMailer.signup('john@example.com').delay
      }.should raise_error(RuntimeError)
    end
  end

  describe Delayed::PerformableMailer do
    describe "perform" do
      before do
        @email = mock('email', :deliver => true)
        @mailer_class = mock('MailerClass', :signup => @email)
        @mailer = Delayed::PerformableMailer.new(@mailer_class, :signup, ['john@example.com'])
      end

      it "should call the method and #deliver on the mailer" do
        @mailer_class.should_receive(:signup).with('john@example.com')
        @email.should_receive(:deliver)
        @mailer.perform
      end
    end
  end

end
Something went wrong with that request. Please try again.