blacklight 5.1.1 → 5.2.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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/blacklight/search_context.js +38 -24
  5. data/app/helpers/blacklight/blacklight_helper_behavior.rb +49 -70
  6. data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -8
  7. data/app/helpers/blacklight/configuration_helper_behavior.rb +10 -2
  8. data/app/helpers/blacklight/facets_helper_behavior.rb +4 -1
  9. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +2 -2
  10. data/app/helpers/blacklight/url_helper_behavior.rb +41 -7
  11. data/app/views/catalog/_facet_layout.html.erb +2 -2
  12. data/app/views/catalog/_per_page_widget.html.erb +4 -4
  13. data/app/views/catalog/_previous_next_doc.html.erb +1 -1
  14. data/app/views/catalog/_show_tools.html.erb +1 -1
  15. data/app/views/catalog/show.html.erb +1 -1
  16. data/app/views/layouts/blacklight.html.erb +1 -1
  17. data/blacklight.gemspec +1 -1
  18. data/config/jetty.yml +3 -0
  19. data/config/locales/blacklight.es.yml +220 -0
  20. data/gemfiles/rails4.1.gemfile +10 -0
  21. data/lib/blacklight/base.rb +1 -1
  22. data/lib/blacklight/catalog/search_context.rb +15 -15
  23. data/lib/blacklight/catalog.rb +19 -6
  24. data/lib/blacklight/configuration.rb +126 -31
  25. data/lib/blacklight/document_presenter.rb +168 -0
  26. data/lib/blacklight/request_builders.rb +288 -0
  27. data/lib/blacklight/routes.rb +6 -2
  28. data/lib/blacklight/solr/request.rb +1 -1
  29. data/lib/blacklight/solr_helper.rb +50 -323
  30. data/lib/blacklight/solr_response/facets.rb +7 -3
  31. data/lib/blacklight/utils.rb +39 -7
  32. data/lib/blacklight.rb +5 -3
  33. data/lib/generators/blacklight/install_generator.rb +17 -5
  34. data/lib/generators/blacklight/models_generator.rb +0 -1
  35. data/lib/generators/blacklight/templates/catalog_controller.rb +6 -0
  36. data/lib/generators/blacklight/templates/config/jetty.yml +8 -4
  37. data/lib/generators/blacklight/templates/config/solr.yml +2 -0
  38. data/spec/controllers/catalog_controller_spec.rb +41 -22
  39. data/spec/features/alternate_controller_spec.rb +1 -1
  40. data/spec/features/search_filters_spec.rb +24 -24
  41. data/spec/features/search_results_spec.rb +9 -4
  42. data/spec/features/search_sort_spec.rb +1 -1
  43. data/spec/helpers/blacklight_helper_spec.rb +87 -0
  44. data/spec/helpers/catalog_helper_spec.rb +5 -10
  45. data/spec/helpers/configuration_helper_spec.rb +22 -1
  46. data/spec/helpers/facets_helper_spec.rb +6 -0
  47. data/spec/helpers/render_constraints_helper_spec.rb +1 -2
  48. data/spec/helpers/url_helper_spec.rb +45 -2
  49. data/spec/lib/blacklight/routes_spec.rb +4 -4
  50. data/spec/lib/blacklight/solr_helper_spec.rb +364 -253
  51. data/spec/lib/blacklight/solr_response/facets_spec.rb +82 -0
  52. data/spec/lib/blacklight/solr_response_spec.rb +3 -1
  53. data/spec/lib/document_presenter_spec.rb +216 -0
  54. data/spec/lib/utils_spec.rb +8 -0
  55. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  56. data/spec/views/catalog/index.html.erb_spec.rb +29 -21
  57. data/spec/views/catalog/show.html.erb_spec.rb +11 -7
  58. data/template.demo.rb +20 -0
  59. metadata +12 -4
  60. data/lib/generators/blacklight/jetty_generator.rb +0 -70
@@ -1,6 +1,10 @@
1
- default:
1
+ development:
2
+ startup_wait: 15
2
3
  jetty_port: 8983
3
4
  test:
4
- jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
5
- jetty_home: <%= ENV['TEST_JETTY_PATH'] || File.join(Rails.root, 'test_jetty') %>
6
- startup_wait: 15
5
+ startup_wait: 60
6
+ jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
7
+ <%= ENV['TEST_JETTY_PATH'] ? "jetty_home: " + ENV['TEST_JETTY_PATH'] : '' %>
8
+ production:
9
+ startup_wait: 15
10
+ jetty_port: 8983
@@ -14,3 +14,5 @@ development:
14
14
  url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr" %>
15
15
  test: &test
16
16
  url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8888}/solr" %>
17
+ production:
18
+ url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr" %>
@@ -70,18 +70,13 @@ describe CatalogController do
70
70
  before do
71
71
  controller.stub(:get_search_results)
72
72
  end
73
- it "should include :search key with hash" do
74
- get :index
75
- expect(session[:search]).to_not be_nil
76
- expect(session[:search]).to be_kind_of(Hash)
77
- end
78
73
  it "should include search hash with key :q" do
79
74
  get :index, :q => @user_query
80
75
  expect(session[:search]).to_not be_nil
81
- expect(session[:search].keys).to include :id
76
+ expect(session[:search].keys).to include 'id'
82
77
 
83
- search = Search.find(session[:search][:id])
84
- expect(search.query_params[:q]).to eq @user_query
78
+ search = Search.find(session[:search]['id'])
79
+ expect(search.query_params['q']).to eq @user_query
85
80
  end
86
81
  end
87
82
 
@@ -200,23 +195,33 @@ describe CatalogController do
200
195
 
201
196
  end # describe index action
202
197
 
203
- describe "update action" do
198
+ describe "track action" do
204
199
  doc_id = '2007020969'
205
200
 
206
201
  it "should set counter value into session[:search]" do
207
- put :update, :id => doc_id, :counter => 3
208
- expect(session[:search][:counter]).to eq "3"
202
+ put :track, :id => doc_id, :counter => 3
203
+ expect(session[:search]['counter']).to eq "3"
209
204
  end
210
205
 
211
206
  it "should redirect to show action for doc id" do
212
- put :update, :id => doc_id, :counter => 3
207
+ put :track, :id => doc_id, :counter => 3
213
208
  assert_redirected_to(catalog_path(doc_id))
214
209
  end
215
210
 
216
211
  it "HTTP status code for redirect should be 303" do
217
- put :update, :id => doc_id, :counter => 3
212
+ put :track, :id => doc_id, :counter => 3
218
213
  expect(response.status).to eq 303
219
214
  end
215
+
216
+ it "should redirect to the path given in the redirect param" do
217
+ put :track, :id => doc_id, :counter => 3, redirect: '/xyz'
218
+ assert_redirected_to("/xyz")
219
+ end
220
+
221
+ it "should redirect to the path of the uri given in the redirect param" do
222
+ put :track, :id => doc_id, :counter => 3, redirect: 'http://localhost:3000/xyz'
223
+ assert_redirected_to("/xyz")
224
+ end
220
225
  end
221
226
 
222
227
  # SHOW ACTION
@@ -254,7 +259,7 @@ describe CatalogController do
254
259
  @search_session = { :id => current_search.id }
255
260
  end
256
261
  it "should set previous document if counter present in session" do
257
- session[:search] = @search_session.merge(:counter => 2)
262
+ session[:search] = @search_session.merge('counter' => 2)
258
263
  get :show, :id => doc_id
259
264
  expect(assigns[:previous_document]).to_not be_nil
260
265
  end
@@ -263,14 +268,14 @@ describe CatalogController do
263
268
  expect(assigns[:previous_document]).to be_nil
264
269
  expect(assigns[:next_document]).to be_nil
265
270
  end
266
- it "should not set previous or next document if session[:search][:counter] is nil" do
271
+ it "should not set previous or next document if session[:search]['counter'] is nil" do
267
272
  session[:search] = {}
268
273
  get :show, :id => doc_id
269
274
  expect(assigns[:previous_document]).to be_nil
270
275
  expect(assigns[:next_document]).to be_nil
271
276
  end
272
277
  it "should set next document if counter present in session" do
273
- session[:search] = @search_session.merge(:counter => 2)
278
+ session[:search] = @search_session.merge('counter' => 2)
274
279
  get :show, :id => doc_id
275
280
  expect(assigns[:next_document]).to_not be_nil
276
281
  end
@@ -483,6 +488,7 @@ describe CatalogController do
483
488
  req = {}
484
489
  res = {}
485
490
  fake_error = RSolr::Error::Http.new(req, res)
491
+ Rails.env.stub(:test? => false)
486
492
  controller.stub(:get_search_results) { |*args| raise fake_error }
487
493
  controller.logger.should_receive(:error).with(fake_error)
488
494
  get :index, :q=>"+"
@@ -514,10 +520,7 @@ describe CatalogController do
514
520
  controller.stub(:has_user_authentication_provider?) { false }
515
521
  @mock_response = double()
516
522
  @mock_document = double()
517
- @mock_response.stub(:docs => [], :total => 1, :facets => [], :facet_queries => {}, :facet_by_field_name => nil)
518
- @mock_document = double()
519
- controller.stub(:find => @mock_response,
520
- :get_single_doc_via_search => @mock_document)
523
+ controller.stub(:get_single_doc_via_search => @mock_document)
521
524
  end
522
525
 
523
526
  it "should not show user util links" do
@@ -634,7 +637,7 @@ describe CatalogController do
634
637
  it "should use an existing search session if the search is in the uri" do
635
638
  s = Search.create(:query_params => { :q => "x" })
636
639
  session[:search] ||= {}
637
- session[:search][:id] = s.id
640
+ session[:search]['id'] = s.id
638
641
  session[:history] ||= []
639
642
  session[:history] << s.id
640
643
  session = controller.send(:current_search_session)
@@ -642,6 +645,23 @@ describe CatalogController do
642
645
  expect(session).to eq(s)
643
646
  end
644
647
  end
648
+
649
+ describe "#has_search_parameters?" do
650
+ subject { controller.has_search_parameters? }
651
+ describe "none" do
652
+ before { controller.stub(params: { }) }
653
+ it { should be_false }
654
+ end
655
+ describe "with a query" do
656
+ before { controller.stub(params: { q: 'hello' }) }
657
+ it { should be_true }
658
+ end
659
+ describe "with a facet" do
660
+ before { controller.stub(params: { f: { "field" => ["value"]} }) }
661
+ it { should be_true }
662
+ end
663
+ end
664
+
645
665
  end
646
666
 
647
667
 
@@ -653,4 +673,3 @@ def assert_facets_have_values(facets)
653
673
  expect(facet.items).to have_at_least(1).item
654
674
  end
655
675
  end
656
-
@@ -29,7 +29,7 @@ describe "Alternate Controller Behaviors" do
29
29
  fill_in "q", :with=>"history"
30
30
  click_button 'search'
31
31
  expect(page).to have_selector ".document-thumbnail"
32
- expect(page).to have_selector ".document-thumbnail a[data-counter]"
32
+ expect(page).to have_selector ".document-thumbnail a[data-context-href]"
33
33
  expect(page).to have_selector ".document-thumbnail a img"
34
34
 
35
35
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Facets" do
4
4
  it "should work without a search term" do
5
5
  visit root_path
6
- within '#facet-language' do
6
+ within "#facet-language_facet" do
7
7
  click_link "Tibetan"
8
8
  end
9
9
  within "#sortAndPerPage" do
@@ -13,7 +13,7 @@ describe "Facets" do
13
13
  expect(page).to have_selector(".blacklight-language_facet")
14
14
  expect(page).to have_selector(".blacklight-language_facet.facet_limit-active")
15
15
 
16
- within "#facet-language" do
16
+ within "#facet-language_facet" do
17
17
  expect(page).to have_selector("span.selected", :text => "Tibetan")
18
18
  expect(page).to have_selector("span.facet-count.selected", :text => "6")
19
19
  end
@@ -22,11 +22,11 @@ describe "Facets" do
22
22
  within ("#sortAndPerPage") do
23
23
  expect(page).to have_content "1 - 2 of 2"
24
24
  end
25
- within "#facet-language" do
25
+ within "#facet-language_facet" do
26
26
  expect(page).to have_selector("span.selected", :text => "Tibetan")
27
27
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
28
28
  end
29
- within "#facet-region" do
29
+ within "#facet-subject_geo_facet" do
30
30
  expect(page).to have_selector("span.selected", :text => "India")
31
31
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
32
32
  end
@@ -40,13 +40,13 @@ describe "Facets" do
40
40
  expect(page).to have_content "1 - 9 of 9"
41
41
  end
42
42
 
43
- within "#facet-language" do
43
+ within "#facet-language_facet" do
44
44
  click_link "Tibetan"
45
45
  end
46
46
  within ("#sortAndPerPage") do
47
47
  expect(page).to have_content "1 - 2 of 2"
48
48
  end
49
- within "#facet-language" do
49
+ within "#facet-language_facet" do
50
50
  expect(page).to have_selector("span.selected", :text => "Tibetan")
51
51
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
52
52
  end
@@ -60,7 +60,7 @@ describe "Facets" do
60
60
  within ("#sortAndPerPage") do
61
61
  expect(page).to have_content "1 entry found"
62
62
  end
63
- within "#facet-language" do
63
+ within "#facet-language_facet" do
64
64
  expect(page).to have_selector("span.selected", :text => "Tibetan")
65
65
  expect(page).to have_selector("span.facet-count.selected", :text => "1")
66
66
  end
@@ -72,14 +72,14 @@ describe "Facets" do
72
72
 
73
73
  it "should allow removing filters" do
74
74
  visit root_path
75
- within "#facet-language" do
75
+ within "#facet-language_facet" do
76
76
  click_link "Tibetan"
77
77
  end
78
- within "#facet-language" do
78
+ within "#facet-language_facet" do
79
79
  expect(page).to have_selector("span.selected", :text => "Tibetan")
80
80
  expect(page).to have_selector("span.facet-count.selected", :text => "6")
81
81
  end
82
- within "#facet-language" do
82
+ within "#facet-language_facet" do
83
83
  click_link 'remove'
84
84
  end
85
85
  expect(page).to_not have_link 'remove'
@@ -90,17 +90,17 @@ describe "Facets" do
90
90
  visit root_path
91
91
  fill_in "q", with: 'history'
92
92
  click_button 'search'
93
- within "#facet-language" do
93
+ within "#facet-language_facet" do
94
94
  click_link 'Tibetan'
95
95
  end
96
- within "#facet-language" do
96
+ within "#facet-language_facet" do
97
97
  expect(page).to have_selector("span.selected", :text => "Tibetan")
98
98
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
99
99
  end
100
100
 
101
101
  click_link '2004'
102
102
 
103
- within "#facet-language" do
103
+ within "#facet-language_facet" do
104
104
  expect(page).to have_selector("span.selected", :text => "Tibetan")
105
105
  expect(page).to have_selector("span.facet-count.selected", :text => "1")
106
106
  end
@@ -111,7 +111,7 @@ describe "Facets" do
111
111
  fill_in "q", with: 'china'
112
112
  click_button 'search'
113
113
 
114
- within "#facet-language" do
114
+ within "#facet-language_facet" do
115
115
  expect(page).to have_selector("span.selected", :text => "Tibetan")
116
116
  expect(page).to have_selector("span.facet-count.selected", :text => "1")
117
117
  end
@@ -125,15 +125,15 @@ describe "Facets" do
125
125
  visit root_path
126
126
  fill_in "q", with: 'history'
127
127
  click_button 'search'
128
- within "#facet-language" do
128
+ within "#facet-language_facet" do
129
129
  click_link 'Tibetan'
130
130
  end
131
- within "#facet-language" do
131
+ within "#facet-language_facet" do
132
132
  expect(page).to have_selector("span.selected", :text => "Tibetan")
133
133
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
134
134
  end
135
135
  click_link 'title'
136
- within "#facet-language" do
136
+ within "#facet-language_facet" do
137
137
  expect(page).to have_selector("span.selected", :text => "Tibetan")
138
138
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
139
139
  end
@@ -147,17 +147,17 @@ describe "Facets" do
147
147
  visit root_path
148
148
  fill_in "q", with: 'history'
149
149
  click_button 'search'
150
- within "#facet-language" do
150
+ within "#facet-language_facet" do
151
151
  click_link 'Tibetan'
152
152
  end
153
- within "#facet-language" do
153
+ within "#facet-language_facet" do
154
154
  expect(page).to have_selector("span.selected", :text => "Tibetan")
155
155
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
156
156
  end
157
157
  within '#per_page-dropdown' do
158
158
  click_link '20'
159
159
  end
160
- within "#facet-language" do
160
+ within "#facet-language_facet" do
161
161
  expect(page).to have_selector("span.selected", :text => "Tibetan")
162
162
  expect(page).to have_selector("span.facet-count.selected", :text => "2")
163
163
  end
@@ -167,14 +167,14 @@ describe "Facets" do
167
167
  end
168
168
  end
169
169
  it "should be collapsed when not selected", :js => true do
170
- pending("Test passes locally but not on Travis.")
170
+ pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
171
171
  visit root_path
172
172
  within(".blacklight-subject_topic_facet") do
173
173
  expect(page).not_to have_selector(".panel-collapse", :visible => true)
174
174
  end
175
175
  end
176
176
  it "should expand when the heading is clicked", :js => true do
177
- pending("Test passes locally but not on Travis.")
177
+ pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
178
178
  visit root_path
179
179
  within(".blacklight-subject_topic_facet") do
180
180
  expect(page).not_to have_selector(".panel-collapse", :visible => true)
@@ -183,7 +183,7 @@ describe "Facets" do
183
183
  end
184
184
  end
185
185
  it "should expand when the anchor is clicked", :js => true do
186
- pending("Test passes locally but not on Travis.")
186
+ pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
187
187
  visit root_path
188
188
  within(".blacklight-subject_topic_facet") do
189
189
  expect(page).not_to have_selector(".panel-collapse", :visible => true)
@@ -192,7 +192,7 @@ describe "Facets" do
192
192
  end
193
193
  end
194
194
  it "should keep selected facets expanded on page load", :js => true do
195
- pending("Test passes locally but not on Travis.")
195
+ pending("Test passes locally but not on Travis.") if ENV['TRAVIS']
196
196
  visit root_path
197
197
  within(".blacklight-subject_topic_facet") do
198
198
  click_link "Topic"
@@ -55,14 +55,19 @@ describe "Search Results" do
55
55
  click_on 'Pluvial nectar of blessings'
56
56
  expect(page).to have_content "« Previous | 10 of 30 | Next »"
57
57
  prev = page.find("#previousNextDocument .previous")
58
- expect(prev['data-counter']).to eq "9"
59
- expect(prev['data-search_id']).to eq search_id
58
+ expect(prev['data-context-href']).to eq "/catalog/2003546302/track?counter=9&search_id=#{search_id}"
60
59
 
61
60
  click_on "« Previous"
62
61
 
63
62
  prev = page.find("#previousNextDocument .previous")
64
- expect(prev['data-counter']).to eq "8"
65
- expect(prev['data-search_id']).to eq search_id
63
+ expect(prev['data-context-href']).to eq "/catalog/2004310986/track?counter=8&search_id=#{search_id}"
64
+ end
65
+
66
+ it "should redirect context urls to the original url", :js => true do
67
+ search_for ''
68
+ first('.index_title a').click
69
+ expect(page).to have_content "« Previous | 1 of 30 | Next »"
70
+ expect(page.current_url).to_not have_content "/track"
66
71
  end
67
72
 
68
73
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Search Sort" do
4
4
  it "should sort on facet results with no search terms" do
5
5
  visit root_path
6
- within "#facet-language" do
6
+ within "#facet-language_facet" do
7
7
  click_link 'English'
8
8
  end
9
9
  expect(page).to have_content 'Sort by relevance'
@@ -32,6 +32,22 @@ describe BlacklightHelper do
32
32
  end
33
33
  end
34
34
 
35
+ describe "#render_page_title" do
36
+ it "should look in content_for(:page_title)" do
37
+ helper.content_for(:page_title) { "xyz" }
38
+ expect(helper.render_page_title).to eq "xyz"
39
+ end
40
+
41
+ it "should look in the @page_title ivar" do
42
+ assign(:page_title, "xyz")
43
+ expect(helper.render_page_title).to eq "xyz"
44
+ end
45
+
46
+ it "should default to the application name" do
47
+ expect(helper.render_page_title).to eq helper.application_name
48
+ end
49
+ end
50
+
35
51
  describe "render_link_rel_alternates" do
36
52
  class MockDocumentAppHelper
37
53
  include Blacklight::Solr::Document
@@ -389,6 +405,9 @@ describe BlacklightHelper do
389
405
  end
390
406
 
391
407
  describe "render_field_value" do
408
+ before do
409
+ Deprecation.stub(:warn)
410
+ end
392
411
  it "should join and html-safe values" do
393
412
  expect(helper.render_field_value(['a', 'b'])).to eq "a, b"
394
413
  end
@@ -426,4 +445,72 @@ describe BlacklightHelper do
426
445
  expect(helper.should_show_spellcheck_suggestions? response).to be_false
427
446
  end
428
447
  end
448
+
449
+ describe "#render_document_partials" do
450
+ let(:doc) { double }
451
+ before do
452
+ helper.stub(document_partial_path_templates: [])
453
+ end
454
+
455
+ it "should get the document format from document_partial_name" do
456
+ helper.should_receive(:document_partial_name).with(doc, :xyz)
457
+ helper.render_document_partial(doc, :xyz)
458
+ end
459
+
460
+ context "with a 1-arg form of document_partial_name" do
461
+ it "should only call the 1-arg form of the document_partial_name" do
462
+ helper.should_receive(:method).with(:document_partial_name).and_return(double(arity: 1))
463
+ helper.should_receive(:document_partial_name).with(doc)
464
+ Deprecation.should_receive(:warn)
465
+ helper.render_document_partial(doc, nil)
466
+ end
467
+ end
468
+ end
469
+
470
+ describe "#document_partial_name" do
471
+ let(:blacklight_config) { Blacklight::Configuration.new }
472
+
473
+ before do
474
+ helper.stub(blacklight_config: blacklight_config)
475
+ end
476
+
477
+ context "with a solr document with empty fields" do
478
+ let(:document) { SolrDocument.new }
479
+ it "should be the default value" do
480
+ expect(helper.document_partial_name(document)).to eq 'default'
481
+ end
482
+ end
483
+
484
+ context "with a solr document with the display type field set" do
485
+ let(:document) { SolrDocument.new 'my_field' => 'xyz'}
486
+
487
+ before do
488
+ blacklight_config.show.display_type_field = 'my_field'
489
+ end
490
+
491
+ it "should use the value in the configured display type field" do
492
+ expect(helper.document_partial_name(document)).to eq 'xyz'
493
+ end
494
+
495
+ it "should use the value in the configured display type field if the action-specific field is empty" do
496
+ expect(helper.document_partial_name(document, :some_action)).to eq 'xyz'
497
+ end
498
+ end
499
+
500
+ context "with a solr doucment with an action-specific field set" do
501
+
502
+ let(:document) { SolrDocument.new 'my_field' => 'xyz', 'other_field' => 'abc' }
503
+
504
+ before do
505
+ blacklight_config.show.media_display_type_field = 'my_field'
506
+ blacklight_config.show.metadata_display_type_field = 'other_field'
507
+ end
508
+
509
+ it "should use the value in the action-specific fields" do
510
+ expect(helper.document_partial_name(document, :media)).to eq 'xyz'
511
+ expect(helper.document_partial_name(document, :metadata)).to eq 'abc'
512
+ end
513
+
514
+ end
515
+ end
429
516
  end
@@ -126,27 +126,22 @@ describe CatalogHelper do
126
126
 
127
127
  describe "should_autofocus_on_search_box?" do
128
128
  it "should be focused if we're on a catalog-like index page without query or facet parameters" do
129
- helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { })
129
+ helper.stub(controller: CatalogController.new, action_name: "index", has_search_parameters?: false)
130
130
  expect(helper.should_autofocus_on_search_box?).to be_true
131
131
  end
132
132
 
133
133
  it "should not be focused if we're not on a catalog controller" do
134
- helper.stub(:controller => ApplicationController.new)
134
+ helper.stub(controller: ApplicationController.new)
135
135
  expect(helper.should_autofocus_on_search_box?).to be_false
136
136
  end
137
137
 
138
138
  it "should not be focused if we're not on a catalog controller index" do
139
- helper.stub(:controller => CatalogController.new, :action_name => "show")
139
+ helper.stub(controller: CatalogController.new, action_name: "show")
140
140
  expect(helper.should_autofocus_on_search_box?).to be_false
141
141
  end
142
142
 
143
- it "should not be focused if a search string is provided" do
144
- helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { :q => "hello"})
145
- expect(helper.should_autofocus_on_search_box?).to be_false
146
- end
147
-
148
- it "should not be focused if a facet is selected" do
149
- helper.stub(:controller => CatalogController.new, :action_name => "index", :params => { :f => { "field" => ["value"]}})
143
+ it "should not be focused if a search parameters are provided" do
144
+ helper.stub(controller: CatalogController.new, action_name: "index", has_search_parameters?: true)
150
145
  expect(helper.should_autofocus_on_search_box?).to be_false
151
146
  end
152
147
  end
@@ -100,4 +100,25 @@ describe BlacklightConfigurationHelper do
100
100
  label = helper.solr_field_label "default text", :key_a, :key_b
101
101
  end
102
102
  end
103
- end
103
+
104
+ describe "#default_per_page" do
105
+ it "should be the configured default per page" do
106
+ helper.stub(blacklight_config: double(default_per_page: 42))
107
+ expect(helper.default_per_page).to eq 42
108
+ end
109
+
110
+ it "should be the first per-page value if a default isn't set" do
111
+ helper.stub(blacklight_config: double(default_per_page: nil, per_page: [11, 22]))
112
+ expect(helper.default_per_page).to eq 11
113
+ end
114
+ end
115
+
116
+ describe "#per_page_options_for_select" do
117
+ it "should be the per-page values formatted as options_for_select" do
118
+ helper.stub(blacklight_config: double(per_page: [11, 22, 33]))
119
+ expect(helper.per_page_options_for_select).to include ["11<span class=\"sr-only\"> per page</span>", 11]
120
+ expect(helper.per_page_options_for_select).to include ["22<span class=\"sr-only\"> per page</span>", 22]
121
+ expect(helper.per_page_options_for_select).to include ["33<span class=\"sr-only\"> per page</span>", 33]
122
+ end
123
+ end
124
+ end
@@ -350,4 +350,10 @@ describe FacetsHelper do
350
350
  expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq '01 Jan 00:00'
351
351
  end
352
352
  end
353
+
354
+ describe "#facet_field_id" do
355
+ it "should be the parameterized version of the facet field" do
356
+ expect(helper.facet_field_id double(field: 'some field')).to eq "facet-some-field"
357
+ end
358
+ end
353
359
  end
@@ -25,8 +25,7 @@ describe RenderConstraintsHelper do
25
25
  end
26
26
  it "should have a link relative to the current url" do
27
27
  result = helper.render_filter_element('type', ['journal'], {:q=>'biz'})
28
- # I'm not certain how the ampersand gets in there. It's not important.
29
- expect(result).to have_link "Remove constraint Type: journal", href: "/catalog?&q=biz"
28
+ expect(result).to have_link "Remove constraint Type: journal", href: "/catalog?q=biz"
30
29
  end
31
30
  end
32
31
 
@@ -18,6 +18,41 @@ describe BlacklightUrlHelper do
18
18
  helper.stub(current_search_session: nil)
19
19
  end
20
20
 
21
+ describe "url_for_document" do
22
+ let(:controller_class) { ::CatalogController.new }
23
+
24
+ before do
25
+ helper.stub(controller: controller_class)
26
+ helper.stub(controller_name: controller_class.controller_name)
27
+ end
28
+
29
+ it "should be a polymorphic routing-ready object" do
30
+ doc = double
31
+ expect(helper.url_for_document(doc)).to eq doc
32
+ end
33
+
34
+ it "should be a catalog controller-specific route" do
35
+ doc = SolrDocument.new
36
+ expect(helper.url_for_document(doc)).to eq({controller: 'catalog', action: :show, id: doc})
37
+ end
38
+
39
+ context "within an alternative catalog controller" do
40
+ let(:controller_class) { ::AlternateController.new }
41
+
42
+ it "should be a catalog controller-specific route" do
43
+ doc = SolrDocument.new
44
+ expect(helper.url_for_document(doc)).to eq({controller: 'alternate', action: :show, id: doc})
45
+ end
46
+ end
47
+
48
+ it "should be a polymorphic route if the solr document responds to #to_model with a non-SolrDocument" do
49
+ some_model = double
50
+ doc = SolrDocument.new
51
+ doc.stub(to_model: some_model)
52
+ expect(helper.url_for_document(doc)).to eq doc
53
+ end
54
+ end
55
+
21
56
  describe "link_back_to_catalog" do
22
57
  let(:query_params) {{:q => "query", :f => "facets", :per_page => "10", :page => "2", :controller=>'catalog'}}
23
58
  let(:bookmarks_query_params) {{ :page => "2", :controller=>'bookmarks'}}
@@ -210,7 +245,15 @@ describe BlacklightUrlHelper do
210
245
  it "should convert the counter parameter into a data- attribute" do
211
246
  data = {'id'=>'123456','title_display'=>['654321']}
212
247
  @document = SolrDocument.new(data)
213
- expect(helper.link_to_document(@document, { :label => :title_display, :counter => 5 })).to match /data-counter="5"/
248
+ expect(helper.link_to_document(@document, { :label => :title_display, :counter => 5 })).to match /\/catalog\/123456\/track\?counter=5/
249
+ end
250
+
251
+ it "should merge the data- attributes from the options with the counter params" do
252
+ data = {'id'=>'123456','title_display'=>['654321']}
253
+ @document = SolrDocument.new(data)
254
+ link = helper.link_to_document @document, { data: { x: 1 } }
255
+ expect(link).to have_selector '[data-x]'
256
+ expect(link).to have_selector '[data-context-href]'
214
257
  end
215
258
 
216
259
  it "passes on the title attribute to the link_to_with_data method" do
@@ -352,4 +395,4 @@ describe BlacklightUrlHelper do
352
395
  expect(added_facet_params_from_facet_action).to eq added_facet_params.except(Blacklight::Solr::FacetPaginator.request_keys[:page], Blacklight::Solr::FacetPaginator.request_keys[:sort])
353
396
  end
354
397
  end
355
- end
398
+ end
@@ -7,8 +7,8 @@ describe Blacklight::Routes do
7
7
  describe "without constraints" do
8
8
  let(:options) { Hash.new }
9
9
  it "should define the resources" do
10
- router.should_receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show, :update]})
11
- router.should_receive(:resources).with(:records, :only=>[:show, :update])
10
+ router.should_receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show]})
11
+ router.should_receive(:resources).with(:records, :only=>[:show])
12
12
  subject.solr_document(:records)
13
13
  end
14
14
  end
@@ -16,8 +16,8 @@ describe Blacklight::Routes do
16
16
  describe "with constraints" do
17
17
  let(:options) { { :constraints => {id: /[a-z]+/, format: false } } }
18
18
  it "should define the resources" do
19
- router.should_receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show, :update], :constraints=>{:id=>/[a-z]+/, :format=>false} })
20
- router.should_receive(:resources).with(:records, :only=>[:show, :update], :constraints=>{:id=>/[a-z]+/, :format=>false})
19
+ router.should_receive(:resources).with(:solr_document, {:path=>:records, :controller=>:records, :only=>[:show], :constraints=>{:id=>/[a-z]+/, :format=>false} })
20
+ router.should_receive(:resources).with(:records, :only=>[:show], :constraints=>{:id=>/[a-z]+/, :format=>false})
21
21
  subject.solr_document(:records)
22
22
  end
23
23
  end