Sha256: 4c2900e519245b71d59e8e98857cd98a31dfffca55d0080ee1011ce99b1d046a

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require_relative '../test_helper'

class OnDemandJobTest < Minitest::Test
  describe RocketJob::Jobs::OnDemandJob do
    before do
      RocketJob::Jobs::OnDemandJob.delete_all
    end

    describe '#perform' do
      it 'hello world' do
        code = <<~CODE
          logger.info 'Hello World'
        CODE

        job = RocketJob::Jobs::OnDemandJob.new(code: code)
        job.perform_now
      end

      it 'retain output' do
        code = <<~CODE
          {'value' => 'h' * 24}
        CODE

        job = RocketJob::Jobs::OnDemandJob.new(
          code:           code,
          collect_output: true
        )
        job.perform_now
        assert_equal 'h' * 24, job.result['value']
      end

      it 'accepts input data' do
        code = <<~CODE
          {'value' => data['a'] * data['b']}
        CODE

        job = RocketJob::Jobs::OnDemandJob.new(
          code:           code,
          collect_output: true,
          data:           {'a' => 10, 'b' => 2}
        )
        job.perform_now
        assert_equal 20, job.result['value']
      end

      it 'validates code' do
        code = <<~CODE
          def bad code
        CODE

        job = RocketJob::Jobs::OnDemandJob.new(code: code)
        refute job.valid?
        assert_raises Mongoid::Errors::Validations do
          job.perform_now
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rocketjob-3.5.2 test/jobs/on_demand_job_test.rb
rocketjob-3.5.1 test/jobs/on_demand_job_test.rb
rocketjob-3.5.0 test/jobs/on_demand_job_test.rb