Last active
November 2, 2018 14:56
-
-
Save peterfication/a39ae43f21cfbe84d33f62f9c806b350 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobs: | |
build: | |
docker: | |
... | |
- image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
elasticsearch: | |
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2 | |
hostname: elasticsearch | |
ports: | |
- "9200:9200" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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