Closed jianbo closed 11 years ago
That is odd. Are you overwriting Sunspot.session
in your test environment at all?
Hi, All I did was following, works fine in dev. Is there any config I need to do for Rspec test? Thanks
Rspec: https://gist.github.com/jianbo/6289664
Sunspot.yml test: solr: hostname: localhost port: 8981 log_level: WARNING auto_commit_after_request: true
Sunspot.rb require "sunspot/queue/sidekiq" backend = Sunspot::Queue::Sidekiq::Backend.new Sunspot.session = Sunspot::Queue::SessionProxy.new(Sunspot.session, backend)
@jianbo two questions:
sunspot.rb
in config/initializers/
?:search => true
, what definitions do you have around that (e.g. before
, after
, etc...)Hi, The sunspot.rb is in my initializers. I copied search => true form http://stackoverflow.com/questions/6989024/how-can-i-write-a-request-spec-with-capybara-rspec-for-testing-sunspot-solr-sear, and it doesn't have any effect before any after adding that, I also restarted solr for test env.
Thanks
@jianbo I'm guessing you're using sunspot_test
that provides the tag for :search => true
. It looks like the issue is on this line where sunspot_test is overriding Sunspot.session
.
I'm not sure a good way to fix this because of how sunspot_test
injects itself into testing. The below code (put in the right place in spec/spec_helper.rb
might work but I have no idea.
before(:each, :search => true) do
backend = Sunspot::Queue::Sidekiq::Backend.new
Sunspot.session = Sunspot::Queue::SessionProxy.new(Sunspot.session, backend)
end
It looks like it's a strange interaction between sunspot_test
(which hasn't been updated in 2 years) and sunspot_queue. Based on what I've seen I don't think this is an issue in sunspot_test itself.
Hi, sorry I didn't make it clear. The reindex didn not work before adding sunspot_test and "search => true", I only added now to see if it make any difference.
Hey @jianbo, so based on the little information I have it sounds like it's working fine in development but you're having issues in test mode. Based on that I don't think it's an issue with sunspot-queue and likely something to do with how your test environment is set up.
I would take a look at what is returned by Sunspot.session
right before calling Toon.reindex
in your test. If it's not an instance of Sunspot::Queue::SessionProxy
then something in overwriting our proxy. The only other thing I can think of is that you have might Sidekiq set to run jobs inline, so they would get run immediately and not queued up like in development mode.
If you can track down the issue I'd love to hear what you found, especially if it's an issue inside sunspot-queue that we can fix for everyone else.
Its because of this line in my spec_helper.rb :) require 'sidekiq/testing' # pushes jobs to array called jobs rather than redis
Hi
I am doing a request rspec test, in my before all block I created all the testing data. In my "it" block I did "MyClass.reindex", and from the redis monitor I can see nothing happened. Works fine in development.
Any idea?
Thanks