Skip to content

Commit

Permalink
configured search_state_class propagates to search builder
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed May 18, 2022
1 parent 59f0811 commit 7f28620
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/services/blacklight/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def search_builder
search_builder_class.new(self)
end

def search_state_class
@search_state.class
end

# a solr query method
# @yield [search_builder] optional block yields configured SearchBuilder, caller can modify or create new SearchBuilder to be used. Block should return SearchBuilder to be used.
# @return [Blacklight::Solr::Response] the solr response object
Expand Down
3 changes: 2 additions & 1 deletion lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def initialize(*options)
end

@blacklight_params = {}
@search_state = Blacklight::SearchState.new(@blacklight_params, @scope&.blacklight_config, @scope)
search_state_class = @scope&.search_state_class || Blacklight::SearchState
@search_state = search_state_class.new(@blacklight_params, @scope&.blacklight_config, @scope)
@additional_filters = {}
@merged_params = {}
@reverse_merged_params = {}
Expand Down
11 changes: 10 additions & 1 deletion spec/models/blacklight/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

let(:processor_chain) { [] }
let(:blacklight_config) { Blacklight::Configuration.new }
let(:scope) { double blacklight_config: blacklight_config }
let(:scope) { double blacklight_config: blacklight_config, search_state_class: nil }

context "with default processor chain" do
subject { described_class.new scope }
Expand All @@ -15,6 +15,15 @@
end
end

context "with scope search_state_class" do
let(:state_class) { Class.new(Blacklight::SearchState) }
let(:scope) { double blacklight_config: blacklight_config, search_state_class: state_class }

it "uses the class-level default_processor_chain" do
expect(subject.search_state).to be_a state_class
end
end

describe "#with" do
it "sets the blacklight params" do
params = {}
Expand Down

0 comments on commit 7f28620

Please sign in to comment.