Martin Streicher <martin.streicher at gmail.com> writes:
> I would like to use rspec to test a model that leverages
> acts_as_solr. I think I want to render rebuild_solr_index and
> solr_commit and perhaps other methods that call out to the Solr
> server moot by having those functions simply return true. (I will
> build other tests to make sure my Solr configuration
> works properly.)
>
> Can anyone make suggestions on how to best approach this? Shall I just
> open the class and redefine certain methods? Or is there a way for me
> to disable Solr for all classes while running rspec?
Solr lets you disable stuff pretty easily. In our system, Recipe and
User are both AAS. We throw this in our spec_helper.rb:
Spec::Runner.configuration.before do
Recipe.configuration[:if] = false
User.configuration[:if] = false
end
def with_solr
Recipe.configuration[:if] = ''true''
User.configuration[:if] = ''true''
yield
Recipe.configuration[:if] = false
User.configuration[:if] = false
end
All of our specs will run with solr disabled, and if you want solr on to
test it you can do
with_solr do
create_user
end
Instead of listing the classes explicitly, you could iterate over all of
the AR::Base subclasses and see which ones are AAS and turn them on/off
automatically.
Pat