Skip to content

Instantly share code, notes, and snippets.

@ches
Created July 11, 2012 11:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ches/3089879 to your computer and use it in GitHub Desktop.
Save ches/3089879 to your computer and use it in GitHub Desktop.
Some Tire setup tips for ElasticSearch
# Use a prefix for the index names that Tire uses so that the test suite doesn't
# stomp on dev data and you can work on multiple apps with ES, but keep tidy
# unadorned names for production.
unless Rails.env.production?
Tire::Model::Search.index_prefix("#{Rails.application.class.parent_name.downcase}_#{Rails.env}")
end
RSpec.configure do |config|
# You may need a different approach for a different data store, using
# Tire's persistence mixin to use ElasticSearch as an ORM, etc.
ES_INDEXED_MODELS = ActiveRecord::Base.descendants.select do |klass|
klass.respond_to? :tire
end
config.before(:suite) do
ES_INDEXED_MODELS.each do |klass|
klass.tire.index.delete
klass.create_elasticsearch_index
end
end
# Here's an idea for using memory store for indexes in test env if this proves
# to be appreciably slow:
#
# http://bitsandbit.es/post/11295134047/unit-testing-with-tire-and-elastic-search
config.before(elasticsearch: true) do
ES_INDEXED_MODELS.each do |klass|
klass.tire.index.delete
klass.create_elasticsearch_index
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment