我正在开发一个搜索API,它使用Sunspot进行索引,使用Rspec进行测试。
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
为了运行测试,我首先启动solr服务器:
rake sunspot:solr:start RAILS_ENV=test
运行测试后,我停止solr服务器,并在开发环境中再次运行它。搜索不再有效。
如果我重新索引,它会再次工作:
rake sunspot:reindex
(自从我有1000多万个条目以来,大约有1个小时)
有关信息,请参阅my/config/sunspot。yml:
development:
solr:
hostname: localhost
port: 8982
log_level: INFO
test:
solr:
hostname: localhost
port: 8981
log_level: WARNING