Created
August 5, 2014 16:53
-
-
Save chrisbloom7/93c91c47a605c040680c to your computer and use it in GitHub Desktop.
Setup acts_as_indexed for Rails testing (Tested on Rails 2.3 with TestUnit)
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
# config/initializers/acts_as_indexed.rb | |
ActsAsIndexed.configure do |config| | |
# Disable acts_as_indexed auto indexing in test by default | |
config.disable_auto_indexing = Rails.env.test? | |
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
# test/integration/search_test.rb | |
require 'test_helper' | |
class SearchTest < ActionController::IntegrationTest | |
setup do | |
@old_product_auto_index = Product.aai_config.disable_auto_indexing | |
@old_product_review_auto_index = ProductReview.aai_config.disable_auto_indexing | |
@old_display_category_auto_index = DisplayCategory.aai_config.disable_auto_indexing | |
@old_page_auto_index = Page.aai_config.disable_auto_indexing | |
# Force acts_as_indexed auto indexing for searchable models | |
Product.aai_config.disable_auto_indexing = false | |
ProductReview.aai_config.disable_auto_indexing = false | |
DisplayCategory.aai_config.disable_auto_indexing = false | |
Page.aai_config.disable_auto_indexing = false | |
end | |
teardown do | |
# Reset acts_as_indexed auto indexing for searchable models | |
Product.aai_config.disable_auto_indexing = @old_product_auto_index | |
ProductReview.aai_config.disable_auto_indexing = @old_product_review_auto_index | |
DisplayCategory.aai_config.disable_auto_indexing = @old_display_category_auto_index | |
Page.aai_config.disable_auto_indexing = @old_page_auto_index | |
# Cleanup index files | |
FileUtils.rm_rf Dir.glob ActsAsIndexed.configuration.index_file.join(Rails.env, '*') | |
end | |
# your tests | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment