blacklight 4.2.2 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/Gemfile +6 -0
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +2 -2
- data/app/assets/stylesheets/blacklight/_header.css.scss +15 -31
- data/app/assets/stylesheets/blacklight/_modal.css.scss +4 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +8 -3
- data/app/helpers/blacklight/facets_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +5 -4
- data/app/views/catalog/_home.html.erb +1 -5
- data/app/views/catalog/show.html.erb +2 -3
- data/app/views/search_history/index.html.erb +2 -6
- data/blacklight.gemspec +1 -1
- data/gemfiles/rails3.gemfile +6 -1
- data/gemfiles/rails4.gemfile +5 -0
- data/lib/blacklight/catalog.rb +4 -8
- data/lib/blacklight/configuration/facet_field.rb +1 -1
- data/lib/blacklight/configuration/search_field.rb +2 -2
- data/lib/blacklight/configuration/solr_field.rb +11 -2
- data/lib/blacklight/configuration/sort_field.rb +1 -1
- data/lib/generators/blacklight/blacklight_generator.rb +3 -7
- data/lib/generators/blacklight/templates/config/solr.yml +1 -1
- data/lib/solrmarc.log.1 +854 -0
- data/spec/controllers/bookmarks_controller_spec.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +20 -20
- data/spec/helpers/blacklight_helper_spec.rb +44 -31
- data/spec/helpers/catalog_helper_spec.rb +5 -5
- data/spec/helpers/facets_helper_spec.rb +48 -48
- data/spec/helpers/search_history_constraints_helper_spec.rb +14 -3
- data/spec/lib/blacklight_solr_document_more_like_this_spec.rb +1 -1
- data/spec/lib/blacklight_solr_response_spec.rb +1 -1
- data/spec/lib/search_fields_spec.rb +1 -1
- data/spec/lib/solr_helper_spec.rb +4 -4
- data/spec/models/solr_docment_spec.rb +1 -1
- data/spec/test_app_templates/Gemfile.extra +4 -11
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -2
- data/spec/test_app_templates/lib/tasks/blacklight_test_app.rake +22 -0
- data/spec/views/catalog/_facets.html.erb_spec.rb +6 -6
- data/spec/views/catalog/_index_default.erb_spec.rb +11 -13
- data/spec/views/catalog/_show_default.erb_spec.rb +11 -13
- data/spec/views/catalog/index.atom.builder_spec.rb +2 -2
- data/tasks/blacklight.rake +7 -4
- metadata +7 -6
- data/spec/test_app_templates/lib/tasks/rspec.rake +0 -8
@@ -29,7 +29,7 @@ describe BookmarksController do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "has a 500 status code when delete is not success" do
|
32
|
-
bm =
|
32
|
+
bm = double(Bookmark)
|
33
33
|
@controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
|
34
34
|
@controller.stub_chain(:current_or_guest_user, :bookmarks, :delete).and_return(false)
|
35
35
|
|
@@ -166,8 +166,8 @@ describe CatalogController do
|
|
166
166
|
|
167
167
|
describe "previous/next documents" do
|
168
168
|
before do
|
169
|
-
@mock_response =
|
170
|
-
@mock_document =
|
169
|
+
@mock_response = double()
|
170
|
+
@mock_document = double()
|
171
171
|
@mock_document.stub(:export_formats => {})
|
172
172
|
controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
|
173
173
|
:get_single_doc_via_search => @mock_document)
|
@@ -212,8 +212,8 @@ describe CatalogController do
|
|
212
212
|
response.should be_success
|
213
213
|
end
|
214
214
|
it "should render show.html.erb" do
|
215
|
-
@mock_response =
|
216
|
-
@mock_document =
|
215
|
+
@mock_response = double()
|
216
|
+
@mock_document = double()
|
217
217
|
@mock_document.stub(:export_formats => {})
|
218
218
|
controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
|
219
219
|
:get_single_doc_via_search => @mock_document)
|
@@ -224,7 +224,7 @@ describe CatalogController do
|
|
224
224
|
describe "@document" do
|
225
225
|
before do
|
226
226
|
@mock_response.stub(:docs => [{ :id => 'my_fake_doc' }])
|
227
|
-
@mock_document =
|
227
|
+
@mock_document = double()
|
228
228
|
controller.stub(:find => @mock_response,
|
229
229
|
:get_single_doc_via_search => @mock_document)
|
230
230
|
end
|
@@ -250,7 +250,7 @@ describe CatalogController do
|
|
250
250
|
end
|
251
251
|
before do
|
252
252
|
@mock_response.stub(:docs => [{ :id => 'my_fake_doc' }])
|
253
|
-
@mock_document =
|
253
|
+
@mock_document = double()
|
254
254
|
controller.stub(:find => @mock_response,
|
255
255
|
:get_single_doc_via_search => @mock_document)
|
256
256
|
|
@@ -262,7 +262,7 @@ describe CatalogController do
|
|
262
262
|
|
263
263
|
# Rails3 needs this to propertly setup a new mime type and
|
264
264
|
# render the results.
|
265
|
-
ActionController.add_renderer :
|
265
|
+
ActionController.add_renderer :double do |template, options|
|
266
266
|
send_data "mock_export", :type => Mime::MOCK
|
267
267
|
end
|
268
268
|
Mime::Type.register "application/mock", :mock
|
@@ -286,10 +286,10 @@ describe CatalogController do
|
|
286
286
|
|
287
287
|
describe "opensearch" do
|
288
288
|
before do
|
289
|
-
@mock_response =
|
290
|
-
@mock_document =
|
289
|
+
@mock_response = double()
|
290
|
+
@mock_document = double()
|
291
291
|
@mock_response.stub(:docs => [{ :id => 'my_fake_doc' }, { :id => 'my_other_doc'}])
|
292
|
-
@mock_document =
|
292
|
+
@mock_document = double()
|
293
293
|
controller.stub(:find => @mock_response,
|
294
294
|
:get_single_doc_via_search => @mock_document)
|
295
295
|
end
|
@@ -306,10 +306,10 @@ describe CatalogController do
|
|
306
306
|
describe "email/sms" do
|
307
307
|
doc_id = '2007020969'
|
308
308
|
before do
|
309
|
-
@mock_response =
|
310
|
-
@mock_document =
|
309
|
+
@mock_response = double()
|
310
|
+
@mock_document = double()
|
311
311
|
@mock_response.stub(:docs => [{ :id => 'my_fake_doc' }, { :id => 'my_other_doc'}])
|
312
|
-
@mock_document =
|
312
|
+
@mock_document = double()
|
313
313
|
controller.stub(:find => @mock_response,
|
314
314
|
:get_single_doc_via_search => @mock_document)
|
315
315
|
end
|
@@ -365,14 +365,14 @@ describe CatalogController do
|
|
365
365
|
|
366
366
|
describe "errors" do
|
367
367
|
it "should return status 404 for a record that doesn't exist" do
|
368
|
-
@mock_response =
|
368
|
+
@mock_response = double()
|
369
369
|
@mock_response.stub(:docs => [])
|
370
|
-
@mock_document =
|
370
|
+
@mock_document = double()
|
371
371
|
controller.stub(:find => @mock_response,
|
372
372
|
:get_single_doc_via_search => @mock_document)
|
373
373
|
get :show, :id=>"987654321"
|
374
374
|
request.flash[:notice].should == "Sorry, you have requested a record that doesn't exist."
|
375
|
-
response.
|
375
|
+
response.should render_template('index')
|
376
376
|
response.status.should == 404
|
377
377
|
end
|
378
378
|
it "should redirect the user to the root url for a bad search" do
|
@@ -394,7 +394,7 @@ describe CatalogController do
|
|
394
394
|
res = {}
|
395
395
|
fake_error = RSolr::Error::Http.new(req, res)
|
396
396
|
controller.stub(:get_search_results) { |*args| raise fake_error }
|
397
|
-
controller.flash.stub
|
397
|
+
controller.flash.stub(:sweep)
|
398
398
|
controller.stub(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
|
399
399
|
expect {
|
400
400
|
get :index, :q=>"+"
|
@@ -408,10 +408,10 @@ describe CatalogController do
|
|
408
408
|
|
409
409
|
before do
|
410
410
|
controller.stub(:has_user_authentication_provider?) { false }
|
411
|
-
@mock_response =
|
412
|
-
@mock_document =
|
411
|
+
@mock_response = double()
|
412
|
+
@mock_document = double()
|
413
413
|
@mock_response.stub(:docs => [], :total => 1, :facets => [], :facet_queries => {}, :facet_by_field_name => nil)
|
414
|
-
@mock_document =
|
414
|
+
@mock_document = double()
|
415
415
|
controller.stub(:find => @mock_response,
|
416
416
|
:get_single_doc_via_search => @mock_document)
|
417
417
|
end
|
@@ -235,17 +235,17 @@ describe BlacklightHelper do
|
|
235
235
|
|
236
236
|
describe "render body class" do
|
237
237
|
it "should include a serialization of the current controller name" do
|
238
|
-
@controller =
|
239
|
-
@controller.
|
240
|
-
@controller.
|
238
|
+
@controller = double("controller")
|
239
|
+
@controller.stub(:controller_name).and_return("123456")
|
240
|
+
@controller.stub(:action_name).and_return("abcdef")
|
241
241
|
|
242
242
|
render_body_class.split(' ').should include('blacklight-123456')
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should include a serialization of the current action name" do
|
246
|
-
@controller =
|
247
|
-
@controller.
|
248
|
-
@controller.
|
246
|
+
@controller = double("controller")
|
247
|
+
@controller.stub(:controller_name).and_return("123456")
|
248
|
+
@controller.stub(:action_name).and_return("abcdef")
|
249
249
|
|
250
250
|
render_body_class.split(' ').should include('blacklight-123456-abcdef')
|
251
251
|
end
|
@@ -305,20 +305,16 @@ describe BlacklightHelper do
|
|
305
305
|
describe "render_document_index" do
|
306
306
|
it "should render the document_list" do
|
307
307
|
@document_list = ['a', 'b']
|
308
|
-
self.stub!(:document_index_view_type) { "gallery" }
|
309
308
|
self.should_receive(:render).with(hash_including(:partial => 'document_gallery'))
|
310
|
-
|
309
|
+
render_document_index_with_view 'gallery', @document_list
|
311
310
|
end
|
312
311
|
|
313
312
|
it "should fall back on more specific templates" do
|
314
|
-
@document_list = ['a', 'b']
|
315
|
-
self.stub!(:document_index_view_type) { "gallery" }
|
316
|
-
|
317
313
|
ex = ActionView::MissingTemplate.new [], '', '', '',''
|
318
314
|
self.should_receive(:render).with(hash_including(:partial => 'document_gallery')).and_raise(ex)
|
319
315
|
self.should_receive(:render).with(hash_including(:partial => 'catalog/document_gallery')).and_raise(ex)
|
320
316
|
self.should_receive(:render).with(hash_including(:partial => 'catalog/document_list'))
|
321
|
-
|
317
|
+
render_document_index_with_view 'gallery', @document_list
|
322
318
|
end
|
323
319
|
end
|
324
320
|
|
@@ -416,7 +412,7 @@ describe BlacklightHelper do
|
|
416
412
|
@doc_id = "MOCK_ID1"
|
417
413
|
@document = MockDocumentAppHelper.new(:id => @doc_id)
|
418
414
|
render_params = {:controller => "controller", :action => "action"}
|
419
|
-
helper.stub
|
415
|
+
helper.stub(:params).and_return(render_params)
|
420
416
|
end
|
421
417
|
it "generates <link rel=alternate> tags" do
|
422
418
|
|
@@ -489,37 +485,46 @@ describe BlacklightHelper do
|
|
489
485
|
end
|
490
486
|
|
491
487
|
it "should check for an explicit value" do
|
492
|
-
doc =
|
488
|
+
doc = double()
|
493
489
|
doc.should_not_receive(:get).with('asdf', :sep => nil)
|
494
490
|
value = helper.render_index_field_value :value => 'asdf', :document => doc, :field => 'asdf'
|
495
491
|
value.should == 'asdf'
|
496
492
|
end
|
497
493
|
|
498
494
|
it "should check for a helper method to call" do
|
499
|
-
doc =
|
495
|
+
doc = double()
|
500
496
|
doc.should_not_receive(:get).with('asdf', :sep => nil)
|
501
497
|
helper.stub(:render_asdf_index_field).and_return('custom asdf value')
|
502
498
|
value = helper.render_index_field_value :document => doc, :field => 'asdf'
|
503
499
|
value.should == 'custom asdf value'
|
504
500
|
end
|
505
501
|
|
502
|
+
it "should gracefully handle when no highlight field is available" do
|
503
|
+
doc = double()
|
504
|
+
doc.should_not_receive(:get)
|
505
|
+
doc.should_receive(:has_highlight_field?).and_return(false)
|
506
|
+
value = helper.render_index_field_value :document => doc, :field => 'highlight'
|
507
|
+
value.should be_blank
|
508
|
+
end
|
509
|
+
|
506
510
|
it "should check for a highlighted field" do
|
507
|
-
doc =
|
511
|
+
doc = double()
|
508
512
|
doc.should_not_receive(:get)
|
513
|
+
doc.should_receive(:has_highlight_field?).and_return(true)
|
509
514
|
doc.should_receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
510
515
|
value = helper.render_index_field_value :document => doc, :field => 'highlight'
|
511
516
|
value.should == '<em>highlight</em>'
|
512
517
|
end
|
513
518
|
|
514
519
|
it "should check the document field value" do
|
515
|
-
doc =
|
520
|
+
doc = double()
|
516
521
|
doc.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
|
517
522
|
value = helper.render_index_field_value :document => doc, :field => 'qwer'
|
518
523
|
value.should == 'document qwer value'
|
519
524
|
end
|
520
525
|
|
521
526
|
it "should work with index fields that aren't explicitly defined" do
|
522
|
-
doc =
|
527
|
+
doc = double()
|
523
528
|
doc.should_receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
|
524
529
|
value = helper.render_index_field_value :document => doc, :field => 'mnbv'
|
525
530
|
value.should == 'document mnbv value'
|
@@ -538,7 +543,7 @@ describe BlacklightHelper do
|
|
538
543
|
end
|
539
544
|
|
540
545
|
it "should check for an explicit value" do
|
541
|
-
doc =
|
546
|
+
doc = double()
|
542
547
|
doc.should_not_receive(:get).with('asdf', :sep => nil)
|
543
548
|
helper.should_not_receive(:render_asdf_document_show_field)
|
544
549
|
value = helper.render_document_show_field_value :value => 'asdf', :document => doc, :field => 'asdf'
|
@@ -546,17 +551,25 @@ describe BlacklightHelper do
|
|
546
551
|
end
|
547
552
|
|
548
553
|
it "should check for a helper method to call" do
|
549
|
-
doc =
|
554
|
+
doc = double()
|
550
555
|
doc.should_not_receive(:get).with('asdf', :sep => nil)
|
551
556
|
helper.stub(:render_asdf_document_show_field).and_return('custom asdf value')
|
552
557
|
value = helper.render_document_show_field_value :document => doc, :field => 'asdf'
|
553
558
|
value.should == 'custom asdf value'
|
554
559
|
end
|
555
560
|
|
561
|
+
it "should gracefully handle when no highlight field is available" do
|
562
|
+
doc = double()
|
563
|
+
doc.should_not_receive(:get)
|
564
|
+
doc.should_receive(:has_highlight_field?).and_return(false)
|
565
|
+
value = helper.render_document_show_field_value :document => doc, :field => 'highlight'
|
566
|
+
value.should be_blank
|
567
|
+
end
|
556
568
|
|
557
569
|
it "should check for a highlighted field" do
|
558
|
-
doc =
|
570
|
+
doc = double()
|
559
571
|
doc.should_not_receive(:get)
|
572
|
+
doc.should_receive(:has_highlight_field?).and_return(true)
|
560
573
|
doc.should_receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
561
574
|
value = helper.render_document_show_field_value :document => doc, :field => 'highlight'
|
562
575
|
value.should == '<em>highlight</em>'
|
@@ -564,14 +577,14 @@ describe BlacklightHelper do
|
|
564
577
|
|
565
578
|
|
566
579
|
it "should check the document field value" do
|
567
|
-
doc =
|
580
|
+
doc = double()
|
568
581
|
doc.should_receive(:get).with('qwer', :sep => nil).and_return('document qwer value')
|
569
582
|
value = helper.render_document_show_field_value :document => doc, :field => 'qwer'
|
570
583
|
value.should == 'document qwer value'
|
571
584
|
end
|
572
585
|
|
573
586
|
it "should work with show fields that aren't explicitly defined" do
|
574
|
-
doc =
|
587
|
+
doc = double()
|
575
588
|
doc.should_receive(:get).with('mnbv', :sep => nil).and_return('document mnbv value')
|
576
589
|
value = helper.render_document_show_field_value :document => doc, :field => 'mnbv'
|
577
590
|
value.should == 'document mnbv value'
|
@@ -580,17 +593,17 @@ describe BlacklightHelper do
|
|
580
593
|
|
581
594
|
describe "#should_render_index_field?" do
|
582
595
|
it "should if the document has the field value" do
|
583
|
-
doc =
|
596
|
+
doc = double()
|
584
597
|
doc.stub(:has?).with('asdf').and_return(true)
|
585
|
-
field_config =
|
598
|
+
field_config = double(:field => 'asdf')
|
586
599
|
helper.should_render_index_field?(doc, field_config).should == true
|
587
600
|
end
|
588
601
|
|
589
602
|
it "should if the document has a highlight field value" do
|
590
|
-
doc =
|
603
|
+
doc = double()
|
591
604
|
doc.stub(:has?).with('asdf').and_return(false)
|
592
605
|
doc.stub(:has_highlight_field?).with('asdf').and_return(true)
|
593
|
-
field_config =
|
606
|
+
field_config = double(:field => 'asdf', :highlight => true)
|
594
607
|
helper.should_render_index_field?(doc, field_config).should == true
|
595
608
|
end
|
596
609
|
end
|
@@ -598,17 +611,17 @@ describe BlacklightHelper do
|
|
598
611
|
|
599
612
|
describe "#should_render_show_field?" do
|
600
613
|
it "should if the document has the field value" do
|
601
|
-
doc =
|
614
|
+
doc = double()
|
602
615
|
doc.stub(:has?).with('asdf').and_return(true)
|
603
|
-
field_config =
|
616
|
+
field_config = double(:field => 'asdf')
|
604
617
|
helper.should_render_show_field?(doc, field_config).should == true
|
605
618
|
end
|
606
619
|
|
607
620
|
it "should if the document has a highlight field value" do
|
608
|
-
doc =
|
621
|
+
doc = double()
|
609
622
|
doc.stub(:has?).with('asdf').and_return(false)
|
610
623
|
doc.stub(:has_highlight_field?).with('asdf').and_return(true)
|
611
|
-
field_config =
|
624
|
+
field_config = double(:field => 'asdf', :highlight => true)
|
612
625
|
helper.should_render_show_field?(doc, field_config).should == true
|
613
626
|
end
|
614
627
|
end
|
@@ -10,11 +10,11 @@ describe CatalogHelper do
|
|
10
10
|
total = args[:total]
|
11
11
|
start = (current_page - 1) * per_page
|
12
12
|
|
13
|
-
mock_response =
|
14
|
-
mock_response.stub
|
15
|
-
mock_response.stub
|
16
|
-
mock_response.stub
|
17
|
-
mock_response.stub
|
13
|
+
mock_response = double("Blacklight::SolrResponse")
|
14
|
+
mock_response.stub(:total).and_return(total)
|
15
|
+
mock_response.stub(:rows).and_return(per_page)
|
16
|
+
mock_response.stub(:start).and_return(start)
|
17
|
+
mock_response.stub(:docs).and_return((1..total).to_a.slice(start, per_page))
|
18
18
|
|
19
19
|
mock_response
|
20
20
|
end
|
@@ -9,9 +9,9 @@ describe FacetsHelper do
|
|
9
9
|
describe "has_facet_values?" do
|
10
10
|
it "should be true if there are any facets to display" do
|
11
11
|
|
12
|
-
a =
|
13
|
-
b =
|
14
|
-
empty =
|
12
|
+
a = double(:items => [1,2])
|
13
|
+
b = double(:items => ['b','c'])
|
14
|
+
empty = double(:items => [])
|
15
15
|
|
16
16
|
fields = [a,b,empty]
|
17
17
|
helper.has_facet_values?(fields).should be_true
|
@@ -19,7 +19,7 @@ describe FacetsHelper do
|
|
19
19
|
|
20
20
|
it "should be false if all facets are empty" do
|
21
21
|
|
22
|
-
empty =
|
22
|
+
empty = double(:items => [])
|
23
23
|
|
24
24
|
fields = [empty]
|
25
25
|
helper.has_facet_values?(fields).should_not be_true
|
@@ -36,34 +36,34 @@ describe FacetsHelper do
|
|
36
36
|
helper.stub(:blacklight_config => @config)
|
37
37
|
end
|
38
38
|
it "should render facets with items" do
|
39
|
-
a =
|
39
|
+
a = double(:items => [1,2], :name=>'basic_field')
|
40
40
|
helper.should_render_facet?(a).should == true
|
41
41
|
end
|
42
42
|
it "should not render facets without items" do
|
43
|
-
empty =
|
43
|
+
empty = double(:items => [], :name=>'basic_field')
|
44
44
|
helper.should_render_facet?(empty).should == false
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not render facets where show is set to false" do
|
48
|
-
a =
|
48
|
+
a = double(:items => [1,2], :name=>'no_show')
|
49
49
|
helper.should_render_facet?(a).should == false
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "facet_by_field_name" do
|
54
54
|
it "should retrieve the facet from the response given a string" do
|
55
|
-
facet_config =
|
56
|
-
facet_field =
|
55
|
+
facet_config = double(:query => nil)
|
56
|
+
facet_field = double()
|
57
57
|
helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
58
58
|
|
59
|
-
@response =
|
59
|
+
@response = double()
|
60
60
|
@response.should_receive(:facet_by_field_name).with('a').and_return(facet_field)
|
61
61
|
|
62
62
|
helper.facet_by_field_name('a').should == facet_field
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should also work for facet query fields" do
|
66
|
-
facet_config =
|
66
|
+
facet_config = double(:query => {})
|
67
67
|
helper.should_receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
|
68
68
|
helper.should_receive(:create_rsolr_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
|
69
69
|
|
@@ -72,7 +72,7 @@ describe FacetsHelper do
|
|
72
72
|
|
73
73
|
describe "query facets" do
|
74
74
|
let(:facet_config) {
|
75
|
-
|
75
|
+
double(
|
76
76
|
:query => {
|
77
77
|
'a_simple_query' => { :fq => 'field:search', :label => 'A Human Readable label'},
|
78
78
|
'another_query' => { :fq => 'field:different_search', :label => 'Label'},
|
@@ -84,7 +84,7 @@ describe FacetsHelper do
|
|
84
84
|
before(:each) do
|
85
85
|
helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
86
86
|
|
87
|
-
@response =
|
87
|
+
@response = double(:facet_queries => {
|
88
88
|
'field:search' => 10,
|
89
89
|
'field:different_search' => 2,
|
90
90
|
'field:not_appearing_in_the_config' => 50,
|
@@ -92,7 +92,7 @@ describe FacetsHelper do
|
|
92
92
|
})
|
93
93
|
end
|
94
94
|
|
95
|
-
it"should convert the query facets into a
|
95
|
+
it"should convert the query facets into a double RSolr FacetField" do
|
96
96
|
field = helper.facet_by_field_name('my_query_facet_field')
|
97
97
|
field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
98
98
|
|
@@ -110,16 +110,16 @@ describe FacetsHelper do
|
|
110
110
|
|
111
111
|
describe "pivot facets" do
|
112
112
|
let(:facet_config) {
|
113
|
-
|
113
|
+
double(:pivot => ['field_a', 'field_b'])
|
114
114
|
}
|
115
115
|
|
116
116
|
before(:each) do
|
117
117
|
helper.should_receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
118
118
|
|
119
|
-
@response =
|
119
|
+
@response = double(:facet_pivot => { 'field_a,field_b' => [{:field => 'field_a', :value => 'a', :count => 10, :pivot => [{:field => 'field_b', :value => 'b', :count => 2}]}]})
|
120
120
|
end
|
121
121
|
|
122
|
-
it "should convert the pivot facet into a
|
122
|
+
it "should convert the pivot facet into a double RSolr FacetField" do
|
123
123
|
field = helper.facet_by_field_name('my_pivot_facet_field')
|
124
124
|
field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
125
125
|
|
@@ -138,9 +138,9 @@ describe FacetsHelper do
|
|
138
138
|
|
139
139
|
describe "render_facet_partials" do
|
140
140
|
it "should try to render all provided facets " do
|
141
|
-
a =
|
142
|
-
b =
|
143
|
-
empty =
|
141
|
+
a = double(:items => [1,2])
|
142
|
+
b = double(:items => ['b','c'])
|
143
|
+
empty = double(:items => [])
|
144
144
|
|
145
145
|
fields = [a,b,empty]
|
146
146
|
|
@@ -152,8 +152,8 @@ describe FacetsHelper do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should default to the configured facets" do
|
155
|
-
a =
|
156
|
-
b =
|
155
|
+
a = double(:items => [1,2])
|
156
|
+
b = double(:items => ['b','c'])
|
157
157
|
helper.should_receive(:facet_field_names) { [a,b] }
|
158
158
|
|
159
159
|
helper.should_receive(:render_facet_limit).with(a, {})
|
@@ -175,11 +175,11 @@ describe FacetsHelper do
|
|
175
175
|
end
|
176
176
|
|
177
177
|
helper.stub(:blacklight_config => @config)
|
178
|
-
@response =
|
178
|
+
@response = double()
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should set basic local variables" do
|
182
|
-
@mock_facet =
|
182
|
+
@mock_facet = double(:name => 'basic_field', :items => [1,2,3])
|
183
183
|
helper.should_receive(:render).with(hash_including(:partial => 'facet_limit',
|
184
184
|
:locals => {
|
185
185
|
:solr_field => 'basic_field',
|
@@ -197,37 +197,37 @@ describe FacetsHelper do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should render a facet _not_ declared in the configuration" do
|
200
|
-
@mock_facet =
|
200
|
+
@mock_facet = double(:name => 'asdf', :items => [1,2,3])
|
201
201
|
helper.should_receive(:render).with(hash_including(:partial => 'facet_limit'))
|
202
202
|
helper.render_facet_limit(@mock_facet)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should get the partial name from the configuration" do
|
206
|
-
@mock_facet =
|
206
|
+
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
207
207
|
helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
|
208
208
|
helper.render_facet_limit(@mock_facet)
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should use a partial layout for rendering the facet frame" do
|
212
|
-
@mock_facet =
|
212
|
+
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
213
213
|
helper.should_receive(:render).with(hash_including(:layout => 'facet_layout'))
|
214
214
|
helper.render_facet_limit(@mock_facet)
|
215
215
|
end
|
216
216
|
|
217
217
|
it "should allow the caller to opt-out of facet layouts" do
|
218
|
-
@mock_facet =
|
218
|
+
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
219
219
|
helper.should_receive(:render).with(hash_including(:layout => nil))
|
220
220
|
helper.render_facet_limit(@mock_facet, :layout => nil)
|
221
221
|
end
|
222
222
|
|
223
223
|
it "should render the facet_pivot partial for pivot facets" do
|
224
|
-
@mock_facet =
|
224
|
+
@mock_facet = double(:name => 'pivot_facet_field', :items => [1,2,3])
|
225
225
|
helper.should_receive(:render).with(hash_including(:partial => 'facet_pivot'))
|
226
226
|
helper.render_facet_limit(@mock_facet)
|
227
227
|
end
|
228
228
|
|
229
229
|
it "should let you override the rendered partial for pivot facets" do
|
230
|
-
@mock_facet =
|
230
|
+
@mock_facet = double(:name => 'my_pivot_facet_field_with_custom_partial', :items => [1,2,3])
|
231
231
|
helper.should_receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
|
232
232
|
helper.render_facet_limit(@mock_facet)
|
233
233
|
end
|
@@ -240,7 +240,7 @@ describe FacetsHelper do
|
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should add facet value for no pre-existing facets" do
|
243
|
-
helper.stub
|
243
|
+
helper.stub(:params).and_return(@params_no_existing_facet)
|
244
244
|
|
245
245
|
result_params = helper.add_facet_params("facet_field", "facet_value")
|
246
246
|
result_params[:f].should be_a_kind_of(Hash)
|
@@ -249,7 +249,7 @@ describe FacetsHelper do
|
|
249
249
|
end
|
250
250
|
|
251
251
|
it "should add a facet param to existing facet constraints" do
|
252
|
-
helper.stub
|
252
|
+
helper.stub(:params).and_return(@params_existing_facets)
|
253
253
|
|
254
254
|
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
|
255
255
|
|
@@ -267,7 +267,7 @@ describe FacetsHelper do
|
|
267
267
|
end
|
268
268
|
it "should leave non-facet params alone" do
|
269
269
|
[@params_existing_facets, @params_no_existing_facet].each do |params|
|
270
|
-
helper.stub
|
270
|
+
helper.stub(:params).and_return(params)
|
271
271
|
|
272
272
|
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
|
273
273
|
|
@@ -279,9 +279,9 @@ describe FacetsHelper do
|
|
279
279
|
end
|
280
280
|
|
281
281
|
it "should replace facets for facets configured as single" do
|
282
|
-
helper.should_receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(
|
282
|
+
helper.should_receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(:single => true))
|
283
283
|
params = { :f => { 'single_value_facet_field' => 'other_value'}}
|
284
|
-
helper.stub
|
284
|
+
helper.stub(:params).and_return params
|
285
285
|
|
286
286
|
result_params = helper.add_facet_params('single_value_facet_field', 'my_value')
|
287
287
|
|
@@ -292,14 +292,14 @@ describe FacetsHelper do
|
|
292
292
|
|
293
293
|
it "should accept a FacetItem instead of a plain facet value" do
|
294
294
|
|
295
|
-
result_params = helper.add_facet_params('facet_field_1',
|
295
|
+
result_params = helper.add_facet_params('facet_field_1', double(:value => 123))
|
296
296
|
|
297
297
|
result_params[:f]['facet_field_1'].should include(123)
|
298
298
|
end
|
299
299
|
|
300
300
|
it "should defer to the field set on a FacetItem" do
|
301
301
|
|
302
|
-
result_params = helper.add_facet_params('facet_field_1',
|
302
|
+
result_params = helper.add_facet_params('facet_field_1', double(:field => 'facet_field_2', :value => 123))
|
303
303
|
|
304
304
|
result_params[:f]['facet_field_1'].should be_blank
|
305
305
|
result_params[:f]['facet_field_2'].should include(123)
|
@@ -307,7 +307,7 @@ describe FacetsHelper do
|
|
307
307
|
|
308
308
|
it "should add any extra fq parameters from the FacetItem" do
|
309
309
|
|
310
|
-
result_params = helper.add_facet_params('facet_field_1',
|
310
|
+
result_params = helper.add_facet_params('facet_field_1', double(:value => 123, :fq => {'facet_field_2' => 'abc'}))
|
311
311
|
|
312
312
|
result_params[:f]['facet_field_1'].should include(123)
|
313
313
|
result_params[:f]['facet_field_2'].should include('abc')
|
@@ -325,7 +325,7 @@ describe FacetsHelper do
|
|
325
325
|
Blacklight::Solr::FacetPaginator.request_keys[:sort] => "index",
|
326
326
|
:id => 'facet_field_name'
|
327
327
|
}
|
328
|
-
helper.stub
|
328
|
+
helper.stub(:params).and_return(catalog_facet_params)
|
329
329
|
end
|
330
330
|
it "should redirect to 'index' action" do
|
331
331
|
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
@@ -366,31 +366,31 @@ describe FacetsHelper do
|
|
366
366
|
|
367
367
|
describe "render_facet_value" do
|
368
368
|
it "should use facet_display_value" do
|
369
|
-
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(
|
369
|
+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
|
370
370
|
|
371
371
|
helper.should_receive(:facet_display_value).and_return('Z')
|
372
372
|
helper.should_receive(:add_facet_params_and_redirect).and_return('link')
|
373
|
-
helper.render_facet_value('simple_field',
|
373
|
+
helper.render_facet_value('simple_field', double(:value => 'A', :hits => 10)).should == (helper.link_to("Z", "link", :class => "facet_select") + " " + (helper.content_tag :span, 10, :class => 'count')).html_safe
|
374
374
|
end
|
375
375
|
|
376
376
|
|
377
377
|
it "should suppress the link" do
|
378
|
-
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(
|
378
|
+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
|
379
379
|
|
380
380
|
helper.should_receive(:facet_display_value).and_return('Z')
|
381
381
|
helper.should_receive(:add_facet_params_and_redirect).and_return('link')
|
382
|
-
helper.render_facet_value('simple_field',
|
382
|
+
helper.render_facet_value('simple_field', double(:value => 'A', :hits => 10), :suppress_link => true).should == "Z <span class=\"count\">10</span>"
|
383
383
|
end
|
384
384
|
end
|
385
385
|
|
386
386
|
describe "#facet_display_value" do
|
387
387
|
it "should just be the facet value for an ordinary facet" do
|
388
|
-
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(
|
388
|
+
helper.stub(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil))
|
389
389
|
helper.facet_display_value('simple_field', 'asdf').should == 'asdf'
|
390
390
|
end
|
391
391
|
|
392
392
|
it "should allow you to pass in a :helper_method argument to the configuration" do
|
393
|
-
helper.stub(:facet_configuration_for_field).with('helper_field').and_return(
|
393
|
+
helper.stub(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
|
394
394
|
|
395
395
|
helper.should_receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
|
396
396
|
|
@@ -398,17 +398,17 @@ describe FacetsHelper do
|
|
398
398
|
end
|
399
399
|
|
400
400
|
it "should extract the configuration label for a query facet" do
|
401
|
-
helper.stub(:facet_configuration_for_field).with('query_facet').and_return(
|
401
|
+
helper.stub(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil))
|
402
402
|
helper.facet_display_value('query_facet', 'query_key').should == 'XYZ'
|
403
403
|
end
|
404
404
|
|
405
405
|
it "should localize the label for date-type facets" do
|
406
|
-
helper.stub(:facet_configuration_for_field).with('date_facet').and_return(
|
406
|
+
helper.stub(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil))
|
407
407
|
helper.facet_display_value('date_facet', '2012-01-01').should == 'Sun, 01 Jan 2012 00:00:00 +0000'
|
408
408
|
end
|
409
409
|
|
410
410
|
it "should localize the label for date-type facets with the supplied localization options" do
|
411
|
-
helper.stub(:facet_configuration_for_field).with('date_facet').and_return(
|
411
|
+
helper.stub(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil))
|
412
412
|
helper.facet_display_value('date_facet', '2012-01-01').should == '01 Jan 00:00'
|
413
413
|
end
|
414
414
|
end
|