Jam*_*ard 3 ruby-on-rails sunspot sunspot-rails
我有一个使用Sunspot和Solr进行搜索功能的rails应用程序.我正在编写功能测试(使用Rails自己的测试套件)来验证当我用params中的搜索词调用我的搜索控制器时,返回正确的记录.
目前我有:
test "should_return_some_records" do
get :index, :term => "search term here"
assert_response :success
assert more stuff ...
end
Run Code Online (Sandbox Code Playgroud)
当我运行rake test:functionals时,这个测试用"ActionView :: Template :: Error"炸弹,因为Sunspot已从其搜索块返回一个空结果数组.
如果我rake sunspot:reindex在search_controller_test的setup方法中运行,则测试通过.但是,这意味着它也会对该文件中的每个测试执行操作,这会使事情变得非常缓慢.
有人可以给我一些关于在我的测试环境中使用Sunspot索引我的灯具的最佳方法,而不必在每次测试之前这样做.
非常感谢提前.
在桌子上敲了敲我的头后,我在search_controller_test.rb中解决了我的问题(其中Item是我正在搜索的模型):
setup do
Item.reindex
end
Run Code Online (Sandbox Code Playgroud)
不知道这是否是最好的做事方式,但也许它会帮助别人.
| 归档时间: |
|
| 查看次数: |
468 次 |
| 最近记录: |