Skip to content

Instantly share code, notes, and snippets.

@barttenbrinke
Last active December 16, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barttenbrinke/5452123 to your computer and use it in GitHub Desktop.
Save barttenbrinke/5452123 to your computer and use it in GitHub Desktop.
# -*- encoding : utf-8 -*-
require 'spec_helper'
## Only run the sphinx test if we can actually run them
if sphinx_test_possible?
describe "Sphinx Integration Test" do
describe "searching for employees" do
# Note: We CANNOT use Rspec's transaction cleanup, as Sphinx will return the first indexed object ids
# We could trigger a re-index for each test, but this is unreliable as Sphinx reloads the index lazy.
# As a solution we create everthing by hand and clean everything up afterwards.
before(:all) do
sphinx_cleanup_temp_files!
@movie1=create!(:Movie)
@movie2=create!(:Movie)
sphinx_generate_xml
@movie2.title = 'UPDATED THROUGH DELTA'
@movie2.rank = 100
sphinx_appendelta_to_xml(@movie2)
sphinx_reindex
sphinx_start
end
after(:all) do
# Manual cleanup
Movie.all.map { |x| x.destroy }
sphinx_stop
sphinx_cleanup_temp_files!
end
it "should return best ranked movie" do
results = Sphinx::CustomRiddle.search('', sphinx_riddle_connection)
results[:results].should eql([@movie1, @movie2])
end
end
## End of Sphinx test check
else
p 'Skipping Sphinx integration test, because I cannot find sphinx!'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment