Sha256: 8924c4a7a6b272a60a0471c873adfb9f69e5c6ae3e4bcaffbcca0b4bbedb06c8

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe AsyncRequest::Job do
  describe '.create_and_enqueue' do
    let(:worker) { WorkerWithoutErrors }

    context 'when no worker class is passed' do
      it 'fails with ArgumentError' do
        expect { described_class.create_and_enqueue(nil, []) }.to raise_error(ArgumentError)
      end
    end

    context 'when called with valid params' do
      it 'creates a new job object' do
        expect { described_class.create_and_enqueue(worker, 'a') }
          .to change { described_class.count }.by(1)
      end

      it 'creates a new job object with WorkerWithoutErrors as worker' do
        job = described_class.create_and_enqueue(worker, 'a')
        expect(job.worker).to eq worker.to_s
      end

      it "creates a new job object with ['a'] as params" do
        job = described_class.create_and_enqueue(worker, 'a')
        expect(job.params).to eq ['a']
      end

      it 'creates a new job object with waiting status' do
        job = described_class.create_and_enqueue(worker, 'a')
        expect(job.waiting?).to be_truthy
      end

      it 'serializes complex params' do
        job = described_class.create_and_enqueue(worker, { a: 'a' }, 3, 'a')
        expect(job.params).to eq [{ a: 'a' }, 3, 'a']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
async_request-1.0.0 spec/models/async_request/job_spec.rb