cbeer / solr_wrapper

Wrap your tests with Solr 5+
MIT License
23 stars 20 forks source link

rake tasks do not respect .solr_wrapper file #127

Open jrochkind opened 5 years ago

jrochkind commented 5 years ago

I have a .solr_wrapper file that specifies solr version 6.3.0.

If I run bundle exec solr_wrapper, as expected I get:

Starting Solr 6.3.0 on port 8983 ..

However, if I use the solr_wrapper rake tasks, (require 'solr_wrapper/rake_task'), and run bundle exec solr:start, it seems to ignore the .solr_wrapper file, I get:

Starting solr at http://127.0.0.1:8983/solr/
solr-8.0.0.zip: |================                               | 70% ( ETA: 00:00:06 )

Is this a bug, should the rake task be using the .solr_wrapper config file too?

If so, I am happy to prepare and submit a PR, feedback welcome.

jrochkind commented 5 years ago

bundle exec solr_wrapper with no args ends up calling SolrWrapper.instance({}) to get an instance to call #start on. This does pick up your .solr_wrapper.

The rake tasks instead of doing SolrWrapper.instance, use SolrWrapper.default_instance. Which does not seem to pick up .solr_config.

I guess I can write my own local rake tasks that use SolrWrapper.instance({}) instead.

But I'm happy to give back to solr_wrapper if this is a bug or desired improvement? It may be that few users are actually using the rake tasks; if you were, I think you'd want them to pick up your .solr_wrapper, no?

I have confirmed that if I simply change @solr_instance = SolrWrapper.default_instance in the rake file to @solr_instance = SolrWrapper.instance({}), it does what I expect.

jrochkind commented 5 years ago

Putting this in your Rakefile is one workaround:

SolrWrapper.default_instance_options = YAML.load(ERB.new(IO.read("./.solr_wrapper")).result(binding))

It seems like there should be an easier and more obvious, documented and/or default solution.

The logic for default config file paths and ERB processing are locked in Solr::Configuration, and you can not currently do SolrWrapper.default_instance_options = Solr::Configuration.new, nor does Solr::Configuration have a #to_h.

jrochkind commented 5 years ago

Aha, here's a less ugly workaround:

SolrWrapper.default_instance_options = SolrWrapper::Configuration.new.options

(looks like #options is effectively the #to_h I was looking for)

jrochkind commented 5 years ago

Perhaps the default default_instance_options should actually be SolrWrapper::Configuration.new.options?

jrochkind commented 5 years ago

It's worth noting that even if you do SolrWrapper.default_instance_options = SolrWrapper::Configuration.new.options, the rake tasks will not create a collection/core you've specified in your .solr_wrapper config file, like bundle exec solr_wrapper will.