Search code examples
rspecthinking-sphinx

Thinking Sphinx 3.0.1 how to turn off Delta indexes when testing with Rspec


I have Delta indexing turned on by default for all my Models:

ThinkingSphinx::Index.define :book, :with => :active_record, :delta => (::Padrino.env == :production ? ThinkingSphinx::Deltas::SidekiqDelta : true) do

I'd like to turn delta indexing off when running Rspec (since it takes longer for the tests to run and I also get an error that the delta.spl file cannot be accessed: FATAL: failed to open db/sphinx/test/book_delta.spl: No such file or directory, will not index. Try --rotate option.)

I've tried to set it to false in the spec/support/sphinx.rb file as it says in the TS docs:

config.before(:suite) do
    ThinkingSphinx::Test.init, suppress_delta_output: false
    ThinkingSphinx.deltas_enabled  = false # try to turn delta indexing off for the Controller and Model tests   
  end

But the delta indexes are still being done for every test that inserts new data, even for data inserted with a Factory Girl factory.

Putting this line: ThinkingSphinx.deltas_enabled = false into any of my specs results in a missing method error: : undefined methoddeltas_enabled=' for ThinkingSphinx:Module`

How can I turn it off?


Solution

  • The ThinkingSphinx.deltas_enabled setting is for Thinking Sphinx v1/v2.

    With Thinking Sphinx v3 (and I highly recommend updating to the latest, 3.0.3), you can do it with this command instead:

    ThinkingSphinx::Deltas.suspend!
    

    If at some point you want to switch them back on, there's a resume! method as well.