Sha256: 3e1142720004cf36b20f131d343c8b74f7a125c6de32ccc24c6731c15b297aa9

Contents?: true

Size: 1.05 KB

Versions: 37

Compression:

Stored size: 1.05 KB

Contents

require 'dynflow/testing'
module ForemanTasks
  module TestHelpers
    def self.use_in_memory_sqlite!
      raise 'the in thread world have already been initialized' if @test_in_thread_world
      @use_in_memory_sqlite = true
    end

    def self.test_in_thread_world
      return @test_in_thread_world if @test_in_thread_world
      world_config = ForemanTasks.dynflow.config.world_config
      if @use_in_memory_sqlite
        world_config.persistence_adapter = lambda do |*_args|
          ::Dynflow::PersistenceAdapters::Sequel.new('adapter' => 'sqlite', 'database' => ':memory:')
        end
      end
      @test_in_thread_world = ::Dynflow::Testing::InThreadWorld.new(world_config)
    end

    module WithInThreadExecutor
      extend ActiveSupport::Concern
      included do
        setup do
          @old_dynflow_world = ForemanTasks.dynflow.world
          ForemanTasks.dynflow.world = ForemanTasks::TestHelpers.test_in_thread_world
        end

        teardown do
          ForemanTasks.dynflow.world = @old_dynflow_world
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 lib/foreman_tasks/test_helpers.rb
foreman-tasks-10.0.1 lib/foreman_tasks/test_helpers.rb
foreman-tasks-10.0.0 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.2.3 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.2.2 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.2.1 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.2.0 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.1.1 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.0.4 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.1.0 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.0.2 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.0.1 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.3.3 lib/foreman_tasks/test_helpers.rb
foreman-tasks-9.0.0 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.2.1 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.1.4 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.3.2 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.3.1 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.1.3 lib/foreman_tasks/test_helpers.rb
foreman-tasks-8.3.0 lib/foreman_tasks/test_helpers.rb