blacklight 9.2.1 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.github/matrix.json +4 -4
  3. data/.github/workflows/build.yml +3 -0
  4. data/.github/workflows/lint.yml +17 -2
  5. data/.github/workflows/main.yml +3 -0
  6. data/.github/workflows/release_7_x_scheduled.yml +3 -0
  7. data/.github/workflows/release_8_x_scheduled.yml +3 -0
  8. data/.github/workflows/test.yml +3 -2
  9. data/.gitignore +0 -1
  10. data/.prettierignore +5 -0
  11. data/.prettierrc.json +4 -0
  12. data/.rubocop.yml +4 -0
  13. data/.rubocop_todo.yml +0 -143
  14. data/VERSION +1 -1
  15. data/app/assets/builds/blacklight.css +39 -9
  16. data/app/assets/javascripts/blacklight/blacklight.esm.js +207 -125
  17. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  18. data/app/assets/javascripts/blacklight/blacklight.js +207 -125
  19. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  20. data/app/assets/stylesheets/blacklight/_search_results.scss +24 -0
  21. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +18 -3
  22. data/app/components/blacklight/constraints_component.rb +2 -1
  23. data/app/components/blacklight/facet_field_component.rb +1 -1
  24. data/app/components/blacklight/open_graph_metadata_component.rb +33 -0
  25. data/app/components/blacklight/search/sidebar_component.html.erb +2 -2
  26. data/app/components/blacklight/search/sidebar_component.rb +3 -2
  27. data/app/controllers/concerns/blacklight/catalog.rb +3 -5
  28. data/app/controllers/concerns/blacklight/controller.rb +2 -6
  29. data/app/controllers/concerns/blacklight/search_context.rb +2 -7
  30. data/app/controllers/concerns/blacklight/token_based_user.rb +2 -6
  31. data/app/helpers/blacklight/catalog_helper_behavior.rb +9 -9
  32. data/app/helpers/blacklight/url_helper_behavior.rb +2 -7
  33. data/app/javascript/blacklight-frontend/bookmark_toggle.js +10 -8
  34. data/app/javascript/blacklight-frontend/checkbox_submit.js +42 -33
  35. data/app/javascript/blacklight-frontend/color_theme_switcher.js +47 -16
  36. data/app/javascript/blacklight-frontend/core.js +18 -19
  37. data/app/javascript/blacklight-frontend/debounce.js +7 -5
  38. data/app/javascript/blacklight-frontend/facet_suggest.js +27 -25
  39. data/app/javascript/blacklight-frontend/index.js +1 -1
  40. data/app/javascript/blacklight-frontend/modal.js +69 -52
  41. data/app/javascript/blacklight-frontend/search_context.js +36 -17
  42. data/app/models/blacklight/facet_paginator.rb +1 -3
  43. data/app/presenters/blacklight/document_presenter.rb +10 -1
  44. data/app/presenters/blacklight/facet_grouped_item_presenter.rb +1 -3
  45. data/app/presenters/blacklight/facet_item_pivot_presenter.rb +0 -8
  46. data/app/presenters/blacklight/json_presenter.rb +1 -3
  47. data/app/presenters/blacklight/open_graph_presenter.rb +34 -0
  48. data/app/presenters/blacklight/thumbnail_presenter.rb +24 -1
  49. data/app/services/blacklight/field_retriever.rb +1 -3
  50. data/app/services/blacklight/search_service.rb +1 -1
  51. data/app/views/catalog/_document.atom.builder +3 -5
  52. data/app/views/catalog/_show_main_content.html.erb +1 -0
  53. data/app/views/catalog/index.atom.builder +8 -4
  54. data/app/views/layouts/blacklight/base.html.erb +7 -1
  55. data/config/i18n-tasks.yml +1 -1
  56. data/config/locales/blacklight.ja.yml +256 -0
  57. data/lib/blacklight/configuration/context.rb +1 -1
  58. data/lib/blacklight/configuration/fields.rb +3 -9
  59. data/lib/blacklight/configuration/view_config.rb +16 -0
  60. data/lib/blacklight/configuration.rb +6 -2
  61. data/lib/blacklight/engine.rb +2 -4
  62. data/lib/blacklight/search_builder.rb +4 -4
  63. data/lib/blacklight/search_state/filter_field.rb +0 -1
  64. data/lib/blacklight/search_state.rb +2 -6
  65. data/lib/blacklight/solr/facet_paginator.rb +1 -1
  66. data/lib/blacklight/solr/repository.rb +1 -3
  67. data/lib/blacklight/solr/response/facets.rb +11 -9
  68. data/lib/blacklight/solr/response/spelling.rb +51 -47
  69. data/lib/blacklight/solr/search_builder_behavior.rb +14 -15
  70. data/lib/blacklight.rb +3 -9
  71. data/lib/generators/blacklight/assets/importmap_generator.rb +3 -3
  72. data/lib/generators/blacklight/assets_generator.rb +1 -1
  73. data/lib/railties/blacklight.rake +3 -5
  74. data/package-lock.json +1054 -0
  75. data/package.json +7 -4
  76. data/rollup.config.js +5 -7
  77. data/spec/components/blacklight/constraints_component_spec.rb +23 -1
  78. data/spec/components/blacklight/document/page_header_component_spec.rb +4 -4
  79. data/spec/components/blacklight/document_component_spec.rb +16 -3
  80. data/spec/components/blacklight/metadata_field_component_spec.rb +2 -2
  81. data/spec/components/blacklight/response/spellcheck_component_spec.rb +2 -2
  82. data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
  83. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +1 -1
  84. data/spec/components/blacklight/system/dropdown_component_spec.rb +1 -2
  85. data/spec/controllers/bookmarks_controller_spec.rb +3 -9
  86. data/spec/controllers/catalog_controller_spec.rb +56 -26
  87. data/spec/features/dark_mode_spec.rb +30 -0
  88. data/spec/features/did_you_mean_spec.rb +1 -1
  89. data/spec/features/facet_missing_spec.rb +3 -3
  90. data/spec/features/modal_spec.rb +2 -2
  91. data/spec/features/open_graph_spec.rb +43 -0
  92. data/spec/features/search_context_spec.rb +1 -1
  93. data/spec/fixtures/sample_solr_documents.yml +6 -0
  94. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +11 -8
  95. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +1 -1
  96. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
  97. data/spec/helpers/blacklight_helper_spec.rb +6 -4
  98. data/spec/helpers/catalog_helper_spec.rb +34 -8
  99. data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +2 -2
  100. data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +2 -2
  101. data/spec/lib/blacklight/search_state/filter_field_spec.rb +1 -1
  102. data/spec/lib/blacklight/search_state/pivot_filter_field_spec.rb +1 -1
  103. data/spec/lib/blacklight/search_state_spec.rb +14 -19
  104. data/spec/lib/blacklight_spec.rb +5 -5
  105. data/spec/models/blacklight/configuration_spec.rb +1 -1
  106. data/spec/models/blacklight/document/cache_key_spec.rb +32 -12
  107. data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
  108. data/spec/models/blacklight/icon_spec.rb +3 -3
  109. data/spec/models/blacklight/search_builder_spec.rb +21 -16
  110. data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +1 -1
  111. data/spec/models/blacklight/solr/document_spec.rb +8 -8
  112. data/spec/models/blacklight/solr/response/facets_spec.rb +5 -5
  113. data/spec/models/blacklight/solr/response/group_response_spec.rb +1 -1
  114. data/spec/models/blacklight/solr/response/group_spec.rb +1 -1
  115. data/spec/models/blacklight/solr/response_spec.rb +18 -3
  116. data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +46 -7
  117. data/spec/models/blacklight/suggest_search_spec.rb +1 -1
  118. data/spec/models/record_mailer_spec.rb +2 -2
  119. data/spec/models/search_spec.rb +7 -7
  120. data/spec/presenters/blacklight/document_presenter_spec.rb +19 -6
  121. data/spec/presenters/blacklight/facet_field_presenter_spec.rb +4 -4
  122. data/spec/presenters/blacklight/field_presenter_spec.rb +12 -9
  123. data/spec/presenters/blacklight/open_graph_presenter_spec.rb +56 -0
  124. data/spec/presenters/blacklight/rendering/pipeline_spec.rb +3 -3
  125. data/spec/presenters/blacklight/thumbnail_presenter_spec.rb +129 -13
  126. data/spec/routing/catalog_routing_spec.rb +1 -1
  127. data/spec/services/blacklight/field_retriever_spec.rb +1 -1
  128. data/spec/services/blacklight/search_service_spec.rb +8 -8
  129. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -3
  130. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -2
  131. data/spec/views/catalog/index.atom.builder_spec.rb +16 -20
  132. data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -1
  133. metadata +12 -2
@@ -62,7 +62,7 @@ RSpec.describe Blacklight::Icon do
62
62
  expect(subject.options[:'aria-hidden']).to be true
63
63
  end
64
64
 
65
- context 'no options provided' do
65
+ context 'without options' do
66
66
  subject { described_class.new(:view) }
67
67
 
68
68
  it 'applies default class with no options' do
@@ -84,7 +84,7 @@ RSpec.describe Blacklight::Icon do
84
84
  describe 'file_source' do
85
85
  subject(:file_source) { instance.file_source }
86
86
 
87
- context 'file is not available' do
87
+ context 'when the file is not available' do
88
88
  subject { described_class.new(:yolo) }
89
89
 
90
90
  let(:asset) { nil }
@@ -94,7 +94,7 @@ RSpec.describe Blacklight::Icon do
94
94
  end
95
95
  end
96
96
 
97
- context 'file is available' do
97
+ context 'when the file is available' do
98
98
  it 'returns the filesource' do
99
99
  expect(file_source).to include '<svg'
100
100
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Blacklight::SearchBuilder, :api do
4
- subject(:builder) { described_class.new processor_chain, scope }
4
+ subject(:builder) { builder_class.new processor_chain, scope }
5
5
 
6
+ let(:builder_class) { described_class }
6
7
  let(:processor_chain) { [] }
7
8
  let(:blacklight_config) { Blacklight::Configuration.new }
8
9
  let(:scope) { double blacklight_config: blacklight_config, search_state_class: nil }
@@ -84,9 +85,11 @@ RSpec.describe Blacklight::SearchBuilder, :api do
84
85
  describe "#merge" do
85
86
  let(:processor_chain) { [:pass_through] }
86
87
 
87
- before do
88
- allow(subject).to receive(:pass_through) do |req_params|
89
- req_params.replace subject.blacklight_params
88
+ let(:builder_class) do
89
+ Class.new(described_class) do
90
+ def pass_through(req_params)
91
+ req_params.replace blacklight_params
92
+ end
90
93
  end
91
94
  end
92
95
 
@@ -99,9 +102,11 @@ RSpec.describe Blacklight::SearchBuilder, :api do
99
102
  describe "#reverse_merge" do
100
103
  let(:processor_chain) { [:pass_through] }
101
104
 
102
- before do
103
- allow(subject).to receive(:pass_through) do |req_params|
104
- req_params.replace subject.blacklight_params
105
+ let(:builder_class) do
106
+ Class.new(described_class) do
107
+ def pass_through(req_params)
108
+ req_params.replace blacklight_params
109
+ end
105
110
  end
106
111
  end
107
112
 
@@ -118,12 +123,15 @@ RSpec.describe Blacklight::SearchBuilder, :api do
118
123
 
119
124
  describe "#processed_parameters" do
120
125
  let(:processor_chain) { [:step_1] }
121
-
122
- it "tries to run the processor method on the search builder" do
123
- allow(subject).to receive(:step_1) do |req_params|
124
- req_params[:step_1] = 'builder'
126
+ let(:builder_class) do
127
+ Class.new(described_class) do
128
+ def step_1(req_params)
129
+ req_params[:step_1] = 'builder'
130
+ end
125
131
  end
132
+ end
126
133
 
134
+ it "tries to run the processor method on the search builder" do
127
135
  subject.with(a: 1)
128
136
  expect(subject.processed_parameters).to include step_1: 'builder'
129
137
  end
@@ -209,13 +217,13 @@ RSpec.describe Blacklight::SearchBuilder, :api do
209
217
 
210
218
  let(:builder_with_param) { builder.with(sort: 'x') }
211
219
 
212
- context "that is invalid" do
220
+ context "when the sort is invalid" do
213
221
  it "removes them" do
214
222
  expect(sort).to be_nil
215
223
  end
216
224
  end
217
225
 
218
- context "that is valid" do
226
+ context "when the sort is valid" do
219
227
  before do
220
228
  blacklight_config.add_sort_field 'x', sort: 'x asc'
221
229
  end
@@ -285,19 +293,16 @@ RSpec.describe Blacklight::SearchBuilder, :api do
285
293
  end
286
294
 
287
295
  it "is marked as changed when pagination changes" do
288
- expect(subject).to receive(:page=).with(1).and_call_original
289
296
  subject.page(1)
290
297
  expect(subject.send(:params_changed?)).to be true
291
298
  end
292
299
 
293
300
  it "is marked as changed when rows changes" do
294
- expect(subject).to receive(:rows=).with(1).and_call_original
295
301
  subject.rows(1)
296
302
  expect(subject.send(:params_changed?)).to be true
297
303
  end
298
304
 
299
305
  it "is marked as changed when start offset changes" do
300
- expect(subject).to receive(:start=).with(1).and_call_original
301
306
  subject.start(1)
302
307
  expect(subject.send(:params_changed?)).to be true
303
308
  end
@@ -40,7 +40,7 @@ RSpec.describe Blacklight::Solr::DefaultFilterQueryBuilder do
40
40
  expect(subject.send(:facet_value_to_fq_string, "facet_name", "1.11")).to eq '{!term f=facet_name}1.11'
41
41
  end
42
42
 
43
- context 'date handling' do
43
+ describe 'date handling' do
44
44
  before { allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(date: true, query: nil, tag: nil, field: 'facet_name')) }
45
45
 
46
46
  it "passes date-type fields through" do
@@ -17,7 +17,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
17
17
  end
18
18
  end
19
19
 
20
- context "Hashy methods" do
20
+ describe "Hashy methods" do
21
21
  it 'creates a doc with hashy methods' do
22
22
  doc = SolrDocument.new('id' => 'SP2514N', 'inStock' => true, 'manu' => 'Samsung Electronics Co. Ltd.', 'name' => 'Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133', 'popularity' => 6, 'price' => 92.0, 'sku' => 'SP2514N', 'timestamp' => '2009-03-20T14:42:49.795Z', 'cat' => ['electronics', 'hard drive'], 'spell' => ['Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133'], 'features' => ['7200RPM, 8MB cache, IDE Ultra ATA-133', 'NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor'])
23
23
 
@@ -33,7 +33,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
33
33
  end
34
34
  end
35
35
 
36
- context "Unique Key" do
36
+ describe "Unique Key" do
37
37
  before do
38
38
  MockDocument.unique_key = 'my_unique_key'
39
39
  end
@@ -69,7 +69,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
69
69
  end
70
70
  end
71
71
 
72
- context "Extendability" do
72
+ describe "Extendability" do
73
73
  before do
74
74
  # Clear extensions
75
75
  MockDocument.registered_extensions = []
@@ -82,7 +82,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
82
82
  end
83
83
 
84
84
  it "lets you register an extension with a nil condition proc" do
85
- MockDocument.use_extension(MockExtension) { |_doc| true }
85
+ MockDocument.use_extension(MockExtension)
86
86
  expect(MockDocument.registered_extensions.find { |a| a[:module_obj] == MockExtension }).not_to be_nil
87
87
  end
88
88
 
@@ -149,7 +149,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
149
149
  end
150
150
  end
151
151
 
152
- context "Will export as" do
152
+ describe "Will export as" do
153
153
  class MockDocument
154
154
  include Blacklight::Solr::Document
155
155
 
@@ -171,7 +171,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
171
171
  expect(doc.export_formats).to have_key(:html)
172
172
  end
173
173
 
174
- context "format not registered with Mime::Type" do
174
+ context "when format is not registered with Mime::Type" do
175
175
  before(:all) do
176
176
  @doc = MockDocument.new
177
177
  @doc.will_export_as(:mock2, "application/mock2")
@@ -197,7 +197,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
197
197
  end
198
198
  end
199
199
 
200
- context "to_semantic_fields" do
200
+ describe "to_semantic_fields" do
201
201
  class MockDocument
202
202
  include Blacklight::Solr::Document
203
203
  end
@@ -235,7 +235,7 @@ RSpec.describe "Blacklight::Solr::Document", :api do
235
235
  end
236
236
  end
237
237
 
238
- context "highlighting" do
238
+ describe "highlighting" do
239
239
  before(:all) do
240
240
  @document = MockDocument.new({ 'id' => 'doc1', 'title_field' => 'doc1 title' }, 'highlighting' => { 'doc1' => { 'title_tsimext' => ['doc <em>1</em>'] }, 'doc2' => { 'title_tsimext' => ['doc 2'] } })
241
241
  end
@@ -5,7 +5,7 @@ RSpec.describe Blacklight::Solr::Response::Facets, :api do
5
5
  Blacklight::SearchBuilder.new(view_context)
6
6
  end
7
7
  let(:view_context) do
8
- double("View context", blacklight_config: CatalogController.blacklight_config.deep_copy)
8
+ instance_double(CatalogController, blacklight_config: CatalogController.blacklight_config.deep_copy)
9
9
  end
10
10
 
11
11
  describe Blacklight::Solr::Response::Facets::FacetField do
@@ -202,13 +202,13 @@ RSpec.describe Blacklight::Solr::Response::Facets, :api do
202
202
  response.merge_facet(**facet)
203
203
  end
204
204
 
205
- context "facet does not already exist" do
205
+ context "when facet does not already exist" do
206
206
  it "adds the facet and appends the new field name and value" do
207
207
  expect(response.facet_fields["foo"]).to eq(["bar", 1])
208
208
  end
209
209
  end
210
210
 
211
- context "facet exists but field does not exist" do
211
+ context "when facet exists but field does not exist" do
212
212
  let(:facet) { { name: "cat", value: "bar", hits: 1 } }
213
213
 
214
214
  it "appends the new field name and value" do
@@ -216,7 +216,7 @@ RSpec.describe Blacklight::Solr::Response::Facets, :api do
216
216
  end
217
217
  end
218
218
 
219
- context "facet exists and field exists" do
219
+ context "when facet exists and field exists" do
220
220
  let(:facet) { { name: "cat", value: "memory", hits: 4 } }
221
221
 
222
222
  it "appends the new field name and value and aggregations uses new value" do
@@ -231,7 +231,7 @@ RSpec.describe Blacklight::Solr::Response::Facets, :api do
231
231
  end
232
232
  end
233
233
 
234
- context "facet.missing" do
234
+ describe "facet.missing" do
235
235
  subject { Blacklight::Solr::Response.new(response, search_builder) }
236
236
 
237
237
  let(:response) do
@@ -11,7 +11,7 @@ RSpec.describe Blacklight::Solr::Response::GroupResponse, :api do
11
11
  Blacklight::SearchBuilder.new(view_context).tap { |b| b.rows = 3 }
12
12
  end
13
13
  let(:view_context) do
14
- double("View context", blacklight_config: CatalogController.blacklight_config.deep_copy)
14
+ instance_double(CatalogController, blacklight_config: CatalogController.blacklight_config.deep_copy)
15
15
  end
16
16
 
17
17
  let(:group) do
@@ -12,7 +12,7 @@ RSpec.describe Blacklight::Solr::Response::Group, :api do
12
12
  end
13
13
 
14
14
  let(:view_context) do
15
- double("View context", blacklight_config: CatalogController.blacklight_config.deep_copy)
15
+ instance_double(CatalogController, blacklight_config: CatalogController.blacklight_config.deep_copy)
16
16
  end
17
17
 
18
18
  let(:response) do
@@ -91,9 +91,7 @@ RSpec.describe Blacklight::Solr::Response, :api do
91
91
  expect(r.entry_name(count: 1)).to eq 'entry'
92
92
  expect(r.entry_name(count: 2)).to eq 'entries'
93
93
  expect(r.size).to eq 26
94
- if Kaminari.config.respond_to? :max_pages
95
- expect(r.max_pages).to be_nil
96
- end
94
+ expect(r.max_pages).to be_nil if Kaminari.config.respond_to? :max_pages
97
95
  expect(r).to be_a Kaminari::PageScopeMethods
98
96
  end
99
97
 
@@ -245,6 +243,23 @@ RSpec.describe Blacklight::Solr::Response, :api do
245
243
  expect(r.spelling.words).to include("dell")
246
244
  expect(r.spelling.words).to include("ultrasharp")
247
245
  end
246
+
247
+ it 'provides spelling suggestion collation' do
248
+ expect(r.spelling.collation).to eq 'dell ultrasharp'
249
+ end
250
+ end
251
+
252
+ context 'without a spellcheck response' do
253
+ let(:raw_response) { { 'response' => { 'numFound' => 0, 'start' => 0, 'docs' => [] } } }
254
+ let(:request_params) { {} }
255
+
256
+ it 'provides no spelling suggestions' do
257
+ expect(r.spelling.words).to eq []
258
+ end
259
+
260
+ it 'provides no collation' do
261
+ expect(r.spelling.collation).to be_nil
262
+ end
248
263
  end
249
264
 
250
265
  context 'with moreLikeThis suggstions' do
@@ -150,7 +150,7 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
150
150
  end
151
151
  end
152
152
 
153
- context "facet parameters" do
153
+ describe "facet parameters" do
154
154
  let(:blacklight_config) do
155
155
  Blacklight::Configuration.new.tap do |config|
156
156
  config.add_facet_field key: 'param_key', field: 'solr_field', limit: 50, ex: 'other'
@@ -353,9 +353,7 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
353
353
  end
354
354
 
355
355
  it "includes proper 'q' when LocalParams are used" do
356
- if /\{[^}]+\}/.match?(subject[:q])
357
- expect(subject[:q]).to match(/\{[^}]+\}wome/)
358
- end
356
+ expect(subject[:q]).to match(/\{[^}]+\}wome/) if /\{[^}]+\}/.match?(subject[:q])
359
357
  end
360
358
 
361
359
  it "includes spellcheck.q, without LocalParams" do
@@ -582,7 +580,7 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
582
580
  expect(solr_parameters[:fq]).to be_a Array
583
581
  end
584
582
 
585
- context "facet not defined in config" do
583
+ context "when facet is not defined in config" do
586
584
  let(:single_facet) { { unknown_facet_field: "foo" } }
587
585
  let(:user_params) { { f: single_facet } }
588
586
 
@@ -758,7 +756,7 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
758
756
  end
759
757
  end
760
758
 
761
- context 'for a field with a configured more_limit' do
759
+ context 'with a field with a configured more_limit' do
762
760
  let(:facet_field) { 'format_more_limited' }
763
761
 
764
762
  it 'uses the more_limit configuration' do
@@ -766,7 +764,7 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
766
764
  end
767
765
  end
768
766
 
769
- context 'for a field with a param key different from the field name' do
767
+ context 'with a field with a param key different from the field name' do
770
768
  let(:user_params) { { page_key => 2, 'facet.sort': 'index', 'facet.prefix': 'x' } }
771
769
  let(:facet_field) { 'param_key' }
772
770
 
@@ -810,6 +808,28 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
810
808
  expect(solr_parameters[:"f.#{facet_field}.facet.prefix"]).to eq 'A'
811
809
  end
812
810
  end
811
+
812
+ context 'with a json facet' do
813
+ let(:facet_field) { 'json_facet' }
814
+ let(:user_params) { { page_key => 2, sort_key => 'index', prefix_key => 'A' } }
815
+
816
+ let(:blacklight_config) do
817
+ Blacklight::Configuration.new do |config|
818
+ config.add_facet_fields_to_solr_request!
819
+ config.add_facet_field 'json_facet', field: 'solr_field', json: true
820
+ end
821
+ end
822
+
823
+ it 'requests the facet page using the JSON Facet API' do
824
+ expect(solr_parameters.dig(:json, :facet, 'json_facet')).to eq(
825
+ 'type' => 'terms', 'field' => 'solr_field', 'limit' => 21, 'offset' => 20, 'sort' => 'index', 'prefix' => 'A'
826
+ )
827
+ end
828
+
829
+ it 'does not add facet.field parameters' do
830
+ expect(solr_parameters).not_to have_key :'facet.field'
831
+ end
832
+ end
813
833
  end
814
834
 
815
835
  describe "#add_facet_suggestion_parameters" do
@@ -895,6 +915,25 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, :api do
895
915
  expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 1, :edismax, :query)).to eq 'the person'
896
916
  expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 1, :edismax, :qf)).to eq '${author_qf}'
897
917
  end
918
+
919
+ context 'with a clause for a search field that is not configured' do
920
+ let(:user_params) { { op: 'must', clause: { '0': { field: 'not_a_real_field', query: 'cats' }, '1': { field: 'title', query: 'the book' } } } }
921
+
922
+ it 'ignores that clause' do
923
+ must = subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must)
924
+ expect(must.length).to eq 1
925
+ expect(must.dig(0, :edismax, :query)).to eq 'the book'
926
+ end
927
+ end
928
+
929
+ context 'with only clauses for search fields that are not configured' do
930
+ let(:user_params) { { op: 'must', clause: { '0': { field: 'not_a_real_field', query: 'cats' } } } }
931
+
932
+ it 'does not switch to the JSON query DSL' do
933
+ expect(subject.to_hash).not_to include(:json, :defType)
934
+ expect(subject.to_hash[:spellcheck]).not_to eq 'false'
935
+ end
936
+ end
898
937
  end
899
938
 
900
939
  describe '#where' do
@@ -8,8 +8,8 @@ RSpec.describe Blacklight::SuggestSearch, :api do
8
8
 
9
9
  describe '#suggestions' do
10
10
  it 'delegates to the repository' do
11
- expect(repository).to receive(:suggestions).with({ q: 'test' }).and_return(response)
12
11
  expect(suggest_search.suggestions).to eq response
12
+ expect(repository).to have_received(:suggestions).with({ q: 'test' })
13
13
  end
14
14
  end
15
15
  end
@@ -60,7 +60,7 @@ RSpec.describe RecordMailer do
60
60
  expect(@https_email.body).to match %r{https://projectblacklight.org/}
61
61
  end
62
62
 
63
- context "email title_field is configured and multi valued" do
63
+ context "when email title_field is configured and multi valued" do
64
64
  let(:document) { SolrDocument.new(id: "123456", foo: ["Fizz Fizz", "Fuzz Fuzz"], format: ["book"], title_tsim: "The horn", language_ssim: "English", author_tsim: "Janetzky, Kurt") }
65
65
 
66
66
  before do
@@ -72,7 +72,7 @@ RSpec.describe RecordMailer do
72
72
  end
73
73
  end
74
74
 
75
- context "email title_field is configured and single valued" do
75
+ context "when email title_field is configured and single valued" do
76
76
  let(:document) { SolrDocument.new(id: "123456", foo: "Fizz Fizz", format: ["book"], title_tsim: "The horn", language_ssim: "English", author_tsim: "Janetzky, Kurt") }
77
77
 
78
78
  before do
@@ -15,19 +15,19 @@ RSpec.describe Search do
15
15
  end
16
16
  end
17
17
 
18
- context "are an indifferent hash" do
18
+ context "when they are an indifferent hash" do
19
19
  include_context "persisting query_params" do
20
20
  let(:query_params) { hash_params.with_indifferent_access }
21
21
  end
22
22
  end
23
23
 
24
- context "are a string-keyed hash" do
24
+ context "when they are a string-keyed hash" do
25
25
  include_context "persisting query_params" do
26
26
  let(:query_params) { hash_params.with_indifferent_access.to_hash }
27
27
  end
28
28
  end
29
29
 
30
- context "include symbol keys" do
30
+ context "when they include symbol keys" do
31
31
  include_context "persisting query_params" do
32
32
  let(:query_params) { hash_params }
33
33
  end
@@ -65,10 +65,10 @@ RSpec.describe Search do
65
65
  it "destroy searches with no user_id that are older than X days" do
66
66
  described_class.destroy_all
67
67
  days_old = 7
68
- described_class.create!(created_at: Date.today)
69
- described_class.create!(created_at: Date.today - (days_old + 1).days)
70
- described_class.create!(user: user, created_at: Date.today)
71
- described_class.create!(user: user, created_at: Date.today - (days_old + 1).days)
68
+ described_class.create!(created_at: Time.zone.today)
69
+ described_class.create!(created_at: Time.zone.today - (days_old + 1).days)
70
+ described_class.create!(user: user, created_at: Time.zone.today)
71
+ described_class.create!(user: user, created_at: Time.zone.today - (days_old + 1).days)
72
72
 
73
73
  expect do
74
74
  described_class.delete_old_searches(days_old)
@@ -1,27 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Blacklight::DocumentPresenter do
3
+ RSpec.describe Blacklight::DocumentPresenter, type: :presenter do
4
4
  subject(:presenter) { described_class.new(doc, request_context) }
5
5
 
6
6
  let(:doc) { SolrDocument.new('asdf' => 'asdf') }
7
7
  let(:blacklight_config) { Blacklight::Configuration.new }
8
- let(:request_context) { double('View context', should_render_field?: true, blacklight_config: blacklight_config) }
9
- let(:controller) { double }
8
+ let(:request_context) { controller.view_context }
10
9
  let(:params) { {} }
11
10
  let(:search_state) { Blacklight::SearchState.new(params, blacklight_config, controller) }
12
11
 
13
12
  before do
14
- allow(request_context).to receive_messages(search_state: search_state, action_name: :show)
13
+ allow(request_context).to receive_messages(should_render_field?: true, blacklight_config: blacklight_config, search_state: search_state, action_name: :show)
15
14
  end
16
15
 
17
16
  describe '#fields_to_render' do
18
17
  subject { presenter.fields_to_render.to_a }
19
18
 
20
- let(:field_config) { Blacklight::Configuration::DisplayField.new(field: 'asdf') }
19
+ let(:field_config) { blacklight_config.show_fields['title'] }
21
20
 
22
21
  context 'when all of the fields have values' do
23
22
  before do
24
- allow(presenter).to receive_messages(fields: { 'title' => field_config })
23
+ blacklight_config.add_show_field 'title', field: 'asdf'
25
24
  end
26
25
 
27
26
  it { is_expected.to include(['title', field_config, an_instance_of(Blacklight::FieldPresenter)]) }
@@ -61,6 +60,20 @@ RSpec.describe Blacklight::DocumentPresenter do
61
60
  end
62
61
  end
63
62
 
63
+ describe '#open_graph' do
64
+ it 'returns an open graph presenter for this document presenter' do
65
+ expect(presenter.open_graph).to be_a(Blacklight::OpenGraphPresenter)
66
+ expect(presenter.open_graph.presenter).to be presenter
67
+ end
68
+
69
+ it 'uses the configured open graph presenter' do
70
+ custom_presenter_class = Class.new(Blacklight::OpenGraphPresenter)
71
+ blacklight_config.index.open_graph_presenter = custom_presenter_class
72
+
73
+ expect(presenter.open_graph).to be_a custom_presenter_class
74
+ end
75
+ end
76
+
64
77
  describe '#inspect' do
65
78
  subject(:inspect) { presenter.inspect }
66
79
 
@@ -31,7 +31,7 @@ RSpec.describe Blacklight::FacetFieldPresenter, type: :presenter do
31
31
  expect(presenter).not_to be_collapsed
32
32
  end
33
33
 
34
- context "it is in the params" do
34
+ context "when it is in the params" do
35
35
  before do
36
36
  search_state.params[:f] = { key: [1] }
37
37
  end
@@ -68,7 +68,7 @@ RSpec.describe Blacklight::FacetFieldPresenter, type: :presenter do
68
68
  end
69
69
 
70
70
  describe '#in_modal?' do
71
- context 'for action #facet, which is a modal-like action' do
71
+ context 'with action #facet, which is a modal-like action' do
72
72
  before do
73
73
  controller.params[:action] = 'facet'
74
74
  end
@@ -78,7 +78,7 @@ RSpec.describe Blacklight::FacetFieldPresenter, type: :presenter do
78
78
  end
79
79
  end
80
80
 
81
- context 'for action #facet_suggest, which is a modal-like action' do
81
+ context 'with action #facet_suggest, which is a modal-like action' do
82
82
  before do
83
83
  controller.params[:action] = 'facet_suggest'
84
84
  end
@@ -189,7 +189,7 @@ RSpec.describe Blacklight::FacetFieldPresenter, type: :presenter do
189
189
  end
190
190
  end
191
191
 
192
- context 'for facet fields with a key that is different from the field name' do
192
+ context 'with facet fields with a key that is different from the field name' do
193
193
  before do
194
194
  allow(controller).to receive(:blacklight_config).and_return(blacklight_config)
195
195
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Blacklight::FieldPresenter, :api do
3
+ RSpec.describe Blacklight::FieldPresenter, :api, type: :presenter do
4
4
  subject(:presenter) { described_class.new(request_context, document, field_config, options) }
5
5
 
6
- let(:request_context) { double('View context', params: { x: '1' }, search_state: search_state, should_render_field?: true, blacklight_config: config) }
6
+ let(:request_context) { controller.view_context }
7
7
  let(:document) do
8
8
  SolrDocument.new(id: 1,
9
9
  'join_true' => %w[a b c],
@@ -15,7 +15,6 @@ RSpec.describe Blacklight::FieldPresenter, :api do
15
15
  end
16
16
  let(:options) { {} }
17
17
  let(:params) { {} }
18
- let(:controller) { double }
19
18
  let(:search_state) { Blacklight::SearchState.new(params, config, controller) }
20
19
 
21
20
  let(:field_config) { config.index_fields[field_name] }
@@ -50,6 +49,10 @@ RSpec.describe Blacklight::FieldPresenter, :api do
50
49
  end
51
50
  end
52
51
 
52
+ before do
53
+ allow(request_context).to receive_messages(params: { x: '1' }, search_state: search_state, should_render_field?: true, blacklight_config: config)
54
+ end
55
+
53
56
  describe '#render' do
54
57
  subject(:result) { presenter.render }
55
58
 
@@ -158,9 +161,10 @@ RSpec.describe Blacklight::FieldPresenter, :api do
158
161
  let(:field_name) { 'explicit_accessor' }
159
162
 
160
163
  it 'calls the accessor with the field_name as the argument' do
161
- expect(document).to receive(:solr_doc_accessor).with('explicit_accessor').and_return("123")
164
+ allow(document).to receive(:solr_doc_accessor).and_return("123")
162
165
 
163
166
  expect(subject).to eq ['123']
167
+ expect(document).to have_received(:solr_doc_accessor).with('explicit_accessor')
164
168
  end
165
169
  end
166
170
 
@@ -168,7 +172,7 @@ RSpec.describe Blacklight::FieldPresenter, :api do
168
172
  let(:field_name) { 'explicit_array_accessor' }
169
173
 
170
174
  it 'calls the accessors on the return of the preceeding' do
171
- allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123")
175
+ allow(document).to receive(:solr_doc_accessor).and_return(double(some_method: "123"))
172
176
 
173
177
  expect(subject).to eq ['123']
174
178
  end
@@ -200,7 +204,7 @@ RSpec.describe Blacklight::FieldPresenter, :api do
200
204
  it { is_expected.to eq ['Static step'] }
201
205
  end
202
206
 
203
- context 'for a field with the helper_method option' do
207
+ context 'with a field with the helper_method option' do
204
208
  let(:field_name) { 'field_with_helper' }
205
209
  let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
206
210
  let(:document) do
@@ -310,14 +314,13 @@ RSpec.describe Blacklight::FieldPresenter, :api do
310
314
  describe '#render_field?' do
311
315
  subject { presenter.render_field? }
312
316
 
313
- let(:field_config) { double('field config', if: true, unless: false, except_operations: nil) }
317
+ let(:field_config) { Blacklight::Configuration::DisplayField.new(if: true, unless: false) }
314
318
 
315
319
  it { is_expected.to be true }
316
320
 
317
321
  context 'when the view context says not to render the field' do
318
- let(:request_context) { double('View context', should_render_field?: false, blacklight_config: config) }
319
-
320
322
  before do
323
+ allow(request_context).to receive_messages(should_render_field?: false)
321
324
  allow(field_config).to receive_messages(if: false)
322
325
  end
323
326