Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 699
tomekfranek Avatar asked Jan 29 '13 19:01

tomekfranek


2 Answers

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.

like image 195
Dave S. Avatar answered Oct 25 '22 14:10

Dave S.


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

Question.index.refresh

like image 27
Shane Andrade Avatar answered Oct 25 '22 15:10

Shane Andrade