Skip to content

Commit de5ddbb

Browse files
authored
Merge pull request #3631 from projectblacklight/refactor-tests
Refactor test to use SearchBuilder
2 parents a958f88 + d0f7d47 commit de5ddbb

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

lib/blacklight/search_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SearchBuilder
1212
attr_reader :processor_chain, :search_state, :blacklight_params
1313

1414
# @overload initialize(scope)
15-
# @param [Object] scope scope the scope where the filter methods reside in.
15+
# @param [Object] scope the scope where the filter methods reside in.
1616
# @overload initialize(processor_chain, scope)
1717
# @param [List<Symbol>,TrueClass] processor_chain options a list of filter methods to run or true, to use the default methods
1818
# @param [Object] scope the scope where the filter methods reside in.

spec/models/blacklight/solr/response/group_response_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
RSpec.describe Blacklight::Solr::Response::GroupResponse, :api do
66
let(:response) do
7-
create_response(sample_response)
7+
Blacklight::Solr::Response.new(sample_response, search_builder)
8+
end
9+
10+
let(:search_builder) do
11+
Blacklight::SearchBuilder.new(view_context).tap { |b| b.rows = 3 }
12+
end
13+
let(:view_context) do
14+
double("View context", blacklight_config: CatalogController.blacklight_config.deep_copy)
815
end
916

1017
let(:group) do
@@ -82,10 +89,6 @@
8289
end
8390
end
8491

85-
def create_response(response, params = {})
86-
Blacklight::Solr::Response.new(response, params)
87-
end
88-
8992
def sample_response
9093
{ "responseHeader" => { "params" => { "rows" => 3, "group.limit" => 5 } },
9194
"grouped" =>

spec/models/blacklight/solr/response/group_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
group.groups.first
88
end
99

10+
let(:search_builder) { {} }
11+
1012
let(:response) do
11-
create_response(sample_response)
13+
Blacklight::Solr::Response.new(sample_response, search_builder)
1214
end
1315

1416
let(:group) do
@@ -51,10 +53,6 @@
5153
end
5254
end
5355

54-
def create_response(response, params = {})
55-
Blacklight::Solr::Response.new(response, params)
56-
end
57-
5856
def sample_response
5957
{ "responseHeader" => { "params" => { "rows" => 3, "group.limit" => 5 } },
6058
"grouped" =>

spec/views/catalog/index.atom.builder_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
end
1515

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

1820
before do
19-
@response = Blacklight::Solr::Response.new({ response: { numFound: 30 } }, start: 10, rows: 10)
21+
allow(view).to receive_messages(action_name: 'index', blacklight_config: blacklight_config)
22+
@response = response
2023
allow(controller).to receive(:search_state_class).and_return(Blacklight::SearchState)
21-
allow(@response).to receive(:documents).and_return(document_list)
24+
allow(search_builder).to receive_messages(start: 10, rows: 10)
25+
allow(response).to receive(:documents).and_return(document_list)
2226
params['content_format'] = 'some_format'
23-
allow(view).to receive_messages(action_name: 'index', blacklight_config: blacklight_config)
2427
end
2528

2629
# We need to use rexml to test certain things that have_tag wont' test

spec/views/catalog/index.html.erb_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
before do
2121
stub_template "catalog/_results_pagination.html.erb" => ""
2222
allow(view).to receive_messages(has_search_parameters?: true, blacklight_config: Blacklight::Configuration.new)
23+
allow(search_builder).to receive_messages(start: 10, rows: 10)
2324
allow(controller).to receive_messages(blacklight_config: Blacklight::Configuration.new)
2425

2526
@response = response
2627
end
2728

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

3032
it "renders the search_header partial" do
3133
render

0 commit comments

Comments
 (0)