Skip to content

Instantly share code, notes, and snippets.

@peterfication
Last active November 2, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterfication/a39ae43f21cfbe84d33f62f9c806b350 to your computer and use it in GitHub Desktop.
Save peterfication/a39ae43f21cfbe84d33f62f9c806b350 to your computer and use it in GitHub Desktop.
jobs:
build:
docker:
...
- image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
...
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
hostname: elasticsearch
ports:
- "9200:9200"
# searches_controller.rb
class SearchController < ApplicationController
def execute
data = if params[:query].blank?
[]
else
Store.search(params[:query]).map do |store|
{
id: store.id,
title: store.title,
}
end
end
render json: { data: data }
end
end
# searches_spec.rb
require 'rails_helper'
describe SearchController do
describe '#execute' do
it 'works' do
store = Store.create!(title: 'Alexa Shopping Center')
# The query is misspelled on purpose!
get '/search?query=Alxa'
expect(response).to have_http_status(200)
expect(JSON.parse(response.body)).to eq({
data: [{
id: store.id,
title: store.title,
},],
})
end
end
end
VCR.configure do |config|
  config.ignore_hosts '127.0.0.1', 'localhost', 'elasticsearch'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment