circleciを使用してgithubでプロジェクトを構成しました。弾性検索にsearchkickを使用しています。インデックスを再作成するコードは次のようになります。
IN spec_helper.rb
RSpec.configure do |config|
....
config.before :each do
Location.reindex
end
...
end
私の app/models/location.rb は次のようになります
class Location < ActiveRecord::Base
...
searchkick word_start: [:location_name], autocomplete: [:location_name]
...
end
私の app/models/search.rb は次のようになります
class Search < ActiveRecord::Base
...
def self.location_auto_complete(search_term)
location_ids = Organization.locations.map(&:id)
Location.search(search_term, fields: [{location_name: :word_start}, :from, :search_id], where: {id: location_ids})
end
end
私の /spec/models/search_spec.rb は次のようになります
require 'rails_helper'
describe Search, type: :model do
before :each do
@location = create(:location,location_name: 'kathmandu')
@location.reindex
Location.searchkick_index.refresh
end
describe '.location_auto_complete(search_term)' do
it 'return location search result for the location search term' do
expect(Search.location_auto_complete('kathmandu')).to match_array(@location)
end
終わり
私の /myapp/config/circle.yml は次のようになります: https://circleci.com/docs/installing-elasticsearch :
database:
override:
# replace CircleCI's generated database.yml
- cp config/database.yml.ci config/database.yml
- bundle exec rake db:drop db:create db:migrate
machine:
services:
- elasticsearch
dependencies:
post:
- wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz
- tar -xvf elasticsearch-1.0.1.tar.gz
- elasticsearch-1.0.1/bin/elasticsearch: {background: true}
dependencies:
cache_directories:
- elasticsearch-1.0.1 # relative to the build directory
post:
- if [[ ! -e elasticsearch-1.0.1 ]]; then wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz && tar -xvf elasticsearch-1.0.1.tar.gz; fi
- elasticsearch-1.0.1/bin/elasticsearch: {background: true}
ラップトップで rspec を実行すると、github (circleci と統合されている) にプッシュしている間は正常に動作し、ステータスが失敗します。また、次のようにも述べています。
We didn't find a circle.yml for this build. You can specify deployment or override our inferred test steps from a circle.yml checked in to your repo's root directory.More information in our docs.