Using Elasticsearch with RSpec and Factorygirl
I have this setup working. I think you are just missing a call to Model.import to import the records into elasticsearch. You also need to make sure any factory creates happen in a let! block, not within your test so that the import will pick up those new records. Try something like this:
display_controller_spec.rb:
context "elasticsearch tests" do let!(:display) { FactoryGirl.create(:display, client: @client) } it "will return a list of displays", :elasticsearch do get :index, { :format => :json }, { "Accept" => "application/json" } # returns Status: 200 OK expect(response.status).to eq 200 json = JSON.parse(response.body) expect(json.count).to be > 0 endend
spec_helper.rb:
RSpec.configure do |config| ... ES_CLASSES = [Event, Interaction, Perch] config.before :all do ES_CLASSES.each do |esc| esc.__elasticsearch__.client.indices.create( index: esc.index_name, body: { settings: esc.settings.to_hash, mappings: esc.mappings.to_hash } ) end end config.after :all do ES_CLASSES.each do |esc| esc.__elasticsearch__.client.indices.delete index: esc.index_name end end config.before(:each, elasticsearch: true) do ES_CLASSES.each { |esc| esc.import(refresh: true, force: true) } endend