Searchkick在Travis CI上失败

伊雷塔塔

我刚刚将Searchkick集成到我的Rails 4.1应用程序中,而Travis CI构建失败了。我通过在.travis.yml中添加elasticsearch服务解决了第一个失败,但是必须通过Rails控制台完成“重新索引”模型的命令,这是失败的原因:

Failure/Error: Unable to find matching line from backtrace
     RuntimeError:
       Index missing - run Item.reindex

那么,如何通过在Travis CI中发布“ Model.reindex”来为模型建立索引?

这是我的.travis.yml文件:

language: ruby
rvm:
  - 2.0.0-p247
env:
  - DB=sqlite
  - DB=mysql
  - DB=postgresql
services:
  - elasticsearch
script:
  - RAILS_ENV=test bundle exec rake db:migrate --trace
  - bundle exec rake db:test:prepare
  - bundle exec rspec spec/
before_script:
  - mysql -e 'create database mbb_test'
  - psql -c 'create database mbb_test;' -U postgres
bundler_args: --binstubs=./bundler_stubs
伊雷塔塔

原来,我只需要将此添加到我的测试帮助器(在我的情况下为spec_helper.rb),以便该项在每次测试时都得到“重新索引”编辑:

config.before(:each) do
  Item.reindex
end

一个更好的版本

config.before(:each, es: true) do
    if Item.searchkick_index.exists?
      Item.searchkick_index.delete
      Item.reindex
    end
  end

摘自:https : //github.com/ankane/searchkick/pull/95

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章