Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashayh/3921996 to your computer and use it in GitHub Desktop.
Save ashayh/3921996 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