kidpollo / tanker

IndexTank Integration with your fav ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to disable update/delete indexes in test environment

zsxking opened this issue · comments

Is there a way to disable the update/delete indexes in test environment?
In my case I have many models with:
after_save :update_tank_indexes
after_destroy :delete_tank_indexes
Then each time a test object created, the update_tank_indexes will be called. This make the tests run very slow, and also break the test when I don't have Internet connection. It will be nice to be able to disable tanker's indexes update, and be able to enable it on per test case basis.

Couldnt you do something like

after_save :update_tank_indexes :if => 'Rails.env == "production"'

Yes, but it's a good point, I don't want to create index during my tests either.

Webmock is a pretty nice way to stub out http requests when doing tests, with it enabled ruby won't do the actual remote request but instead get a predefined response.

We have been using something like this for a few projects using tanker:

  stub_request(:put, /api.indextank.com/).to_return(:status => 200)

  stub_request(:delete, /api.indextank.com/).to_return(:status => 200)

Thanks @arvida I do think that disabling index tank on test environment go e beyod what the gem should do so I am closing this issue

Thanks for this technique. Since I want to play with searching in all environments but test, I inverted the condition. Also note that the statement requires a comma before the :if or :unless.
after_save :update_tank_indexes, :unless => 'Rails.env == "test"'