Forked from ches/config-initializers-elasticsearch.rb
Created
October 20, 2012 04:23
-
-
Save ashayh/3921996 to your computer and use it in GitHub Desktop.
Some Tire setup tips for ElasticSearch
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
# 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 |
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
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