Sha256: ce344309ed6be428a0f7c51385bf40b8c3a782e8fc6480363702676b713de747

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

require 'active_support/rescuable'

describe Rollbar::ActiveJob do
  class TestJob
    # To mix in rescue_from
    include ActiveSupport::Rescuable
    include Rollbar::ActiveJob

    attr_reader :job_id
    attr_accessor :arguments

    def initialize(*arguments)
      @arguments = arguments
    end

    def perform(exception, job_id)
      @job_id = job_id
      # ActiveJob calls rescue_with_handler when a job raises an exception
      rescue_with_handler(exception) || raise(exception)
    end
  end

  before { reconfigure_notifier }

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

  it "reports the error to Rollbar" do
    expected_params = {
      :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
  end

  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rollbar-2.18.2 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.18.0 spec/rollbar/plugins/active_job_spec.rb