Sha256: 632e435c3e844ae00a994b35f15c2682314f27b49493039ee33a02c4d6c20f80

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

class StatusedRoutine
  lev_routine

  protected
  def exec
    status.set_progress(9, 10)
    status.save({'hi' => 'there'})
    fatal_error(code: 'blah', message: 'hi')
  end
end

RSpec.describe 'Statused Routines' do

  before { Lev::Jobba.use_jobba }

  context 'in a routine' do
    it 'queues the job object on queue' do
      id = StatusedRoutine.perform_later
      status = Jobba::Status.find(id)

      expect(status).to be_queued
    end

    context 'inline activejob mode' do
      before { ::ActiveJob::Base.queue_adapter = :inline }
      after { ::ActiveJob::Base.queue_adapter = :test }

      it 'sets job to started when called' do
        expect_any_instance_of(Jobba::Status).to receive(:started!)
        StatusedRoutine.perform_later
      end

      it 'completes the status object on completion, returning other data' do
        id = StatusedRoutine.perform_later
        status = Jobba::Status.find(id)
        expect(status).to be_failed
        expect(status.progress).to eq(0.9)
        expect(status.errors).to contain_exactly(
          a_hash_including({'code' => 'blah', 'message' => 'hi'})
        )
        expect(status.data).to eq ({'hi' => 'there'})
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lev-7.0.3 spec/statused_routines_spec.rb
lev-7.0.2 spec/statused_routines_spec.rb
lev-7.0.1 spec/statused_routines_spec.rb