From 95ee46fa87474995b3a0c792cf6c1079b15c80dc Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Thu, 27 Aug 2015 16:39:31 -0400 Subject: [PATCH] SearchHelper#search_results takes optional block Used to configure or replace the SearchBuilder --- lib/blacklight/search_helper.rb | 6 +++++- spec/lib/blacklight/search_helper_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/blacklight/search_helper.rb b/lib/blacklight/search_helper.rb index b88625931f..28257b24bb 100644 --- a/lib/blacklight/search_helper.rb +++ b/lib/blacklight/search_helper.rb @@ -94,14 +94,18 @@ def get_search_results(user_params = params || {}, extra_controller_params = {}) # a solr query method # @param [Hash,HashWithIndifferentAccess] user_params ({}) the user provided parameters (e.g. query, facets, sort, etc) - # @param [Hash,HashWithIndifferentAccess] extra_controller_params ({}) extra parameters to add to the search # @param [List{'docs'=>[]}}) + + replacement_search_builder = subject.search_builder([:new_chain]) + + # Sorry, have to use mocks to make sure method really passes the + # block return value to the repository search, couldn't figure + # out a better way to test. + expect(subject.repository).to receive(:search) do |arg_search_builder| + expect(arg_search_builder).to equal(replacement_search_builder) + end + + subject.search_results({q: @no_docs_query}, [:one, :two]) do |arg_search_builder| + expect(arg_search_builder.processor_chain).to eq([:one, :two]) + + replacement_search_builder + end + end + end + describe "#get_search_results " do it "should be deprecated and return results" do expect(Deprecation).to receive(:warn)