Sha256: 5f71d5c674421212ac537bbc375c5f7d61ad2af30728ebdfa6caa78b0756fcd4

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

class MailerSubscriber < ActionMailer::Base
  include Reactor::Subscribable

  def fire_mailer(event)
    mail subject: 'Here is a mailer',
         to: 'reactor@hired.com',
         from: 'test+reactor@hired.com',
         body: 'an example email body'
  end
end

class MyMailerWorker < Reactor::Workers::MailerWorker
  self.source = MailerSubscriber
  self.action = :fire_mailer
  self.async  = false
  self.delay  = 0
  self.deprecated = false
end

class MyBlockMailerWorker < Reactor::Workers::MailerWorker
  self.source = MailerSubscriber
  self.async  = false
  self.delay  = 0
  self.action = lambda { |event| fire_mailer(event) }
  self.deprecated = false
end

describe Reactor::Workers::MailerWorker do
  let(:klass) { MyMailerWorker }
  let(:event_data) { Hash[some_example: :event_data] }
  subject { klass.new.perform(event_data) }

  before do
    allow_any_instance_of(klass).to receive(:should_perform?).and_return(true)
  end

  it_behaves_like 'configurable subscriber worker'

  it 'sends an email from symbol method name' do
    expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(1)
  end

  context 'for a block subscription' do
    let(:klass) { MyBlockMailerWorker }

    it 'sends an email from the block' do
      expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(1)
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reactor-0.19.0 spec/workers/mailer_worker_spec.rb
reactor-0.18.0 spec/workers/mailer_worker_spec.rb
reactor-0.17.0 spec/workers/mailer_worker_spec.rb
reactor-0.16.1 spec/workers/mailer_worker_spec.rb
reactor-0.16.0 spec/workers/mailer_worker_spec.rb