Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #487: Automatically add Rollbar::ActiveJob to ActionMailer::DeliveryJob #819

Merged
merged 5 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/rollbar/plugins/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ def self.included(base)
end
end
end

# Automatically add to ActionMailer::DeliveryJob
ActionMailer::DeliveryJob.send(:include, Rollbar::ActiveJob) if defined?(ActionMailer::DeliveryJob)
42 changes: 37 additions & 5 deletions spec/rollbar/plugins/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,53 @@ def perform(exception, job_id)
before { reconfigure_notifier }

let(:exception) { StandardError.new('oh no') }
let(:job_id) { "123" }
let(:job_id) { '123' }
let(:argument) { 12 }

it "reports the error to Rollbar" do
it 'reports the error to Rollbar' do
expected_params = {
:job => "TestJob",
:job => 'TestJob',
:job_id => job_id,
:use_exception_level_filters => true,
:arguments => [argument]
}
expect(Rollbar).to receive(:error).with(exception, expected_params)
TestJob.new(argument).perform(exception, job_id) rescue nil
TestJob.new(argument).perform(exception, job_id) rescue nil # rubocop:disable Style/RescueModifier
end

it "reraises the error so the job backend can handle the failure and retry" do
it 'reraises the error so the job backend can handle the failure and retry' do
expect { TestJob.new(argument).perform(exception, job_id) }.to raise_error exception
end

context 'using ActionMailer::DeliveryJob', :if => defined?(ActionMailer::DeliveryJob) do
include ActiveJob::TestHelper if defined?(ActiveJob::TestHelper) # rubocop:disable Style/MixinUsage

class TestMailer < ActionMailer::Base
attr_accessor :arguments

def test_email(*_arguments)
error = StandardError.new('oh no')
raise(error)
end
end

it 'job is created' do
ActiveJob::Base.queue_adapter = :test
expect do
TestMailer.test_email(argument).deliver_later
end.to have_enqueued_job.on_queue('mailers')
end

it 'reports the error to Rollbar' do
expected_params = {
:job => 'ActionMailer::DeliveryJob',
:use_exception_level_filters => true,
:arguments => ['TestMailer', 'test_email', 'deliver_now', 12]
}
expect(Rollbar).to receive(:error).with(kind_of(StandardError), hash_including(expected_params))
perform_enqueued_jobs do
TestMailer.test_email(argument).deliver_later rescue nil # rubocop:disable Style/RescueModifier
end
end
end
end