I have a class method in a model that calls thinking_sphinx's search() method. I need to check this class method.
I want to start, index or stop sphinx in my rspec test cases. I am trying with this piece of code.
before(:all) do
ThinkingSphinx::Test.start
end
after(:all) do
ThinkingSphinx::Test.stop
end
and with this code in each test case before I fire the search query
ThinkingSphinx::Test.index
but still after I fire the search query, it gives me empty results though exact matches are there in the test db.
Please guide me with code examples if you are using rspec with thinking_sphinx
This is due to transactional fixtures.
While ActiveRecord can run all its operations within a single transaction, Sphinx doesn’t have access to that, and so indexing will not include your transaction’s changes.
You have to disable your transactional fixtures.
In your rspec_helper.rb put
to disable globally.
See Turn off transactional fixtures for one spec with RSpec 2
Following David post, we end up with following solution:
It switch specified tables to :truncation strategy, and after that switch them back to :trasaction strategy.