blacklight 6.4.0 → 6.5.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +11 -12
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_twitter_typeahead.scss +1 -1
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +1 -0
- data/app/controllers/concerns/blacklight/bookmarks.rb +8 -10
- data/app/controllers/concerns/blacklight/catalog.rb +10 -24
- data/app/helpers/blacklight/catalog_helper_behavior.rb +14 -6
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +5 -0
- data/app/models/concerns/blacklight/document/export.rb +16 -18
- data/app/models/search.rb +3 -7
- data/app/views/saved_searches/index.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/lib/blacklight/engine.rb +1 -0
- data/lib/blacklight/search_state.rb +10 -7
- data/spec/controllers/bookmarks_controller_spec.rb +6 -0
- data/spec/controllers/catalog_controller_spec.rb +97 -152
- data/spec/helpers/catalog_helper_spec.rb +36 -0
- data/spec/helpers/render_constraints_helper_spec.rb +8 -0
- data/spec/lib/blacklight/search_state_spec.rb +63 -29
- data/spec/models/blacklight/configuration_spec.rb +1 -1
- data/spec/support/backport_test.rb +9 -33
- data/template.demo.rb +0 -1
- metadata +5 -5
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
2
|
describe CatalogController do
|
|
3
|
+
let(:doc_id) { '2007020969' }
|
|
4
|
+
let(:mock_response) { double() }
|
|
5
|
+
let(:mock_document) { double() }
|
|
4
6
|
|
|
5
7
|
describe "index action" do
|
|
6
|
-
|
|
8
|
+
context "with format :html" do
|
|
7
9
|
let(:user_query) { 'history' } # query that will get results
|
|
8
10
|
|
|
9
11
|
it "has no search history if no search criteria" do
|
|
@@ -42,19 +44,18 @@ describe CatalogController do
|
|
|
42
44
|
page = 2
|
|
43
45
|
get :index, params: { page: page }
|
|
44
46
|
expect(assigns(:response).docs).to_not be_empty
|
|
45
|
-
expect(assigns(:response).params[:start].to_i).to eq (page-1) *
|
|
47
|
+
expect(assigns(:response).params[:start].to_i).to eq (page-1) * controller.blacklight_config[:default_solr_params][:rows]
|
|
46
48
|
assert_facets_have_values(assigns(:response).aggregations)
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
it "has no docs or facet values for query without results", :integration => true do
|
|
50
52
|
get :index, params: { q: 'sadfdsafasdfsadfsadfsadf' } # query for no results
|
|
51
|
-
|
|
52
53
|
expect(assigns(:response).docs).to be_empty
|
|
53
54
|
assigns(:response).aggregations.each do |key, facet|
|
|
54
55
|
expect(facet.items).to be_empty
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
|
-
|
|
58
|
+
|
|
58
59
|
it "shows 0 results when the user asks for an invalid value to a custom facet query", :integration => true do
|
|
59
60
|
get :index, params: { f: { example_query_facet_field: 'bogus' } } # bogus custom facet value
|
|
60
61
|
expect(assigns(:response).docs).to be_empty
|
|
@@ -66,7 +67,7 @@ describe CatalogController do
|
|
|
66
67
|
get :index, params: { f: {example_query_facet_field: 'years_5' } } # valid custom facet value with NO results
|
|
67
68
|
expect(assigns(:response).docs).to be_empty
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
it "has a spelling suggestion for an appropriately poor query", :integration => true do
|
|
71
72
|
get :index, params: { q: 'boo' }
|
|
72
73
|
expect(assigns(:response).spelling.words).to_not be_nil
|
|
@@ -80,7 +81,6 @@ describe CatalogController do
|
|
|
80
81
|
get :index, params: { q: user_query }
|
|
81
82
|
expect(session[:search]).to_not be_nil
|
|
82
83
|
expect(session[:search].keys).to include 'id'
|
|
83
|
-
|
|
84
84
|
search = Search.find(session[:search]['id'])
|
|
85
85
|
expect(search.query_params['q']).to eq user_query
|
|
86
86
|
end
|
|
@@ -125,8 +125,8 @@ describe CatalogController do
|
|
|
125
125
|
expect(response).to be_success
|
|
126
126
|
end
|
|
127
127
|
let(:json) { JSON.parse(response.body)['response'] }
|
|
128
|
-
let(:pages)
|
|
129
|
-
let(:docs)
|
|
128
|
+
let(:pages) { json["pages"] }
|
|
129
|
+
let(:docs) { json["docs"] }
|
|
130
130
|
let(:facets) { json["facets"] }
|
|
131
131
|
|
|
132
132
|
it "gets the pages" do
|
|
@@ -161,8 +161,8 @@ describe CatalogController do
|
|
|
161
161
|
let(:blacklight_config) { Blacklight::Configuration.new }
|
|
162
162
|
|
|
163
163
|
before :each do
|
|
164
|
-
allow(
|
|
165
|
-
allow(
|
|
164
|
+
allow(controller).to receive_messages blacklight_config: blacklight_config
|
|
165
|
+
allow(controller).to receive_messages search_results: [double, double]
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
it "does not render when the config is false" do
|
|
@@ -178,33 +178,29 @@ describe CatalogController do
|
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
it "passes a hash to the render call" do
|
|
181
|
-
blacklight_config.index.respond_to.yaml = {
|
|
181
|
+
blacklight_config.index.respond_to.yaml = { inline: '', layout: false }
|
|
182
182
|
get :index, params: { format: 'yaml' }
|
|
183
183
|
expect(response.body).to be_blank
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
it "evaluates a proc" do
|
|
187
|
-
blacklight_config.index.respond_to.yaml = lambda { render
|
|
187
|
+
blacklight_config.index.respond_to.yaml = lambda { render plain: "" }
|
|
188
188
|
get :index, params: { format: 'yaml' }
|
|
189
189
|
expect(response.body).to be_empty
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
it "with a symbol, it should call a controller method" do
|
|
193
193
|
expect(subject).to receive(:render_some_yaml) do
|
|
194
|
-
subject.
|
|
194
|
+
subject.head :ok, layout: false
|
|
195
195
|
end
|
|
196
|
-
|
|
197
196
|
blacklight_config.index.respond_to.yaml = :render_some_yaml
|
|
198
197
|
get :index, params: { format: 'yaml' }
|
|
199
198
|
expect(response.body).to be_blank
|
|
200
199
|
end
|
|
201
200
|
end
|
|
202
|
-
|
|
203
201
|
end # describe index action
|
|
204
202
|
|
|
205
203
|
describe "track action" do
|
|
206
|
-
doc_id = '2007020969'
|
|
207
|
-
|
|
208
204
|
it "persists the search session id value into session[:search]" do
|
|
209
205
|
put :track, params: { id: doc_id, counter: 3, search_id: "123" }
|
|
210
206
|
expect(session[:search]['id']).to eq "123"
|
|
@@ -214,7 +210,7 @@ describe CatalogController do
|
|
|
214
210
|
put :track, params: { id: doc_id, counter: 3 }
|
|
215
211
|
expect(session[:search]['counter']).to eq "3"
|
|
216
212
|
end
|
|
217
|
-
|
|
213
|
+
|
|
218
214
|
it "records the current per_page setting" do
|
|
219
215
|
put :track, params: { id: doc_id, counter: 3, per_page: 15 }
|
|
220
216
|
expect(session[:search]['per_page']).to eq "15"
|
|
@@ -243,9 +239,6 @@ describe CatalogController do
|
|
|
243
239
|
|
|
244
240
|
# SHOW ACTION
|
|
245
241
|
describe "show action" do
|
|
246
|
-
|
|
247
|
-
doc_id = '2007020969'
|
|
248
|
-
|
|
249
242
|
describe "with format :html" do
|
|
250
243
|
it "gets document", :integration => true do
|
|
251
244
|
get :show, params: { id: doc_id }
|
|
@@ -261,50 +254,48 @@ describe CatalogController do
|
|
|
261
254
|
expect(json["response"]["document"].keys).to match_array(["author_t", "opensearch_display", "marc_display", "published_display", "author_display", "lc_callnum_display", "title_t", "pub_date", "pub_date_sort", "subtitle_display", "format", "url_suppl_display", "material_type_display", "title_display", "subject_addl_t", "subject_t", "isbn_t", "id", "title_addl_t", "subject_geo_facet", "subject_topic_facet", "author_addl_t", "language_facet", "subtitle_t", "timestamp"])
|
|
262
255
|
end
|
|
263
256
|
end
|
|
264
|
-
|
|
257
|
+
|
|
265
258
|
describe "previous/next documents" do
|
|
259
|
+
let(:search_session) { { :id => current_search.id } }
|
|
260
|
+
let(:current_search) { Search.create(:query_params => { :q => ""}) }
|
|
266
261
|
before do
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
262
|
+
allow(mock_document).to receive_messages(:export_formats => {})
|
|
263
|
+
allow(controller).to receive_messages(
|
|
264
|
+
fetch: [mock_response, mock_document],
|
|
265
|
+
get_previous_and_next_documents_for_search: [double(:total => 5), [double("a"), mock_document, double("b")]],
|
|
266
|
+
current_search_session: current_search
|
|
267
|
+
)
|
|
268
|
+
end
|
|
269
|
+
it "sets previous document if counter present in session" do
|
|
270
|
+
session[:search] = search_session.merge('counter' => 2)
|
|
271
|
+
get :show, params: { id: doc_id }
|
|
272
|
+
expect(assigns[:previous_document]).to_not be_nil
|
|
273
|
+
end
|
|
274
|
+
it "does not set previous or next document if session is blank" do
|
|
275
|
+
get :show, params: { id: doc_id }
|
|
276
|
+
expect(assigns[:previous_document]).to be_nil
|
|
277
|
+
expect(assigns[:next_document]).to be_nil
|
|
278
|
+
end
|
|
279
|
+
it "does not set previous or next document if session[:search]['counter'] is nil" do
|
|
280
|
+
session[:search] = {}
|
|
281
|
+
get :show, params: { id: doc_id }
|
|
282
|
+
expect(assigns[:previous_document]).to be_nil
|
|
283
|
+
expect(assigns[:next_document]).to be_nil
|
|
284
|
+
end
|
|
285
|
+
it "sets next document if counter present in session" do
|
|
286
|
+
session[:search] = search_session.merge('counter' => 2)
|
|
287
|
+
get :show, params: { id: doc_id }
|
|
288
|
+
expect(assigns[:next_document]).to_not be_nil
|
|
277
289
|
end
|
|
278
|
-
it "sets previous document if counter present in session" do
|
|
279
|
-
session[:search] = @search_session.merge('counter' => 2)
|
|
280
|
-
get :show, params: { id: doc_id }
|
|
281
|
-
expect(assigns[:previous_document]).to_not be_nil
|
|
282
|
-
end
|
|
283
|
-
it "does not set previous or next document if session is blank" do
|
|
284
|
-
get :show, params: { id: doc_id }
|
|
285
|
-
expect(assigns[:previous_document]).to be_nil
|
|
286
|
-
expect(assigns[:next_document]).to be_nil
|
|
287
|
-
end
|
|
288
|
-
it "does not set previous or next document if session[:search]['counter'] is nil" do
|
|
289
|
-
session[:search] = {}
|
|
290
|
-
get :show, params: { id: doc_id }
|
|
291
|
-
expect(assigns[:previous_document]).to be_nil
|
|
292
|
-
expect(assigns[:next_document]).to be_nil
|
|
293
|
-
end
|
|
294
|
-
it "sets next document if counter present in session" do
|
|
295
|
-
session[:search] = @search_session.merge('counter' => 2)
|
|
296
|
-
get :show, params: { id: doc_id }
|
|
297
|
-
expect(assigns[:next_document]).to_not be_nil
|
|
298
|
-
end
|
|
299
290
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
291
|
+
it "does not break if solr returns an exception" do
|
|
292
|
+
allow(controller).to receive(:get_previous_and_next_documents_for_search) {
|
|
293
|
+
raise Blacklight::Exceptions::InvalidRequest.new "Error"
|
|
294
|
+
}
|
|
295
|
+
get :show, params: { id: doc_id }
|
|
296
|
+
expect(assigns[:previous_document]).to be_nil
|
|
297
|
+
expect(assigns[:next_document]).to be_nil
|
|
298
|
+
end
|
|
308
299
|
end
|
|
309
300
|
|
|
310
301
|
# NOTE: status code is always 200 in isolation mode ...
|
|
@@ -312,96 +303,61 @@ describe CatalogController do
|
|
|
312
303
|
get :show, params: { id: doc_id }
|
|
313
304
|
expect(response).to be_success
|
|
314
305
|
end
|
|
306
|
+
|
|
315
307
|
it "renders show.html.erb" do
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
allow(@mock_document).to receive_messages(:export_formats => {})
|
|
319
|
-
allow(controller).to receive_messages(fetch: [@mock_response, @mock_document])
|
|
308
|
+
allow(mock_document).to receive_messages(:export_formats => {})
|
|
309
|
+
allow(controller).to receive_messages(fetch: [mock_response, mock_document])
|
|
320
310
|
get :show, params: { id: doc_id }
|
|
321
311
|
expect(response).to render_template(:show)
|
|
322
312
|
end
|
|
323
313
|
|
|
324
314
|
describe "@document" do
|
|
325
315
|
before do
|
|
326
|
-
|
|
327
|
-
allow(
|
|
328
|
-
@mock_document = double()
|
|
329
|
-
allow(controller).to receive_messages(:find => @mock_response )
|
|
330
|
-
end
|
|
331
|
-
before(:each) do
|
|
316
|
+
allow(mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc')])
|
|
317
|
+
allow(controller).to receive_messages(:find => mock_response )
|
|
332
318
|
get :show, params: { id: doc_id }
|
|
333
|
-
@document = assigns[:document]
|
|
334
319
|
end
|
|
335
320
|
it "is a SolrDocument" do
|
|
336
|
-
expect(
|
|
321
|
+
expect(assigns[:document]).to be_instance_of(SolrDocument)
|
|
337
322
|
end
|
|
338
323
|
end
|
|
339
|
-
|
|
324
|
+
|
|
340
325
|
describe "with dynamic export formats" do
|
|
341
326
|
render_views
|
|
342
327
|
module FakeExtension
|
|
343
328
|
def self.extended(document)
|
|
344
329
|
document.will_export_as(:mock, "application/mock")
|
|
345
330
|
end
|
|
346
|
-
|
|
331
|
+
|
|
347
332
|
def export_as_mock
|
|
348
333
|
"mock_export"
|
|
349
334
|
end
|
|
350
335
|
end
|
|
351
|
-
|
|
352
|
-
before do
|
|
353
|
-
@mock_response = double()
|
|
354
|
-
allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }])
|
|
355
|
-
@mock_document = double()
|
|
356
|
-
allow(controller).to receive_messages(find: @mock_response)
|
|
357
|
-
end
|
|
358
336
|
|
|
359
|
-
before
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
ActionController.add_renderer :double do |template, options|
|
|
364
|
-
send_data "mock_export", :type => Mime::MOCK
|
|
365
|
-
end
|
|
337
|
+
before do
|
|
338
|
+
allow(mock_response).to receive_messages(:documents => [SolrDocument.new(id: 'my_fake_doc')])
|
|
339
|
+
allow(controller).to receive_messages(:find => mock_response,
|
|
340
|
+
:get_single_doc_via_search => mock_document)
|
|
366
341
|
Mime::Type.register "application/mock", :mock
|
|
367
|
-
|
|
368
342
|
SolrDocument.use_extension(FakeExtension)
|
|
369
343
|
end
|
|
370
|
-
|
|
371
|
-
before do
|
|
372
|
-
@mock_response = double()
|
|
373
|
-
allow(@mock_response).to receive_messages(:documents => [SolrDocument.new(id: 'my_fake_doc')])
|
|
374
|
-
@mock_document = double()
|
|
375
|
-
allow(controller).to receive_messages(:find => @mock_response,
|
|
376
|
-
:get_single_doc_via_search => @mock_document)
|
|
377
|
-
|
|
378
|
-
allow(controller).to receive_messages(:find => @mock_response,
|
|
379
|
-
:get_single_doc_via_search => @mock_document)
|
|
380
|
-
end
|
|
381
344
|
|
|
382
345
|
it "responds to an extension-registered format properly" do
|
|
383
346
|
get :show, params: { id: doc_id, format: 'mock' }
|
|
384
347
|
expect(response).to be_success
|
|
385
348
|
expect(response.body).to match /mock_export/
|
|
386
349
|
end
|
|
387
|
-
|
|
388
350
|
|
|
389
|
-
after
|
|
390
|
-
# remove the fake extension
|
|
391
|
-
SolrDocument.registered_extensions.pop
|
|
351
|
+
after do
|
|
352
|
+
SolrDocument.registered_extensions.pop # remove the fake extension
|
|
392
353
|
end
|
|
393
354
|
end # dynamic export formats
|
|
394
|
-
|
|
395
355
|
end # describe show action
|
|
396
356
|
|
|
397
357
|
describe "opensearch" do
|
|
398
358
|
before do
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
allow(@mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')])
|
|
402
|
-
@mock_document = double()
|
|
403
|
-
allow(controller).to receive_messages(find: @mock_response)
|
|
404
|
-
|
|
359
|
+
allow(mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')])
|
|
360
|
+
allow(controller).to receive_messages(find: mock_response)
|
|
405
361
|
end
|
|
406
362
|
it "returns an opensearch description" do
|
|
407
363
|
get :opensearch, params: { format: 'xml' }
|
|
@@ -414,7 +370,6 @@ describe CatalogController do
|
|
|
414
370
|
end
|
|
415
371
|
|
|
416
372
|
describe "email/sms" do
|
|
417
|
-
doc_id = '2007020969'
|
|
418
373
|
let(:mock_response) { double(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')]) }
|
|
419
374
|
before do
|
|
420
375
|
allow(controller).to receive_messages(find: mock_response)
|
|
@@ -436,10 +391,9 @@ describe CatalogController do
|
|
|
436
391
|
expect(request.flash[:error]).to be_nil
|
|
437
392
|
end
|
|
438
393
|
it "redirects back to the record upon success" do
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
394
|
+
allow(RecordMailer).to receive(:email_record)
|
|
395
|
+
.with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host'))
|
|
396
|
+
.and_return double(deliver: nil)
|
|
443
397
|
post :email, params: { id: doc_id, to: 'test_email@projectblacklight.org', message: 'xyz' }
|
|
444
398
|
expect(request.flash[:error]).to be_nil
|
|
445
399
|
expect(request).to redirect_to(solr_document_path(doc_id))
|
|
@@ -450,6 +404,7 @@ describe CatalogController do
|
|
|
450
404
|
expect(request.flash[:success]).to eq "Email Sent"
|
|
451
405
|
end
|
|
452
406
|
end
|
|
407
|
+
|
|
453
408
|
describe "sms" do
|
|
454
409
|
it "gives error if no phone number is given" do
|
|
455
410
|
post :sms, params: { id: doc_id, carrier: 'att' }
|
|
@@ -473,9 +428,10 @@ describe CatalogController do
|
|
|
473
428
|
expect(request).to redirect_to(solr_document_path(doc_id))
|
|
474
429
|
end
|
|
475
430
|
it "sends to the appropriate carrier email address" do
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
431
|
+
expect(RecordMailer)
|
|
432
|
+
.to receive(:sms_record)
|
|
433
|
+
.with(anything, { to: '5555555555@txt.att.net' }, hash_including(:host => 'test.host'))
|
|
434
|
+
.and_return double(:deliver => nil)
|
|
479
435
|
post :sms, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
|
|
480
436
|
end
|
|
481
437
|
it "redirects back to the record upon success" do
|
|
@@ -483,7 +439,6 @@ describe CatalogController do
|
|
|
483
439
|
expect(request.flash[:error]).to eq nil
|
|
484
440
|
expect(request).to redirect_to(solr_document_path(doc_id))
|
|
485
441
|
end
|
|
486
|
-
|
|
487
442
|
it "renders sms_success template for XHR requests" do
|
|
488
443
|
post :sms, xhr: true, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
|
|
489
444
|
expect(request).to render_template 'sms_success'
|
|
@@ -494,19 +449,17 @@ describe CatalogController do
|
|
|
494
449
|
|
|
495
450
|
describe "errors" do
|
|
496
451
|
it "returns status 404 for a record that doesn't exist" do
|
|
497
|
-
|
|
498
|
-
allow(controller).to receive_messages(:find => @mock_response)
|
|
452
|
+
allow(controller).to receive_messages(:find => double(documents: []))
|
|
499
453
|
get :show, params: { id: "987654321" }
|
|
500
454
|
expect(response.status).to eq 404
|
|
501
|
-
expect(response.content_type).to eq Mime
|
|
455
|
+
expect(response.content_type).to eq Mime[:html]
|
|
502
456
|
end
|
|
503
|
-
it "returns status 404 for a record that doesn't exist even for non-html format" do
|
|
504
|
-
@mock_response = double(documents: [])
|
|
505
|
-
allow(controller).to receive_messages(:find => @mock_response)
|
|
506
457
|
|
|
458
|
+
it "returns status 404 for a record that doesn't exist even for non-html format" do
|
|
459
|
+
allow(controller).to receive_messages(:find => double(documents: []))
|
|
507
460
|
get :show, params: { id: "987654321", format: "xml" }
|
|
508
461
|
expect(response.status).to eq 404
|
|
509
|
-
expect(response.content_type).to eq Mime
|
|
462
|
+
expect(response.content_type).to eq Mime[:xml]
|
|
510
463
|
end
|
|
511
464
|
|
|
512
465
|
it "redirects the user to the root url for a bad search" do
|
|
@@ -529,7 +482,6 @@ describe CatalogController do
|
|
|
529
482
|
allow(controller).to receive(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
|
|
530
483
|
expect { get :index, params: { q: '+' } }.to raise_error Blacklight::Exceptions::InvalidRequest
|
|
531
484
|
end
|
|
532
|
-
|
|
533
485
|
end
|
|
534
486
|
|
|
535
487
|
context "without a user authentication provider" do
|
|
@@ -578,7 +530,6 @@ describe CatalogController do
|
|
|
578
530
|
session[:history] = []
|
|
579
531
|
controller.send(:add_to_search_history, double(:id => 1))
|
|
580
532
|
expect(session[:history]).to have(1).item
|
|
581
|
-
|
|
582
533
|
controller.send(:add_to_search_history, double(:id => 2))
|
|
583
534
|
expect(session[:history]).to have(2).items
|
|
584
535
|
expect(session[:history].first).to eq 2
|
|
@@ -587,13 +538,11 @@ describe CatalogController do
|
|
|
587
538
|
it "removes searches from the list when the list gets too big" do
|
|
588
539
|
allow(controller).to receive(:blacklight_config).and_return(double(:search_history_window => 5))
|
|
589
540
|
session[:history] = (0..4).to_a.reverse
|
|
590
|
-
|
|
591
541
|
expect(session[:history]).to have(5).items
|
|
592
542
|
controller.send(:add_to_search_history, double(:id => 5))
|
|
593
543
|
controller.send(:add_to_search_history, double(:id => 6))
|
|
594
544
|
controller.send(:add_to_search_history, double(:id => 7))
|
|
595
545
|
expect(session[:history]).to include(*(3..7).to_a)
|
|
596
|
-
|
|
597
546
|
end
|
|
598
547
|
end
|
|
599
548
|
|
|
@@ -654,45 +603,42 @@ describe CatalogController do
|
|
|
654
603
|
|
|
655
604
|
describe "#add_show_tools_partial" do
|
|
656
605
|
before do
|
|
657
|
-
|
|
658
|
-
allow(controller).to receive(:perform_like)
|
|
606
|
+
described_class.add_show_tools_partial(:like, callback: :perform_like, validator: :validate_like_params)
|
|
659
607
|
allow(controller).to receive(:solr_document_url).and_return('catalog/1')
|
|
660
|
-
allow(controller).to receive(:action_documents).and_return(
|
|
608
|
+
allow(controller).to receive(:action_documents).and_return(1)
|
|
661
609
|
Rails.application.routes.draw do
|
|
662
610
|
get 'catalog/like', as: :catalog_like
|
|
663
611
|
end
|
|
664
612
|
end
|
|
665
613
|
|
|
666
614
|
after do
|
|
667
|
-
|
|
615
|
+
described_class.blacklight_config.show.document_actions.delete(:like)
|
|
668
616
|
Rails.application.reload_routes!
|
|
669
617
|
end
|
|
670
618
|
|
|
671
619
|
it "adds the action to a list" do
|
|
672
|
-
expect(
|
|
620
|
+
expect(described_class.blacklight_config.show.document_actions).to have_key(:like)
|
|
673
621
|
end
|
|
674
622
|
|
|
675
623
|
it "defines the action method" do
|
|
676
|
-
expect(controller.respond_to
|
|
624
|
+
expect(controller).to respond_to(:like)
|
|
677
625
|
end
|
|
678
626
|
|
|
679
627
|
describe "when posting to the action" do
|
|
680
|
-
|
|
681
|
-
before do
|
|
682
|
-
allow(controller).to receive(:validate_like_params).and_return(true)
|
|
683
|
-
post :like
|
|
684
|
-
end
|
|
628
|
+
context 'with valid params' do
|
|
685
629
|
it "calls the supplied method on post" do
|
|
686
|
-
expect(controller).to
|
|
630
|
+
expect(controller).to receive(:validate_like_params).and_return(true)
|
|
631
|
+
expect(controller).to receive(:perform_like)
|
|
632
|
+
post :like
|
|
687
633
|
end
|
|
688
634
|
end
|
|
689
635
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
636
|
+
context "with failure on invalid params" do
|
|
637
|
+
it "does not call the supplied method" do
|
|
638
|
+
expect(controller).to receive(:validate_like_params).and_return(false)
|
|
639
|
+
expect(controller).not_to receive(:perform_like)
|
|
640
|
+
skip 'Clarify expectations on validator failure: 400? 500? Set a specific error key/msg? Render the same template anyway?'
|
|
641
|
+
post :like
|
|
696
642
|
end
|
|
697
643
|
end
|
|
698
644
|
end
|
|
@@ -713,7 +659,6 @@ describe CatalogController do
|
|
|
713
659
|
end
|
|
714
660
|
end
|
|
715
661
|
|
|
716
|
-
|
|
717
662
|
# there must be at least one facet, and each facet must have at least one value
|
|
718
663
|
def assert_facets_have_values(aggregations)
|
|
719
664
|
expect(aggregations).to_not be_empty
|
|
@@ -129,6 +129,42 @@ describe CatalogHelper do
|
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
+
describe "rss_feed_link_tag" do
|
|
133
|
+
context "when an alternate scope is passed in" do
|
|
134
|
+
let(:my_engine) { double("Engine") }
|
|
135
|
+
let(:query_params) { { controller: 'catalog', action: 'index' } }
|
|
136
|
+
let(:config) { Blacklight::Configuration.new }
|
|
137
|
+
let(:search_state) { Blacklight::SearchState.new(query_params, config) }
|
|
138
|
+
|
|
139
|
+
it "calls url_for on the engine scope" do
|
|
140
|
+
allow(helper).to receive(:search_state).and_return search_state
|
|
141
|
+
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
|
|
142
|
+
tag = helper.rss_feed_link_tag(route_set: my_engine)
|
|
143
|
+
expect(tag).to match /title="RSS for results"/
|
|
144
|
+
expect(tag).to match /rel="alternate"/
|
|
145
|
+
expect(tag).to match %r{type="application/rss\+xml"}
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe "atom_feed_link_tag" do
|
|
151
|
+
context "when an alternate scope is passed in" do
|
|
152
|
+
let(:my_engine) { double("Engine") }
|
|
153
|
+
let(:query_params) { { controller: 'catalog', action: 'index' } }
|
|
154
|
+
let(:config) { Blacklight::Configuration.new }
|
|
155
|
+
let(:search_state) { Blacklight::SearchState.new(query_params, config) }
|
|
156
|
+
|
|
157
|
+
it "calls url_for on the engine scope" do
|
|
158
|
+
allow(helper).to receive(:search_state).and_return search_state
|
|
159
|
+
expect(my_engine).to receive(:url_for).and_return(url_for(query_params))
|
|
160
|
+
tag = helper.atom_feed_link_tag(route_set: my_engine)
|
|
161
|
+
expect(tag).to match /title="Atom for results"/
|
|
162
|
+
expect(tag).to match /rel="alternate"/
|
|
163
|
+
expect(tag).to match %r{type="application/atom\+xml"}
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
132
168
|
describe "should_autofocus_on_search_box?" do
|
|
133
169
|
it "is focused if we're on a catalog-like index page without query or facet parameters" do
|
|
134
170
|
allow(helper).to receive_messages(controller: CatalogController.new, action_name: "index", has_search_parameters?: false)
|
|
@@ -25,6 +25,14 @@ describe RenderConstraintsHelper do
|
|
|
25
25
|
expect(subject).to have_selector "a[href='/?f%5Btype%5D=journal']"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
context 'with an ordinary hash' do
|
|
29
|
+
let(:params) { { q: 'foobar', f: { type: 'journal' } } }
|
|
30
|
+
|
|
31
|
+
it "has a link relative to the current url" do
|
|
32
|
+
expect(subject).to have_selector "a[href='/?f%5Btype%5D=journal']"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
28
36
|
context "with a route_set" do
|
|
29
37
|
let(:params) { ActionController::Parameters.new(q: 'foobar', f: { type: 'journal' }, route_set: my_engine) }
|
|
30
38
|
it "accepts an optional route set" do
|