[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to disable callbacks for system tests #1683

Open
JasonBarnabe opened this issue Jun 26, 2024 · 0 comments
Open

Document how to disable callbacks for system tests #1683

JasonBarnabe opened this issue Jun 26, 2024 · 0 comments

Comments

@JasonBarnabe
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant