I was wondering how you were testing the search in your application when using ElasticSearch and Tire.
-
How do you setup a new ElasticSearch test instance? Is there a way to mock it?
-
Any gems you know of that might help with that?
Some stuff I found helpful:
I found a great article answering pretty much all my questions 🙂
http://bitsandbit.es/post/11295134047/unit-testing-with-tire-and-elastic-search#disqus_thread
Plus, there is an answer from Karmi, Tire author.
This is useful as well: https://github.com/karmi/tire/wiki/Integration-Testing-Rails-Models-with-Tire
I can’t believe I did not find these before asking…
Prefixing your index-names for the current environment
You could set a different index-name for each environment (in your case: the test environment).
For example, you could create an initializer in
with the following line:
A conceivable approach for deleting the indexes
Assuming that you have models named Customer, Order and Product, put the following code somewhere at your test-startup/before-block/each-run-block.
Alternative
An alternative could be to set up a different ElasticSearch instance for testing on another port, let’s say 1234.
In your enviornment/test.rb you could then set
And at a suitable location (e.g. your testing startup) you can then delete all indexes on the ElasticSearch testing-instance with:
Maybe you must still make sure that your Tire-Mapping definitions for you model classes are still getting called.