Skip to content

Commit

Permalink
Finish test setup and sent desired search_builder_class
Browse files Browse the repository at this point in the history
Co-authored-by: Carolyn Cole <carolyncole@users.noreply.github.com>
Co-authored-by: James R. Griffin III <jrgriffiniii@users.noreply.github.com>
Co-authored-by: Eliot Jordan <eliotjordan@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 7, 2023
1 parent 31bb7ad commit 88396a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ def basic_response
end

def search_service_context
return {} unless Flipflop.multi_algorithm?
return {} unless params[:search_algorithm] == "alternate"
{ search_builder_class: AlternateSearchBuilder }
end
end
34 changes: 12 additions & 22 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,22 @@
end
end
end

describe "switching search algorithms" do
let(:repository) { CatalogController.blacklight_config.repository }

before do
allow(repository).to receive(:search).and_call_original
allow_any_instance_of(Blacklight::Configuration).to receive(:repository).and_return(repository)
end

context "when the multi-algorithm feature is on" do
before do
allow(Flipflop).to receive(:multi_algorithm?).and_return(true)
end

context "when the search_algorithm parameter is not present" do
it "uses the default search builder" do
# We want to make sure that the repository (in
# controller.blacklight_config.repository) receives search with an
# instance of SearchBuilder.
repository = CatalogController.blacklight_config.repository
allow(repository).to receive(:search).and_call_original
allow_any_instance_of(Blacklight::Configuration).to receive(:repository).and_return(repository)
get :index, params: { q: "coffee" }

expect(repository).to have_received(:search).with(instance_of(SearchBuilder))
Expand All @@ -139,13 +141,9 @@

context "when the search_algorithm parameter is set to 'alternate'" do
it "uses the alternate search builder" do
allow(SearchBuilder).to receive(:new).and_call_original
allow(AlternateSearchBuilder).to receive(:new).and_call_original

get :index, params: { q: "coffee", search_algorithm: "alternate" }

expect(AlternateSearchBuilder).to have_received(:new)
expect(SearchBuilder).not_to have_received(:new)
expect(repository).to have_received(:search).with(instance_of(AlternateSearchBuilder))
end
end
end
Expand All @@ -157,25 +155,17 @@

context "when the search_algorithm parameter is not present" do
it "uses the default search builder" do
allow(SearchBuilder).to receive(:new).and_call_original
allow(AlternateSearchBuilder).to receive(:new).and_call_original

get :index, params: { q: "coffee" }

expect(SearchBuilder).to have_received(:new)
expect(AlternateSearchBuilder).not_to have_received(:new)
expect(repository).to have_received(:search).with(instance_of(SearchBuilder))
end
end

context "when the search_algorithm parameter is set to alternate" do
it "uses the alternate search builder" do
allow(SearchBuilder).to receive(:new).and_call_original
allow(AlternateSearchBuilder).to receive(:new).and_call_original

get :index, params: { q: "coffee" }
get :index, params: { q: "coffee", search_algorithm: "alternate" }

expect(SearchBuilder).to have_received(:new)
expect(AlternateSearchBuilder).not_to have_received(:new)
expect(repository).to have_received(:search).with(instance_of(SearchBuilder))
end
end
end
Expand Down

0 comments on commit 88396a9

Please sign in to comment.