Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:46:29+00:00 2026-05-31T08:46:29+00:00

I was wondering how you were testing the search in your application when using

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:46:31+00:00Added an answer on May 31, 2026 at 8:46 am

    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

    config/initializers/tire.rb
    

    with the following line:

    Tire::Model::Search.index_prefix "#{Rails.application.class.parent_name.downcase}_#{Rails.env.to_s.downcase}"
    

    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.

    # iterate over the model types
    # there are also ways to fetch all model classes of the rails app automaticly, e.g.:
    #   http://stackoverflow.com/questions/516579/is-there-a-way-to-get-a-collection-of-all-the-models-in-your-rails-app
    [Customer, Order, Product].each do |klass|
    
      # make sure that the current model is using tire
      if klass.respond_to? :tire
        # delete the index for the current model
        klass.tire.index.delete
    
        # the mapping definition must get executed again. for that, we reload the model class.
        load File.expand_path("../../app/models/#{klass.name.downcase}.rb", __FILE__)
    
      end
    end
    

    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

    Tire::Configuration.url "http://localhost:1234"
    

    And at a suitable location (e.g. your testing startup) you can then delete all indexes on the ElasticSearch testing-instance with:

    Tire::Configuration.client.delete(Tire::Configuration.url)
    

    Maybe you must still make sure that your Tire-Mapping definitions for you model classes are still getting called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am load testing a web application and wondering if there is a way
I'm wondering is there any way to automate testing of Flex applications using HP
I think I understand unit testing. But I was wondering: is there a way
HI there I was wondering if there is a better way of testing that
I'm wondering what the best practices are in Test Driven Development / testing using
Trying to create a unit test (borderline integration testing) using ThreadFactory, and just wondering
I have a simple web application testing desktop application. I am wondering how I
I keep wondering what are Contexts when it comes to Unit testing. There seem
I'm jumping into unit-testing the Visual-Studio 2008 way, and I'm wondering what's the best
I'm wondering what are the strengths and weaknesses of using JUnit for code testing?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.