Samuel-Zacharie Faure
Samuel-Zacharie Faure

Reputation: 1152

Sunspot reindexing during tests erase development indexing

I'm working on a search API which uses Sunspot for indexing and Rspec for testing.

I have a test for my search controller :

  context 'when doing a simple search', :type => :request do
    let!(:instance_of_my_model) { create(:instance_of_my_model) }
    it 'return the correct results' do
      MyModel.reindex

     # some test code with a GET request
    end
  end

For running tests, I start by lauching the solr server :

rake sunspot:solr:start RAILS_ENV=test

After running my test, I stop the solr server and run it back again in development environnement. The search don't work anymore.

It works again if I reindex :

rake sunspot:reindex

(~1 hour since I have 10M+ entries)

Why is this happening ?

For information, my /config/sunspot.yml :

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING

Upvotes: 0

Views: 193

Answers (1)

Samuel-Zacharie Faure
Samuel-Zacharie Faure

Reputation: 1152

After some searching, this answer : Reindex on sunspot rails tipped me of.

My sunspot.yml should have been :

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO
    path: /solr/development


test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING
    path: /solr/test

Upvotes: 1

Related Questions