8000 Refactor test to use SearchBuilder by jcoyne · Pull Request #3631 · projectblacklight/blacklight · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor test to use SearchBuilder #3631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SearchBuilder
attr_reader :processor_chain, :search_state, :blacklight_params

# @overload initialize(scope)
# @param [Object] scope scope the scope where the filter methods reside in.
# @param [Object] scope the scope where the filter methods reside in.
# @overload initialize(processor_chain, scope)
# @param [List<Symbol>,TrueClass] processor_chain options a list of filter methods to run or true, to use the default methods
# @param [Object] scope the scope where the filter methods reside in.
Expand Down
13 changes: 8 additions & 5 deletions spec/models/blacklight/solr/response/group_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

RSpec.describe Blacklight::Solr::Response::GroupResponse, :api do
let(:response) do
create_response(sample_response)
Blacklight::Solr::Response.new(sample_response, search_builder)
end

let(:search_builder) do
Blacklight::SearchBuilder.new(view_context).tap { |b| b.rows = 3 }
end
let(:view_context) do
double("View context", blacklight_config: CatalogController.blacklight_config.deep_copy)
end

let(:group) do
Expand Down Expand Up @@ -82,10 +89,6 @@
end
end

def create_response(response, params = {})
Blacklight::Solr::Response.new(response, params)
end

def sample_response
{ "responseHeader" => { "params" => { "rows" => 3, "group.limit" => 5 } },
"grouped" =>
Expand Down
8 changes: 3 additions & 5 deletions spec/models/blacklight/solr/response/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
group.groups.first
end

let(:search_builder) { {} }

let(:response) do
create_response(sample_response)
Blacklight::Solr::Response.new(sample_response, search_builder)
end

let(:group) do
Expand Down Expand Up @@ -51,10 +53,6 @@
end
end

def create_response(response, params = {})
Blacklight::Solr::Response.new(response, params)
end

def sample_response
{ "responseHeader" => { "params" => { "rows" => 3, "group.limit" => 5 } },
"grouped" =>
Expand Down
9 changes: 6 additions & 3 deletions spec/views/catalog/index.atom.builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
end

let(:blacklight_config) { CatalogController.blacklight_config.deep_copy }
let(:search_builder) { Blacklight::SearchBuilder.new(view) }
let(:response) { Blacklight::Solr::Response.new({ response: { numFound: 30 } }, search_builder) }

before do
@response = Blacklight::Solr::Response.new({ response: { numFound: 30 } }, start: 10, rows: 10)
allow(view).to receive_messages(action_name: 'index', blacklight_config: blacklight_config)
@response = response
allow(controller).to receive(:search_state_class).and_return(Blacklight::SearchState)
allow(@response).to receive(:documents).and_return(document_list)
allow(search_builder).to receive_messages(start: 10, rows: 10)
allow(response).to receive(:documents).and_return(document_list)
params['content_format'] = 'some_format'
allow(view).to receive_messages(action_name: 'index', blacklight_config: blacklight_config)
end

# We need to use rexml to test certain things that have_tag wont' test
Expand Down
4 changes: 3 additions & 1 deletion spec/views/catalog/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
before do
stub_template "catalog/_results_pagination.html.erb" => ""
allow(view).to receive_messages(has_search_parameters?: true, blacklight_config: Blacklight::Configuration.new)
allow(search_builder).to receive_messages(start: 10, rows: 10)
allow(controller).to receive_messages(blacklight_config: Blacklight::Configuration.new)

@response = response
end

let(:response) { Blacklight::Solr::Response.new({ response: { numFound: 30 } }, start: 10, rows: 10) }
let(:search_builder) { Blacklight::SearchBuilder.new(view) }
let(:response) { Blacklight::Solr::Response.new({ response: { numFound: 30 } }, search_builder) }

it "renders the search_header partial" do
render
Expand Down
0