7

如何避免sleep 1在该示例中使用等待 ES 索引完成?

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
4

2 回答 2

12

调用“刷新”API 端点。如果您使用的是 Tire 和 ActiveModel 集成功能,它将是:

Question.tire.index.refresh

或者,您可以使用 curl 直接命中端点。

于 2013-01-29T20:15:25.967 回答
2

您可以调用refresh索引,这将导致它重建:

Question.index.refresh

于 2013-01-29T20:17:23.000 回答