How to wait for ES indexing to finish in Rspec and Capybara?
Asked Answered
T

2

7

How to avoid using sleep 1 in that example for wait until ES indexing will be finished?

describe Question do
  before do
    create :question, content: "Some test question",
                      app: @app
    create :question, content: "Some other question",
                      app: @app
    sleep 1
  end

  it_behaves_like "search results found" do
    let(:query) { "Some" }
    let(:results) { ["Some test question", "Some other question"] }
  end
end
Tut answered 29/1, 2013 at 19:12 Comment(0)
A
12

Make a call to the 'refresh' API endpoint. If you're using Tire and the ActiveModel integration feature, it would be:

Question.tire.index.refresh

Alternatively you can use curl to hit the endpoint directly.

Abdomen answered 29/1, 2013 at 20:15 Comment(0)
U
2

You can call refresh on the index and that will cause it to rebuild:

Question.index.refresh

Un answered 29/1, 2013 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.