Sha256: 83f778cb408d63b8540c30017b4ebb1fbfce2afcf58719c2de53ab997199e8c3

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

describe QuickbooksWebConnector::Failure do

  describe '.create' do
    it 'creates a new failure and saves it' do
      failure = stub :failure
      failure.should_receive(:save)
      described_class.should_receive(:new).with(Exception, { foo: 'bar' }).and_return(failure)

      described_class.create(exception: Exception, payload: { foo: 'bar' })
    end
  end

  describe '.requeue' do
    it 'adds the failure back in as a new job' do
      described_class.create(exception: Exception.new('boom'), payload: { 'request_builder_class' => 'SomeBuilder', 'response_handler_class' => 'SomeHandler', 'args' => ['36'] })

      described_class.requeue(0)

      expect(described_class.find(0)['retried_at']).to_not be_nil

      expect(QuickbooksWebConnector.size).to eq(1)
      new_job = QuickbooksWebConnector.reserve
      expect(new_job.request_builder_class).to be(SomeBuilder)
      expect(new_job.response_handler_class).to be(SomeHandler)
      expect(new_job.args).to eq(['36'])
    end
  end

  describe '.remove' do
    it 'removes the failed job from the list' do
      described_class.create(exception: Exception.new, payload: {})

      expect(described_class.all).to have(1).job

      described_class.remove(0)

      expect(described_class.all).to have(0).jobs
    end
  end

  describe '#save' do
    subject(:failure) { described_class.new(Exception.new('something went wrong'), { foo: 'bar' }) }

    it 'stores the failure with some details in redis' do
      failure.save

      expect(described_class.count).to eq(1)

      item = described_class.all.first
      expect(item['failed_at']).to_not be_nil
      expect(item['payload']).to eq('foo' => 'bar')
      expect(item['exception']).to eq('Exception')
      expect(item['error']).to eq('something went wrong')
      expect(item['backtrace']).to be_an(Array)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
quickbooks_web_connector-0.0.6 spec/lib/quickbooks_web_connector/failure_spec.rb
quickbooks_web_connector-0.0.5 spec/lib/quickbooks_web_connector/failure_spec.rb
quickbooks_web_connector-0.0.4 spec/lib/quickbooks_web_connector/failure_spec.rb