Created
June 5, 2011 11:04
-
-
Save thhermansen/1008868 to your computer and use it in GitHub Desktop.
Sunspot rspec helper file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Put this in spec/support/ | |
# Will use a sunspot stub session as default in all tests. | |
# | |
# To actually test the search you'll need something like: | |
# describe "something", sunspot: true do | |
# ...some tests... | |
# end | |
# | |
# If you do this in your spec helper: | |
# RSpec.configure do |config| | |
# ... | |
# config.treat_symbols_as_metadata_keys_with_true_values = true | |
# end | |
# | |
# You can drop the true in the options to describe. | |
# describe "something", sunspot do | |
# ...some tests... | |
# end | |
# Stubs search for all specs | |
Sunspot.session = Sunspot::Rails::StubSessionProxy.new(Sunspot.session) | |
# Rspec hook for enable it on selected tests | |
RSpec.configure do |config| | |
config.before :sunspot => true do | |
Sunspot.session = Sunspot.session.original_session | |
Sunspot.remove_all! | |
end | |
config.after :sunspot => true do | |
Sunspot.session = Sunspot::Rails::StubSessionProxy.new(Sunspot.session) | |
end | |
end | |
# | |
# Make sunspot index right away in test environment. | |
# | |
module Sunspot | |
module Rails | |
module Searchable | |
module InstanceMethods | |
def solr_index | |
solr_index! | |
end | |
def solr_remove_from_index | |
solr_remove_from_index! | |
end | |
end | |
end | |
end | |
end |
This is update in relation to https://github.com/CompanyBook/sunspot_massive_record/wiki/Rspec-and-Sunspot-Rails
It's not clear
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you think that - does it not work? Before it should set it to the original non-stubbed version. Afterwards it should set it back to a stubbed version to make the rest of the test go faster as we don't need to index test-data usually.
Anyway; I would probably do this different now. I'll update the gist.