Sha256: 49f8befa8cc22eccd0602968c99ae60afe909311772f0604ff33f92944772021

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

require_relative 'test_helper'
require 'active_job'
require 'dynflow/active_job/queue_adapter'

module Dynflow
  class SampleJob < ::ActiveJob::Base
    queue_as :slow

    def perform(msg)
      puts "This job says #{msg}"
    end
  end

  describe 'running jobs' do
    before(:all) do
      world = WorldFactory.create_world
      ::ActiveJob::QueueAdapters.send(:include, ::Dynflow::ActiveJob::QueueAdapters)
      ::ActiveJob::Base.queue_adapter = :dynflow
      dynflow_mock = Minitest::Mock.new
      dynflow_mock.expect(:world, world)
      rails_app_mock = Minitest::Mock.new
      rails_app_mock .expect(:dynflow, dynflow_mock)
      rails_mock = Minitest::Mock.new
      rails_mock.expect(:application, rails_app_mock)
      if defined? ::Rails
        @original_rails = ::Rails
        Object.send(:remove_const, 'Rails')
      end
      Object.const_set('Rails', rails_mock)
    end

    after(:all) do
      Object.send(:remove_const, 'Rails')
      Object.const_set('Rails', @original_rails)
    end

    it 'is able to run the job right away' do
      out, = capture_subprocess_io do
        SampleJob.perform_now 'hello'
      end
      assert_match(/job says hello/, out)
    end

    it 'enqueues the job' do
      out, = capture_subprocess_io do
        SampleJob.perform_later 'hello'
      end
      assert_match(/Enqueued Dynflow::SampleJob/, out)
    end

    it 'schedules job in the future' do
      out, = capture_subprocess_io do
        SampleJob.set(:wait => 1.seconds).perform_later 'hello'
      end
      assert_match(/Enqueued Dynflow::SampleJob.*at.*UTC/, out)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dynflow-1.0.4 test/activejob_adapter_test.rb
dynflow-1.0.3 test/activejob_adapter_test.rb
dynflow-1.0.2 test/activejob_adapter_test.rb
dynflow-1.0.1 test/activejob_adapter_test.rb
dynflow-1.0.0 test/activejob_adapter_test.rb