I just integrated Searchkick on my Rails 4.1 app and my Travis CI build just failed. I solved the first failure by adding the elasticsearch service in my .travis.yml, but the command to "reindex" the model has to be done via a Rails console, and that is the failure with:
Failure/Error: Unable to find matching line from backtrace
RuntimeError:
Index missing - run Item.reindex
So how do I index a model by issuing the "Model.reindex" in Travis CI?
Here is my .travis.yml file:
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
turns out I just had to add this to my test helper (in my case spec_helper.rb) so that the Item gets "reindex"-ed every test:
config.before(:each) do
Item.reindex
end
A BETTER VERSION
config.before(:each, es: true) do
if Item.searchkick_index.exists?
Item.searchkick_index.delete
Item.reindex
end
end
taken from: https://github.com/ankane/searchkick/pull/95