Sha256: 16514e30738e98b881f95f01334ad578336d46e0f5f9e23edf57dac0ad0b0813

Contents?: true

Size: 956 Bytes

Versions: 1

Compression:

Stored size: 956 Bytes

Contents

require 'spec_helper'

RSpec.describe Lev::BackgroundJob do
  class DelayedRoutine
    lev_routine
    protected
    def exec; end
  end

  subject(:job) { described_class.all.last }

  before do
    Lev.configuration.job_store.clear
    allow(SecureRandom).to receive(:uuid) { '123abc' }
    DelayedRoutine.perform_later
  end

  it 'behaves as a nice ruby object' do
    expect(job.id).to eq('123abc')
    expect(job.status).to eq(Lev::BackgroundJob::STATE_QUEUED)
    expect(job.progress).to eq(0.0)
  end

  it 'is unknown when not found' do
    foo = described_class.find('noooooo')
    expect(foo.status).to eq(Lev::BackgroundJob::STATE_UNKNOWN)
  end

  it 'uses as_json' do
    json = job.as_json

    expect(json).to eq({
      'id' => '123abc',
      'status' => Lev::BackgroundJob::STATE_QUEUED,
      'progress' => 0.0,
      'errors' => []
    })

    job.save(foo: :bar)
    json = job.as_json

    expect(json['foo']).to eq('bar')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lev-5.0.0 spec/lev/status_spec.rb