【问题标题】:How can I get Sunspot to index the fixtures for my test environment?如何让 Sunspot 为我的测试环境索引灯具?
【发布时间】:2012-02-13 14:32:48
【问题描述】:

我有一个使用 Sunspot 和 Solr 来提供搜索功能的 rails 应用程序。 我目前正在编写功能测试(使用 Rails 自己的测试套件),以验证当我在参数中使用搜索词调用搜索控制器时,是否返回了正确的记录。

目前我有:

test "should_return_some_records" do
  get :index, :term => "search term here"
  assert_response :success
  assert more stuff ...
end

当我运行 rake test:functionals 时,这个测试会出现“ActionView::Template::Error”,因为 Sunspot 从其搜索块返回了一个空的结果数组。

如果我在我的 searchs_controller_test 的设置方法中运行 rake sunspot:reindex,则测试通过。但是,这意味着该文件中的每个测试也会运行它的操作,这会使事情变得非常缓慢。

有人可以给我一些关于让 Sunspot 为我的测试环境索引我的装置的最佳方法的建议,而不必在每次测试之前都这样做。

非常感谢。

【问题讨论】:

    标签: ruby-on-rails sunspot sunspot-rails


    【解决方案1】:

    在我的头撞在桌子上之后,我在我的 searchs_controller_test.rb 中解决了这样的问题(其中 Item 是我正在搜索的模型):

    setup do
      Item.reindex
    end
    

    不知道这是否是最好的做事方式,但也许它会对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      相关资源
      最近更新 更多