Skip to content

Document how to disable callbacks for system tests #1683

@JasonBarnabe

Description

@JasonBarnabe

The readme explains how to disable callbacks in the test environment with Searchkick.disable_callbacks. As described in #1031, this does not disable callbacks when running Rails system tests as the server starts in a separate thread.

I suggest adding info on how to disable callbacks to that section of the readme. In particular, the code suggested in that issue, or something like this:


System tests

As the callbacks setting is a thread variable, you will need to add additional code to disable it in system tests.

lib/searchkick_disable_middleware.rb:

class SearchkickDisableMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    Searchkick.callbacks(false) do
      @app.call(env)
    end
  end
end

In config/environments/test.rb:

require 'searchkick_disable_middleware'

Rails.application.configure do

  # (Your other configuration...)

  config.middleware.insert_before(0, SearchkickDisableMiddleware)
end

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions