blacklight 6.2.0 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.solr_wrapper +5 -0
- data/.travis.yml +3 -5
- data/Gemfile +3 -3
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/core.js +19 -5
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +48 -20
- data/app/helpers/blacklight/configuration_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/url_helper_behavior.rb +2 -1
- data/app/presenters/blacklight/document_presenter.rb +58 -150
- data/app/presenters/blacklight/field_presenter.rb +31 -0
- data/app/presenters/blacklight/index_presenter.rb +69 -0
- data/app/presenters/blacklight/link_alternate_presenter.rb +29 -0
- data/app/presenters/blacklight/rendering/abstract_step.rb +24 -0
- data/app/presenters/blacklight/rendering/helper_method.rb +23 -0
- data/app/presenters/blacklight/rendering/join.rb +16 -0
- data/app/presenters/blacklight/rendering/link_to_facet.rb +35 -0
- data/app/presenters/blacklight/rendering/microdata.rb +17 -0
- data/app/presenters/blacklight/rendering/pipeline.rb +32 -0
- data/app/presenters/blacklight/rendering/terminator.rb +9 -0
- data/app/presenters/blacklight/show_presenter.rb +93 -0
- data/app/services/blacklight/field_retriever.rb +58 -0
- data/app/views/catalog/_document_default.atom.builder +2 -3
- data/app/views/catalog/_document_default.rss.builder +2 -2
- data/app/views/kaminari/blacklight/_next_page.html.erb +9 -3
- data/app/views/kaminari/blacklight/_prev_page.html.erb +10 -3
- data/lib/blacklight/configuration.rb +15 -3
- data/lib/blacklight/configuration/null_field.rb +13 -0
- data/lib/blacklight/configuration/view_config.rb +6 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +1 -1
- data/lib/generators/blacklight/templates/config/blacklight.yml +1 -1
- data/lib/generators/blacklight/templates/config/jetty.yml +1 -1
- data/spec/controllers/alternate_controller_spec.rb +2 -2
- data/spec/controllers/application_controller_spec.rb +1 -1
- data/spec/controllers/blacklight/facet_spec.rb +3 -3
- data/spec/controllers/blacklight/search_fields_spec.rb +7 -7
- data/spec/controllers/blacklight/search_helper_spec.rb +44 -44
- data/spec/controllers/blacklight/suggest_search_spec.rb +1 -1
- data/spec/controllers/bookmarks_controller_spec.rb +6 -6
- data/spec/controllers/catalog_controller_spec.rb +125 -125
- data/spec/controllers/saved_searches_controller_spec.rb +4 -9
- data/spec/controllers/search_history_controller_spec.rb +3 -6
- data/spec/controllers/suggest_controller_spec.rb +2 -2
- data/spec/features/alternate_controller_spec.rb +3 -3
- data/spec/features/bookmarks_spec.rb +6 -6
- data/spec/features/did_you_mean_spec.rb +10 -10
- data/spec/features/facets_spec.rb +4 -4
- data/spec/features/record_view_spec.rb +4 -4
- data/spec/features/saved_searches_spec.rb +4 -4
- data/spec/features/search_context_spec.rb +4 -4
- data/spec/features/search_filters_spec.rb +10 -10
- data/spec/features/search_formats_spec.rb +2 -2
- data/spec/features/search_history_spec.rb +5 -5
- data/spec/features/search_pagination_spec.rb +4 -4
- data/spec/features/search_results_spec.rb +7 -7
- data/spec/features/search_sort_spec.rb +2 -2
- data/spec/features/search_spec.rb +6 -6
- data/spec/helpers/blacklight_helper_spec.rb +105 -65
- data/spec/helpers/catalog_helper_spec.rb +36 -36
- data/spec/helpers/configuration_helper_spec.rb +28 -28
- data/spec/helpers/facets_helper_spec.rb +39 -39
- data/spec/helpers/hash_as_hidden_fields_spec.rb +1 -1
- data/spec/helpers/render_constraints_helper_spec.rb +1 -1
- data/spec/helpers/search_history_constraints_helper_spec.rb +7 -7
- data/spec/helpers/url_helper_spec.rb +20 -17
- data/spec/lib/blacklight/search_state_spec.rb +2 -2
- data/spec/lib/blacklight/utils_spec.rb +15 -15
- data/spec/lib/blacklight_spec.rb +1 -1
- data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
- data/spec/models/blacklight/configurable_spec.rb +3 -3
- data/spec/models/blacklight/configuration_spec.rb +52 -52
- data/spec/models/blacklight/document_spec.rb +10 -10
- data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
- data/spec/models/blacklight/search_builder_spec.rb +34 -34
- data/spec/models/blacklight/user_spec.rb +4 -4
- data/spec/models/bookmark_spec.rb +5 -5
- data/spec/models/record_mailer_spec.rb +11 -11
- data/spec/models/search_spec.rb +1 -1
- data/spec/models/solr_document_spec.rb +4 -4
- data/spec/presenters/document_presenter_spec.rb +94 -50
- data/spec/presenters/index_presenter_spec.rb +147 -0
- data/spec/presenters/pipeline_spec.rb +28 -0
- data/spec/presenters/show_presenter_spec.rb +287 -0
- data/spec/routing/catalog_routing_spec.rb +11 -11
- data/spec/spec_helper.rb +10 -1
- data/spec/support/backport_test.rb +38 -0
- data/spec/test_app_templates/Gemfile.extra +2 -10
- data/spec/views/_user_util_links.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_constraints.html.erb_spec.rb +3 -3
- data/spec/views/catalog/_constraints_element.html.erb_spec.rb +5 -5
- data/spec/views/catalog/_document.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_facets.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_index_default.erb_spec.rb +5 -4
- data/spec/views/catalog/_index_header_default.html.erb_spec.rb +4 -3
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
- data/spec/views/catalog/_search_header.erb_spec.rb +1 -1
- data/spec/views/catalog/_show_default.erb_spec.rb +6 -5
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +2 -1
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -2
- data/spec/views/catalog/_view_type_group.html.erb_spec.rb +3 -3
- data/spec/views/catalog/facet.html.erb_spec.rb +3 -3
- data/spec/views/catalog/index.atom.builder_spec.rb +15 -14
- data/spec/views/catalog/index.html.erb_spec.rb +3 -3
- data/spec/views/catalog/opensearch.xml.builder_spec.rb +1 -1
- data/spec/views/catalog/show.html.erb_spec.rb +5 -4
- data/tasks/blacklight.rake +1 -1
- metadata +25 -4
- data/config/jetty.yml +0 -13
data/spec/models/search_spec.rb
CHANGED
@@ -10,22 +10,22 @@ describe SolrDocument do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "new" do
|
13
|
-
it "
|
13
|
+
it "takes a Hash as the argument" do
|
14
14
|
expect { SolrDocument.new(:id => 1) }.not_to raise_error
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "access methods" do
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "has the right value for title_display" do
|
21
21
|
expect(@solrdoc[:title_display]).not_to be_nil
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "has the right value for format" do
|
25
25
|
expect(@solrdoc[:format][0]).to eq 'Book'
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "provides the item's solr id" do
|
29
29
|
expect(@solrdoc.id).to eq '00282214'
|
30
30
|
end
|
31
31
|
end
|
@@ -3,11 +3,13 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Blacklight::DocumentPresenter do
|
5
5
|
include Capybara::RSpecMatchers
|
6
|
+
let(:show_presenter) { Blacklight::ShowPresenter.new(document, request_context, config) }
|
7
|
+
let(:index_presenter) { Blacklight::IndexPresenter.new(document, request_context, config) }
|
6
8
|
let(:request_context) { double }
|
7
9
|
let(:config) { Blacklight::Configuration.new }
|
8
10
|
|
9
11
|
subject { presenter }
|
10
|
-
let(:presenter) {
|
12
|
+
let(:presenter) { described_class.new(document, request_context, config) }
|
11
13
|
let(:parameter_class) { ActionController::Parameters }
|
12
14
|
let(:params) { parameter_class.new }
|
13
15
|
let(:search_state) { Blacklight::SearchState.new(params, config) }
|
@@ -22,6 +24,7 @@ describe Blacklight::DocumentPresenter do
|
|
22
24
|
|
23
25
|
before do
|
24
26
|
allow(request_context).to receive(:search_state).and_return(search_state)
|
27
|
+
allow(Deprecation).to receive(:warn)
|
25
28
|
end
|
26
29
|
|
27
30
|
describe "link_rel_alternates" do
|
@@ -50,6 +53,7 @@ describe Blacklight::DocumentPresenter do
|
|
50
53
|
allow(request_context).to receive(:polymorphic_url) do |_, opts|
|
51
54
|
"url.#{opts[:format]}"
|
52
55
|
end
|
56
|
+
allow(request_context).to receive(:show_presenter).and_return(show_presenter)
|
53
57
|
end
|
54
58
|
|
55
59
|
let(:document) { MockDocument.new(id: "MOCK_ID1") }
|
@@ -112,78 +116,85 @@ describe Blacklight::DocumentPresenter do
|
|
112
116
|
config.add_index_field 'with_default', default: 'value'
|
113
117
|
end
|
114
118
|
end
|
115
|
-
|
119
|
+
before do
|
120
|
+
allow(request_context).to receive(:index_presenter).and_return(index_presenter)
|
121
|
+
end
|
122
|
+
it "checks for an explicit value" do
|
116
123
|
value = subject.render_index_field_value 'asdf', :value => 'asdf'
|
117
124
|
expect(value).to eq 'asdf'
|
118
125
|
end
|
119
126
|
|
120
|
-
it "
|
127
|
+
it "checks for a helper method to call" do
|
121
128
|
allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
|
122
129
|
value = subject.render_index_field_value 'asdf'
|
123
130
|
expect(value).to eq 'custom asdf value'
|
124
131
|
end
|
125
132
|
|
126
|
-
it "
|
133
|
+
it "checks for a link_to_search" do
|
127
134
|
allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_search_true' => ['x'] }).and_return('/foo')
|
128
135
|
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
129
136
|
value = subject.render_index_field_value 'link_to_search_true'
|
130
137
|
expect(value).to eq 'bar'
|
131
138
|
end
|
132
139
|
|
133
|
-
it "
|
140
|
+
it "checks for a link_to_search with a field name" do
|
134
141
|
allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo')
|
135
142
|
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
136
143
|
value = subject.render_index_field_value 'link_to_search_named'
|
137
144
|
expect(value).to eq 'bar'
|
138
145
|
end
|
139
146
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
147
|
+
context "when no highlight field is available" do
|
148
|
+
before do
|
149
|
+
allow(document).to receive(:has_highlight_field?).and_return(false)
|
150
|
+
end
|
151
|
+
let(:value) { subject.render_index_field_value 'highlight' }
|
152
|
+
it "is blank" do
|
153
|
+
expect(value).to be_blank
|
154
|
+
end
|
144
155
|
end
|
145
156
|
|
146
|
-
it "
|
157
|
+
it "checks for a highlighted field" do
|
147
158
|
allow(document).to receive(:has_highlight_field?).and_return(true)
|
148
159
|
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
149
160
|
value = subject.render_index_field_value 'highlight'
|
150
161
|
expect(value).to eq '<em>highlight</em>'
|
151
162
|
end
|
152
163
|
|
153
|
-
it "
|
164
|
+
it "checks the document field value" do
|
154
165
|
value = subject.render_index_field_value 'qwer'
|
155
166
|
expect(value).to eq 'document qwer value'
|
156
167
|
end
|
157
168
|
|
158
|
-
it "
|
169
|
+
it "works with index fields that aren't explicitly defined" do
|
159
170
|
value = subject.render_index_field_value 'mnbv'
|
160
171
|
expect(value).to eq 'document mnbv value'
|
161
172
|
end
|
162
173
|
|
163
|
-
it "
|
174
|
+
it "calls an accessor on the solr document" do
|
164
175
|
allow(document).to receive_messages(solr_doc_accessor: "123")
|
165
176
|
value = subject.render_index_field_value 'solr_doc_accessor'
|
166
177
|
expect(value).to eq "123"
|
167
178
|
end
|
168
179
|
|
169
|
-
it "
|
180
|
+
it "calls an explicit accessor on the solr document" do
|
170
181
|
allow(document).to receive_messages(solr_doc_accessor: "123")
|
171
182
|
value = subject.render_index_field_value 'explicit_accessor'
|
172
183
|
expect(value).to eq "123"
|
173
184
|
end
|
174
185
|
|
175
|
-
it "
|
186
|
+
it "calls an accessor on the solr document with the field as an argument" do
|
176
187
|
allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
|
177
188
|
value = subject.render_index_field_value 'explicit_accessor_with_arg'
|
178
189
|
expect(value).to eq "123"
|
179
190
|
end
|
180
191
|
|
181
|
-
it "
|
192
|
+
it "supports solr field configuration" do
|
182
193
|
value = subject.render_index_field_value 'alias'
|
183
194
|
expect(value).to eq "document qwer value"
|
184
195
|
end
|
185
196
|
|
186
|
-
it "
|
197
|
+
it "supports default values in the field configuration" do
|
187
198
|
value = subject.render_index_field_value 'with_default'
|
188
199
|
expect(value).to eq "value"
|
189
200
|
end
|
@@ -204,6 +215,10 @@ describe Blacklight::DocumentPresenter do
|
|
204
215
|
end
|
205
216
|
end
|
206
217
|
|
218
|
+
before do
|
219
|
+
allow(request_context).to receive(:show_presenter).and_return(show_presenter)
|
220
|
+
end
|
221
|
+
|
207
222
|
it 'html-escapes values' do
|
208
223
|
value = subject.render_document_show_field_value 'asdf', value: '<b>val1</b>'
|
209
224
|
expect(value).to eq '<b>val1</b>'
|
@@ -219,39 +234,43 @@ describe Blacklight::DocumentPresenter do
|
|
219
234
|
expect(value).to eq 'a, b, and c'
|
220
235
|
end
|
221
236
|
|
222
|
-
it "
|
237
|
+
it "checks for an explicit value" do
|
223
238
|
expect(request_context).to_not receive(:render_asdf_document_show_field)
|
224
239
|
value = subject.render_document_show_field_value 'asdf', :value => 'val1'
|
225
240
|
expect(value).to eq 'val1'
|
226
241
|
end
|
227
242
|
|
228
|
-
it "
|
243
|
+
it "checks for a helper method to call" do
|
229
244
|
allow(request_context).to receive(:render_asdf_document_show_field).and_return('custom asdf value')
|
230
245
|
value = subject.render_document_show_field_value 'asdf'
|
231
246
|
expect(value).to eq 'custom asdf value'
|
232
247
|
end
|
233
248
|
|
234
|
-
it "
|
249
|
+
it "checks for a link_to_search" do
|
235
250
|
allow(request_context).to receive(:search_action_path).and_return('/foo')
|
236
251
|
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
237
252
|
value = subject.render_document_show_field_value 'link_to_search_true'
|
238
253
|
expect(value).to eq 'bar'
|
239
254
|
end
|
240
255
|
|
241
|
-
it "
|
256
|
+
it "checks for a link_to_search with a field name" do
|
242
257
|
allow(request_context).to receive(:search_action_path).and_return('/foo')
|
243
258
|
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
244
259
|
value = subject.render_document_show_field_value 'link_to_search_named'
|
245
260
|
expect(value).to eq 'bar'
|
246
261
|
end
|
247
262
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
263
|
+
context "when no highlight field is available" do
|
264
|
+
before do
|
265
|
+
allow(document).to receive(:has_highlight_field?).and_return(false)
|
266
|
+
end
|
267
|
+
let(:value) { subject.render_document_show_field_value 'highlight' }
|
268
|
+
it "is blank" do
|
269
|
+
expect(value).to be_blank
|
270
|
+
end
|
252
271
|
end
|
253
272
|
|
254
|
-
it "
|
273
|
+
it "checks for a highlighted field" do
|
255
274
|
allow(document).to receive(:has_highlight_field?).and_return(true)
|
256
275
|
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
257
276
|
value = subject.render_document_show_field_value 'highlight'
|
@@ -265,68 +284,80 @@ describe Blacklight::DocumentPresenter do
|
|
265
284
|
expect(value).to eq '<em>highlight</em> and <em>other highlight</em>'
|
266
285
|
end
|
267
286
|
|
268
|
-
it "
|
287
|
+
it "checks the document field value" do
|
269
288
|
value = subject.render_document_show_field_value 'qwer'
|
270
289
|
expect(value).to eq 'document qwer value'
|
271
290
|
end
|
272
291
|
|
273
|
-
it "
|
292
|
+
it "works with show fields that aren't explicitly defined" do
|
274
293
|
value = subject.render_document_show_field_value 'mnbv'
|
275
294
|
expect(value).to eq 'document mnbv value'
|
276
295
|
end
|
277
296
|
|
278
|
-
it "
|
297
|
+
it "calls an accessor on the solr document" do
|
279
298
|
allow(document).to receive_messages(solr_doc_accessor: "123")
|
280
299
|
value = subject.render_document_show_field_value 'solr_doc_accessor'
|
281
300
|
expect(value).to eq "123"
|
282
301
|
end
|
283
302
|
|
284
|
-
it "
|
303
|
+
it "calls an explicit accessor on the solr document" do
|
285
304
|
allow(document).to receive_messages(solr_doc_accessor: "123")
|
286
305
|
value = subject.render_document_show_field_value 'explicit_accessor'
|
287
306
|
expect(value).to eq "123"
|
288
307
|
end
|
289
308
|
|
290
|
-
it "
|
309
|
+
it "calls an explicit array-style accessor on the solr document" do
|
291
310
|
allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123")
|
292
311
|
value = subject.render_document_show_field_value 'explicit_array_accessor'
|
293
312
|
expect(value).to eq "123"
|
294
313
|
end
|
295
314
|
|
296
|
-
it "
|
315
|
+
it "calls an accessor on the solr document with the field as an argument" do
|
297
316
|
allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
|
298
317
|
value = subject.render_document_show_field_value 'explicit_accessor_with_arg'
|
299
318
|
expect(value).to eq "123"
|
300
319
|
end
|
301
320
|
end
|
302
321
|
describe "render_field_value" do
|
303
|
-
|
322
|
+
before do
|
323
|
+
expect(Deprecation).to receive(:warn)
|
324
|
+
end
|
325
|
+
it "joins and html-safe values" do
|
304
326
|
expect(subject.render_field_value(['a', 'b'])).to eq "a and b"
|
305
327
|
end
|
306
328
|
|
307
|
-
|
308
|
-
|
329
|
+
context "with separator_options" do
|
330
|
+
let(:field_config) { double(to_h: { field: 'foo', separator: nil, itemprop: nil, separator_options: { two_words_connector: '; '}}) }
|
331
|
+
it "uses the field_config.separator_options" do
|
332
|
+
expect(subject.render_field_value(['c', 'd'], field_config)).to eq "c; d"
|
333
|
+
end
|
309
334
|
end
|
310
335
|
|
311
|
-
|
312
|
-
|
336
|
+
context "with itemprop attributes" do
|
337
|
+
let(:field_config) { double(to_h: { field: 'bar', separator: nil, itemprop: 'some-prop', separator_options: nil }) }
|
338
|
+
it "includes schema.org itemprop attributes" do
|
339
|
+
expect(subject.render_field_value('a', field_config)).to have_selector("span[@itemprop='some-prop']", :text => "a")
|
340
|
+
end
|
313
341
|
end
|
314
342
|
end
|
315
343
|
|
316
344
|
describe "#document_heading" do
|
317
|
-
|
318
|
-
allow(
|
345
|
+
before do
|
346
|
+
allow(request_context).to receive(:show_presenter).and_return(show_presenter)
|
347
|
+
end
|
348
|
+
it "falls back to an id" do
|
349
|
+
allow(document).to receive(:[]).with('id').and_return "xyz"
|
319
350
|
expect(subject.document_heading).to eq document.id
|
320
351
|
end
|
321
352
|
|
322
|
-
it "
|
353
|
+
it "returns the value of the field" do
|
323
354
|
config.show.title_field = :x
|
324
355
|
allow(document).to receive(:has?).with(:x).and_return(true)
|
325
356
|
allow(document).to receive(:[]).with(:x).and_return("value")
|
326
357
|
expect(subject.document_heading).to eq "value"
|
327
358
|
end
|
328
359
|
|
329
|
-
it "
|
360
|
+
it "returns the first present value" do
|
330
361
|
config.show.title_field = [:x, :y]
|
331
362
|
allow(document).to receive(:has?).with(:x).and_return(false)
|
332
363
|
allow(document).to receive(:has?).with(:y).and_return(true)
|
@@ -336,28 +367,41 @@ describe Blacklight::DocumentPresenter do
|
|
336
367
|
end
|
337
368
|
|
338
369
|
describe "#document_show_html_title" do
|
339
|
-
|
340
|
-
allow(
|
370
|
+
before do
|
371
|
+
allow(request_context).to receive(:show_presenter).and_return(show_presenter)
|
372
|
+
end
|
373
|
+
it "falls back to an id" do
|
374
|
+
allow(document).to receive(:[]).with('id').and_return "xyz"
|
341
375
|
expect(subject.document_show_html_title).to eq document.id
|
342
376
|
end
|
343
377
|
|
344
|
-
it "
|
378
|
+
it "returns the value of the field" do
|
345
379
|
config.show.html_title_field = :x
|
346
380
|
allow(document).to receive(:has?).with(:x).and_return(true)
|
347
|
-
allow(document).to receive(:
|
381
|
+
allow(document).to receive(:fetch).with(:x, nil).and_return("value")
|
348
382
|
expect(subject.document_show_html_title).to eq "value"
|
349
383
|
end
|
350
384
|
|
351
|
-
it "
|
385
|
+
it "returns the first present value" do
|
352
386
|
config.show.html_title_field = [:x, :y]
|
353
387
|
allow(document).to receive(:has?).with(:x).and_return(false)
|
354
388
|
allow(document).to receive(:has?).with(:y).and_return(true)
|
355
|
-
allow(document).to receive(:
|
389
|
+
allow(document).to receive(:fetch).with(:y, nil).and_return("value")
|
356
390
|
expect(subject.document_show_html_title).to eq "value"
|
357
391
|
end
|
358
392
|
end
|
359
393
|
|
360
394
|
describe '#get_field_values' do
|
395
|
+
let(:field_config) { double }
|
396
|
+
let(:options) { double }
|
397
|
+
it "calls field_values" do
|
398
|
+
expect(Deprecation).to receive(:warn)
|
399
|
+
expect(presenter).to receive(:field_values).with(field_config, options)
|
400
|
+
presenter.get_field_values('name', field_config, options)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe '#field_values' do
|
361
405
|
context 'for a field with the helper_method option' do
|
362
406
|
let(:field_name) { 'field_with_helper' }
|
363
407
|
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
|
@@ -366,19 +410,19 @@ describe Blacklight::DocumentPresenter do
|
|
366
410
|
document['field_with_helper'] = 'value'
|
367
411
|
end
|
368
412
|
|
369
|
-
it "
|
413
|
+
it "checks call the helper method with arguments" do
|
370
414
|
allow(request_context).to receive(:render_field_with_helper) do |*args|
|
371
415
|
args.first
|
372
416
|
end
|
373
417
|
|
374
418
|
render_options = { a: 1 }
|
375
419
|
|
376
|
-
options = subject.
|
420
|
+
options = subject.field_values field_config, a: 1
|
377
421
|
|
378
422
|
expect(options).to include :document, :field, :value, :config, :a
|
379
423
|
expect(options[:document]).to eq document
|
380
424
|
expect(options[:field]).to eq 'field_with_helper'
|
381
|
-
expect(options[:value]).to eq 'value'
|
425
|
+
expect(options[:value]).to eq ['value']
|
382
426
|
expect(options[:config]).to eq field_config
|
383
427
|
expect(options[:a]).to eq 1
|
384
428
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Blacklight::IndexPresenter do
|
5
|
+
include Capybara::RSpecMatchers
|
6
|
+
let(:request_context) { double }
|
7
|
+
let(:config) { Blacklight::Configuration.new }
|
8
|
+
|
9
|
+
subject { presenter }
|
10
|
+
let(:presenter) { described_class.new(document, request_context, config) }
|
11
|
+
let(:parameter_class) { ActionController::Parameters }
|
12
|
+
let(:params) { parameter_class.new }
|
13
|
+
let(:search_state) { Blacklight::SearchState.new(params, config) }
|
14
|
+
|
15
|
+
let(:document) do
|
16
|
+
SolrDocument.new(id: 1,
|
17
|
+
'link_to_search_true' => 'x',
|
18
|
+
'link_to_search_named' => 'x',
|
19
|
+
'qwer' => 'document qwer value',
|
20
|
+
'mnbv' => 'document mnbv value')
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(request_context).to receive(:search_state).and_return(search_state)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "field_value" do
|
28
|
+
let(:config) do
|
29
|
+
Blacklight::Configuration.new.configure do |config|
|
30
|
+
config.add_index_field 'qwer'
|
31
|
+
config.add_index_field 'asdf', :helper_method => :render_asdf_index_field
|
32
|
+
config.add_index_field 'link_to_search_true', :link_to_search => true
|
33
|
+
config.add_index_field 'link_to_search_named', :link_to_search => :some_field
|
34
|
+
config.add_index_field 'highlight', :highlight => true
|
35
|
+
config.add_index_field 'solr_doc_accessor', :accessor => true
|
36
|
+
config.add_index_field 'explicit_accessor', :accessor => :solr_doc_accessor
|
37
|
+
config.add_index_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg
|
38
|
+
config.add_index_field 'alias', field: 'qwer'
|
39
|
+
config.add_index_field 'with_default', default: 'value'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
it "checks for an explicit value" do
|
43
|
+
value = subject.field_value 'asdf', :value => 'asdf'
|
44
|
+
expect(value).to eq 'asdf'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "checks for a helper method to call" do
|
48
|
+
allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
|
49
|
+
value = subject.field_value 'asdf'
|
50
|
+
expect(value).to eq 'custom asdf value'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "checks for a link_to_search" do
|
54
|
+
allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_search_true' => ['x'] }).and_return('/foo')
|
55
|
+
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
56
|
+
value = subject.field_value 'link_to_search_true'
|
57
|
+
expect(value).to eq 'bar'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "checks for a link_to_search with a field name" do
|
61
|
+
allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo')
|
62
|
+
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
63
|
+
value = subject.field_value 'link_to_search_named'
|
64
|
+
expect(value).to eq 'bar'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "gracefully handles when no highlight field is available" do
|
68
|
+
allow(document).to receive(:has_highlight_field?).and_return(false)
|
69
|
+
value = subject.field_value 'highlight'
|
70
|
+
expect(value).to be_blank
|
71
|
+
end
|
72
|
+
|
73
|
+
it "checks for a highlighted field" do
|
74
|
+
allow(document).to receive(:has_highlight_field?).and_return(true)
|
75
|
+
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
76
|
+
value = subject.field_value 'highlight'
|
77
|
+
expect(value).to eq '<em>highlight</em>'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "checks the document field value" do
|
81
|
+
value = subject.field_value 'qwer'
|
82
|
+
expect(value).to eq 'document qwer value'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "works with index fields that aren't explicitly defined" do
|
86
|
+
value = subject.field_value 'mnbv'
|
87
|
+
expect(value).to eq 'document mnbv value'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "calls an accessor on the solr document" do
|
91
|
+
allow(document).to receive_messages(solr_doc_accessor: "123")
|
92
|
+
value = subject.field_value 'solr_doc_accessor'
|
93
|
+
expect(value).to eq "123"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "calls an explicit accessor on the solr document" do
|
97
|
+
allow(document).to receive_messages(solr_doc_accessor: "123")
|
98
|
+
value = subject.field_value 'explicit_accessor'
|
99
|
+
expect(value).to eq "123"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "calls an accessor on the solr document with the field as an argument" do
|
103
|
+
allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
|
104
|
+
value = subject.field_value 'explicit_accessor_with_arg'
|
105
|
+
expect(value).to eq "123"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "supports solr field configuration" do
|
109
|
+
value = subject.field_value 'alias'
|
110
|
+
expect(value).to eq "document qwer value"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "supports default values in the field configuration" do
|
114
|
+
value = subject.field_value 'with_default'
|
115
|
+
expect(value).to eq "value"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#field_values' do
|
120
|
+
context 'for a field with the helper_method option' do
|
121
|
+
let(:field_name) { 'field_with_helper' }
|
122
|
+
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
|
123
|
+
|
124
|
+
before do
|
125
|
+
document['field_with_helper'] = 'value'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "checks call the helper method with arguments" do
|
129
|
+
allow(request_context).to receive(:render_field_with_helper) do |*args|
|
130
|
+
args.first
|
131
|
+
end
|
132
|
+
|
133
|
+
render_options = { a: 1 }
|
134
|
+
|
135
|
+
options = subject.send(:field_values, field_config, a: 1)
|
136
|
+
|
137
|
+
expect(options).to include :document, :field, :value, :config, :a
|
138
|
+
expect(options[:document]).to eq document
|
139
|
+
expect(options[:field]).to eq 'field_with_helper'
|
140
|
+
expect(options[:value]).to eq ['value']
|
141
|
+
expect(options[:config]).to eq field_config
|
142
|
+
expect(options[:a]).to eq 1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|