blacklight 6.2.0 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.solr_wrapper +5 -0
  4. data/.travis.yml +3 -5
  5. data/Gemfile +3 -3
  6. data/VERSION +1 -1
  7. data/app/assets/javascripts/blacklight/core.js +19 -5
  8. data/app/helpers/blacklight/blacklight_helper_behavior.rb +48 -20
  9. data/app/helpers/blacklight/configuration_helper_behavior.rb +1 -1
  10. data/app/helpers/blacklight/url_helper_behavior.rb +2 -1
  11. data/app/presenters/blacklight/document_presenter.rb +58 -150
  12. data/app/presenters/blacklight/field_presenter.rb +31 -0
  13. data/app/presenters/blacklight/index_presenter.rb +69 -0
  14. data/app/presenters/blacklight/link_alternate_presenter.rb +29 -0
  15. data/app/presenters/blacklight/rendering/abstract_step.rb +24 -0
  16. data/app/presenters/blacklight/rendering/helper_method.rb +23 -0
  17. data/app/presenters/blacklight/rendering/join.rb +16 -0
  18. data/app/presenters/blacklight/rendering/link_to_facet.rb +35 -0
  19. data/app/presenters/blacklight/rendering/microdata.rb +17 -0
  20. data/app/presenters/blacklight/rendering/pipeline.rb +32 -0
  21. data/app/presenters/blacklight/rendering/terminator.rb +9 -0
  22. data/app/presenters/blacklight/show_presenter.rb +93 -0
  23. data/app/services/blacklight/field_retriever.rb +58 -0
  24. data/app/views/catalog/_document_default.atom.builder +2 -3
  25. data/app/views/catalog/_document_default.rss.builder +2 -2
  26. data/app/views/kaminari/blacklight/_next_page.html.erb +9 -3
  27. data/app/views/kaminari/blacklight/_prev_page.html.erb +10 -3
  28. data/lib/blacklight/configuration.rb +15 -3
  29. data/lib/blacklight/configuration/null_field.rb +13 -0
  30. data/lib/blacklight/configuration/view_config.rb +6 -0
  31. data/lib/generators/blacklight/templates/catalog_controller.rb +1 -1
  32. data/lib/generators/blacklight/templates/config/blacklight.yml +1 -1
  33. data/lib/generators/blacklight/templates/config/jetty.yml +1 -1
  34. data/spec/controllers/alternate_controller_spec.rb +2 -2
  35. data/spec/controllers/application_controller_spec.rb +1 -1
  36. data/spec/controllers/blacklight/facet_spec.rb +3 -3
  37. data/spec/controllers/blacklight/search_fields_spec.rb +7 -7
  38. data/spec/controllers/blacklight/search_helper_spec.rb +44 -44
  39. data/spec/controllers/blacklight/suggest_search_spec.rb +1 -1
  40. data/spec/controllers/bookmarks_controller_spec.rb +6 -6
  41. data/spec/controllers/catalog_controller_spec.rb +125 -125
  42. data/spec/controllers/saved_searches_controller_spec.rb +4 -9
  43. data/spec/controllers/search_history_controller_spec.rb +3 -6
  44. data/spec/controllers/suggest_controller_spec.rb +2 -2
  45. data/spec/features/alternate_controller_spec.rb +3 -3
  46. data/spec/features/bookmarks_spec.rb +6 -6
  47. data/spec/features/did_you_mean_spec.rb +10 -10
  48. data/spec/features/facets_spec.rb +4 -4
  49. data/spec/features/record_view_spec.rb +4 -4
  50. data/spec/features/saved_searches_spec.rb +4 -4
  51. data/spec/features/search_context_spec.rb +4 -4
  52. data/spec/features/search_filters_spec.rb +10 -10
  53. data/spec/features/search_formats_spec.rb +2 -2
  54. data/spec/features/search_history_spec.rb +5 -5
  55. data/spec/features/search_pagination_spec.rb +4 -4
  56. data/spec/features/search_results_spec.rb +7 -7
  57. data/spec/features/search_sort_spec.rb +2 -2
  58. data/spec/features/search_spec.rb +6 -6
  59. data/spec/helpers/blacklight_helper_spec.rb +105 -65
  60. data/spec/helpers/catalog_helper_spec.rb +36 -36
  61. data/spec/helpers/configuration_helper_spec.rb +28 -28
  62. data/spec/helpers/facets_helper_spec.rb +39 -39
  63. data/spec/helpers/hash_as_hidden_fields_spec.rb +1 -1
  64. data/spec/helpers/render_constraints_helper_spec.rb +1 -1
  65. data/spec/helpers/search_history_constraints_helper_spec.rb +7 -7
  66. data/spec/helpers/url_helper_spec.rb +20 -17
  67. data/spec/lib/blacklight/search_state_spec.rb +2 -2
  68. data/spec/lib/blacklight/utils_spec.rb +15 -15
  69. data/spec/lib/blacklight_spec.rb +1 -1
  70. data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
  71. data/spec/models/blacklight/configurable_spec.rb +3 -3
  72. data/spec/models/blacklight/configuration_spec.rb +52 -52
  73. data/spec/models/blacklight/document_spec.rb +10 -10
  74. data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
  75. data/spec/models/blacklight/search_builder_spec.rb +34 -34
  76. data/spec/models/blacklight/user_spec.rb +4 -4
  77. data/spec/models/bookmark_spec.rb +5 -5
  78. data/spec/models/record_mailer_spec.rb +11 -11
  79. data/spec/models/search_spec.rb +1 -1
  80. data/spec/models/solr_document_spec.rb +4 -4
  81. data/spec/presenters/document_presenter_spec.rb +94 -50
  82. data/spec/presenters/index_presenter_spec.rb +147 -0
  83. data/spec/presenters/pipeline_spec.rb +28 -0
  84. data/spec/presenters/show_presenter_spec.rb +287 -0
  85. data/spec/routing/catalog_routing_spec.rb +11 -11
  86. data/spec/spec_helper.rb +10 -1
  87. data/spec/support/backport_test.rb +38 -0
  88. data/spec/test_app_templates/Gemfile.extra +2 -10
  89. data/spec/views/_user_util_links.html.erb_spec.rb +1 -1
  90. data/spec/views/catalog/_constraints.html.erb_spec.rb +3 -3
  91. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +5 -5
  92. data/spec/views/catalog/_document.html.erb_spec.rb +2 -2
  93. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
  94. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +4 -4
  95. data/spec/views/catalog/_facets.html.erb_spec.rb +4 -4
  96. data/spec/views/catalog/_index_default.erb_spec.rb +5 -4
  97. data/spec/views/catalog/_index_header_default.html.erb_spec.rb +4 -3
  98. data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
  99. data/spec/views/catalog/_search_header.erb_spec.rb +1 -1
  100. data/spec/views/catalog/_show_default.erb_spec.rb +6 -5
  101. data/spec/views/catalog/_show_sidebar.erb_spec.rb +2 -1
  102. data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
  103. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
  104. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -2
  105. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +3 -3
  106. data/spec/views/catalog/facet.html.erb_spec.rb +3 -3
  107. data/spec/views/catalog/index.atom.builder_spec.rb +15 -14
  108. data/spec/views/catalog/index.html.erb_spec.rb +3 -3
  109. data/spec/views/catalog/opensearch.xml.builder_spec.rb +1 -1
  110. data/spec/views/catalog/show.html.erb_spec.rb +5 -4
  111. data/tasks/blacklight.rake +1 -1
  112. metadata +25 -4
  113. data/config/jetty.yml +0 -13
@@ -15,7 +15,7 @@ describe Blacklight::SuggestSearch do
15
15
  end
16
16
  end
17
17
  describe '#suggest_results' do
18
- it 'should call send_and_recieve from a repository connection' do
18
+ it 'calls send_and_recieve from a repository connection' do
19
19
  expect(suggest_search).to receive(:suggest_handler_path).and_return(suggest_path)
20
20
  expect(suggest_search.suggest_results).to eq 'sent'
21
21
  end
@@ -5,7 +5,7 @@ describe BookmarksController do
5
5
  # jquery 1.9 ajax does error callback if 200 returns empty body. so use 204 instead.
6
6
  describe "update" do
7
7
  it "has a 200 status code when creating a new one" do
8
- xhr :put, :update, :id => '2007020969', :format => :js
8
+ put :update, xhr: true, params: { id: '2007020969', format: :js }
9
9
  expect(response).to be_success
10
10
  expect(response.code).to eq "200"
11
11
  expect(JSON.parse(response.body)["bookmarks"]["count"]).to eq 1
@@ -16,7 +16,7 @@ describe BookmarksController do
16
16
  allow(@controller).to receive_message_chain(:current_or_guest_user, :persisted?).and_return(true)
17
17
  allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :exists?).and_return(false)
18
18
  allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
19
- xhr :put, :update, :id => 'iamabooboo', :format => :js
19
+ put :update, xhr: true, params: { id: 'iamabooboo', format: :js }
20
20
  expect(response.code).to eq "500"
21
21
  end
22
22
  end
@@ -28,7 +28,7 @@ describe BookmarksController do
28
28
  end
29
29
 
30
30
  it "has a 200 status code when delete is success" do
31
- xhr :delete, :destroy, :id => '2007020969', :format => :js
31
+ delete :destroy, xhr: true, params: { id: '2007020969', format: :js }
32
32
  expect(response).to be_success
33
33
  expect(response.code).to eq "200"
34
34
  expect(JSON.parse(response.body)["bookmarks"]["count"]).to eq 0
@@ -39,7 +39,7 @@ describe BookmarksController do
39
39
  allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
40
40
  allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :find_by).and_return(double('bookmark', delete: nil, destroyed?: false))
41
41
 
42
- xhr :delete, :destroy, :id => 'pleasekillme', :format => :js
42
+ delete :destroy, xhr: true, params: { id: 'pleasekillme', format: :js }
43
43
 
44
44
  expect(response.code).to eq "500"
45
45
  end
@@ -55,7 +55,7 @@ describe BookmarksController do
55
55
  end
56
56
 
57
57
  it 'finds the user from the encrypted token' do
58
- get :index, encrypted_user_id: token
58
+ get :index, params: { encrypted_user_id: token }
59
59
  expect(controller.send(:token_user).id).to eq user.id
60
60
  end
61
61
 
@@ -63,7 +63,7 @@ describe BookmarksController do
63
63
  let(:current_time) { Time.zone.now - 2.hours }
64
64
 
65
65
  it 'is expired' do
66
- get :index, encrypted_user_id: token
66
+ get :index, params: { encrypted_user_id: token }
67
67
  expect do
68
68
  controller.send(:token_user)
69
69
  end.to raise_error(Blacklight::Exceptions::ExpiredSessionToken)
@@ -15,40 +15,40 @@ describe CatalogController do
15
15
  end
16
16
 
17
17
  describe "preferred view" do
18
- it "should save the view choice" do
19
- get :index, q: 'foo', view: 'gallery'
18
+ it "saves the view choice" do
19
+ get :index, params: { q: 'foo', view: 'gallery' }
20
20
  expect(session[:preferred_view]).to eq 'gallery'
21
21
  end
22
22
  end
23
23
 
24
24
  # check each user manipulated parameter
25
- it "should have docs and facets for query with results", :integration => true do
26
- get :index, q: user_query
25
+ it "has docs and facets for query with results", :integration => true do
26
+ get :index, params: { q: user_query }
27
27
  expect(assigns(:response).docs).to_not be_empty
28
28
  assert_facets_have_values(assigns(:response).aggregations)
29
29
  end
30
- it "should have docs and facets for existing facet value", :integration => true do
31
- get :index, f: {"format" => 'Book'}
30
+ it "has docs and facets for existing facet value", :integration => true do
31
+ get :index, params: { f: {"format" => 'Book'} }
32
32
  expect(assigns(:response).docs).to_not be_empty
33
33
  assert_facets_have_values(assigns(:response).aggregations)
34
34
  end
35
- it "should have docs and facets for non-default results per page", :integration => true do
35
+ it "has docs and facets for non-default results per page", :integration => true do
36
36
  num_per_page = 7
37
- get :index, :per_page => num_per_page
37
+ get :index, params: { per_page: num_per_page }
38
38
  expect(assigns(:response).docs).to have(num_per_page).items
39
39
  assert_facets_have_values(assigns(:response).aggregations)
40
40
  end
41
41
 
42
- it "should have docs and facets for second page", :integration => true do
42
+ it "has docs and facets for second page", :integration => true do
43
43
  page = 2
44
- get :index, :page => page
44
+ get :index, params: { page: page }
45
45
  expect(assigns(:response).docs).to_not be_empty
46
46
  expect(assigns(:response).params[:start].to_i).to eq (page-1) * @controller.blacklight_config[:default_solr_params][:rows]
47
47
  assert_facets_have_values(assigns(:response).aggregations)
48
48
  end
49
49
 
50
- it "should have no docs or facet values for query without results", :integration => true do
51
- get :index, q: 'sadfdsafasdfsadfsadfsadf' # query for no results
50
+ it "has no docs or facet values for query without results", :integration => true do
51
+ get :index, params: { q: 'sadfdsafasdfsadfsadfsadf' } # query for no results
52
52
 
53
53
  expect(assigns(:response).docs).to be_empty
54
54
  assigns(:response).aggregations.each do |key, facet|
@@ -56,20 +56,20 @@ describe CatalogController do
56
56
  end
57
57
  end
58
58
 
59
- it "should show 0 results when the user asks for an invalid value to a custom facet query", :integration => true do
60
- get :index, f: {example_query_facet_field: 'bogus'} # bogus custom facet value
59
+ it "shows 0 results when the user asks for an invalid value to a custom facet query", :integration => true do
60
+ get :index, params: { f: { example_query_facet_field: 'bogus' } } # bogus custom facet value
61
61
  expect(assigns(:response).docs).to be_empty
62
62
  end
63
63
 
64
- it "should return results (possibly 0) when the user asks for a valid value to a custom facet query", :integration => true do
65
- get :index, f: {example_query_facet_field: 'years_10'} # valid custom facet value with some results
64
+ it "returns results (possibly 0) when the user asks for a valid value to a custom facet query", :integration => true do
65
+ get :index, params: { f: { example_query_facet_field: 'years_10' } } # valid custom facet value with some results
66
66
  expect(assigns(:response).docs).to_not be_empty
67
- get :index, f: {example_query_facet_field: 'years_5'} # valid custom facet value with NO results
67
+ get :index, params: { f: {example_query_facet_field: 'years_5' } } # valid custom facet value with NO results
68
68
  expect(assigns(:response).docs).to be_empty
69
69
  end
70
70
 
71
- it "should have a spelling suggestion for an appropriately poor query", :integration => true do
72
- get :index, :q => 'boo'
71
+ it "has a spelling suggestion for an appropriately poor query", :integration => true do
72
+ get :index, params: { q: 'boo' }
73
73
  expect(assigns(:response).spelling.words).to_not be_nil
74
74
  end
75
75
 
@@ -78,7 +78,7 @@ describe CatalogController do
78
78
  allow(controller).to receive(:search_results)
79
79
  end
80
80
  it "includes search hash with key :q" do
81
- get :index, q: user_query
81
+ get :index, params: { q: user_query }
82
82
  expect(session[:search]).to_not be_nil
83
83
  expect(session[:search].keys).to include 'id'
84
84
 
@@ -89,11 +89,11 @@ describe CatalogController do
89
89
 
90
90
  # check with no user manipulation
91
91
  describe "for default query" do
92
- it "should get documents when no query", :integration => true do
92
+ it "gets documents when no query", :integration => true do
93
93
  get :index
94
94
  expect(assigns(:response).docs).to_not be_empty
95
95
  end
96
- it "should get facets when no query", :integration => true do
96
+ it "gets facets when no query", :integration => true do
97
97
  get :index
98
98
  assert_facets_have_values(assigns(:response).aggregations)
99
99
  end
@@ -113,8 +113,8 @@ describe CatalogController do
113
113
  end
114
114
 
115
115
  describe "with format :rss" do
116
- it "should get the feed", :integration => true do
117
- get :index, :format => 'rss'
116
+ it "gets the feed", :integration => true do
117
+ get :index, params: { format: 'rss' }
118
118
  expect(response).to be_success
119
119
  end
120
120
  end
@@ -122,7 +122,7 @@ describe CatalogController do
122
122
  describe "with format :json" do
123
123
  render_views
124
124
  before do
125
- get :index, :format => 'json'
125
+ get :index, params: { format: 'json' }
126
126
  expect(response).to be_success
127
127
  end
128
128
  let(:json) { JSON.parse(response.body)['response'] }
@@ -166,27 +166,27 @@ describe CatalogController do
166
166
  allow(@controller).to receive_messages search_results: [double, double]
167
167
  end
168
168
 
169
- it "should not render when the config is false" do
169
+ it "does not render when the config is false" do
170
170
  blacklight_config.index.respond_to.yaml = false
171
- expect { get :index, format: 'yaml' }.to raise_error ActionController::RoutingError
171
+ expect { get :index, params: { format: 'yaml' } }.to raise_error ActionController::RoutingError
172
172
  end
173
173
 
174
174
  it "renders the default when the config is true" do
175
175
  # TODO: this should really stub a template and see if it gets rendered,
176
176
  # but how to do that is non-obvious..
177
177
  blacklight_config.index.respond_to.yaml = true
178
- expect { get :index, format: 'yaml' }.to raise_error ActionView::MissingTemplate
178
+ expect { get :index, params: { format: 'yaml' } }.to raise_error ActionView::MissingTemplate
179
179
  end
180
180
 
181
- it "should pass a hash to the render call" do
181
+ it "passes a hash to the render call" do
182
182
  blacklight_config.index.respond_to.yaml = { nothing: true, layout: false }
183
- get :index, format: 'yaml'
183
+ get :index, params: { format: 'yaml' }
184
184
  expect(response.body).to be_blank
185
185
  end
186
186
 
187
- it "should evaluate a proc" do
187
+ it "evaluates a proc" do
188
188
  blacklight_config.index.respond_to.yaml = lambda { render text: "" }
189
- get :index, format: 'yaml'
189
+ get :index, params: { format: 'yaml' }
190
190
  expect(response.body).to be_empty
191
191
  end
192
192
 
@@ -196,7 +196,7 @@ describe CatalogController do
196
196
  end
197
197
 
198
198
  blacklight_config.index.respond_to.yaml = :render_some_yaml
199
- get :index, format: 'yaml'
199
+ get :index, params: { format: 'yaml' }
200
200
  expect(response.body).to be_blank
201
201
  end
202
202
  end
@@ -206,38 +206,38 @@ describe CatalogController do
206
206
  describe "track action" do
207
207
  doc_id = '2007020969'
208
208
 
209
- it "should persist the search session id value into session[:search]" do
210
- put :track, :id => doc_id, :counter => 3, search_id: "123"
209
+ it "persists the search session id value into session[:search]" do
210
+ put :track, params: { id: doc_id, counter: 3, search_id: "123" }
211
211
  expect(session[:search]['id']).to eq "123"
212
212
  end
213
213
 
214
- it "should set counter value into session[:search]" do
215
- put :track, :id => doc_id, :counter => 3
214
+ it "sets counter value into session[:search]" do
215
+ put :track, params: { id: doc_id, counter: 3 }
216
216
  expect(session[:search]['counter']).to eq "3"
217
217
  end
218
218
 
219
- it "should record the current per_page setting" do
220
- put :track, :id => doc_id, :counter => 3, :per_page => 15
219
+ it "records the current per_page setting" do
220
+ put :track, params: { id: doc_id, counter: 3, per_page: 15 }
221
221
  expect(session[:search]['per_page']).to eq "15"
222
222
  end
223
223
 
224
- it "should redirect to show action for doc id" do
225
- put :track, :id => doc_id, :counter => 3
224
+ it "redirects to show action for doc id" do
225
+ put :track, params: { id: doc_id, counter: 3 }
226
226
  assert_redirected_to(solr_document_path(doc_id))
227
227
  end
228
228
 
229
229
  it "HTTP status code for redirect should be 303" do
230
- put :track, :id => doc_id, :counter => 3
230
+ put :track, params: { id: doc_id, counter: 3 }
231
231
  expect(response.status).to eq 303
232
232
  end
233
233
 
234
- it "should redirect to the path given in the redirect param" do
235
- put :track, :id => doc_id, :counter => 3, redirect: '/xyz'
234
+ it "redirects to the path given in the redirect param" do
235
+ put :track, params: { id: doc_id, counter: 3, redirect: '/xyz' }
236
236
  assert_redirected_to("/xyz")
237
237
  end
238
238
 
239
- it "should redirect to the path of the uri given in the redirect param" do
240
- put :track, :id => doc_id, :counter => 3, redirect: 'http://localhost:3000/xyz'
239
+ it "redirects to the path of the uri given in the redirect param" do
240
+ put :track, params: { id: doc_id, counter: 3, redirect: 'http://localhost:3000/xyz' }
241
241
  assert_redirected_to("/xyz")
242
242
  end
243
243
  end
@@ -248,15 +248,15 @@ describe CatalogController do
248
248
  doc_id = '2007020969'
249
249
 
250
250
  describe "with format :html" do
251
- it "should get document", :integration => true do
252
- get :show, :id => doc_id
251
+ it "gets document", :integration => true do
252
+ get :show, params: { id: doc_id }
253
253
  expect(assigns[:document]).to_not be_nil
254
254
  end
255
255
  end
256
256
 
257
257
  describe "with format :json" do
258
- it "should get the feed" do
259
- get :show, id: doc_id, format: 'json'
258
+ it "gets the feed" do
259
+ get :show, params: { id: doc_id, format: 'json' }
260
260
  expect(response).to be_success
261
261
  json = JSON.parse response.body
262
262
  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"])
@@ -276,33 +276,33 @@ describe CatalogController do
276
276
 
277
277
  @search_session = { :id => current_search.id }
278
278
  end
279
- it "should set previous document if counter present in session" do
279
+ it "sets previous document if counter present in session" do
280
280
  session[:search] = @search_session.merge('counter' => 2)
281
- get :show, :id => doc_id
281
+ get :show, params: { id: doc_id }
282
282
  expect(assigns[:previous_document]).to_not be_nil
283
283
  end
284
- it "should not set previous or next document if session is blank" do
285
- get :show, :id => doc_id
284
+ it "does not set previous or next document if session is blank" do
285
+ get :show, params: { id: doc_id }
286
286
  expect(assigns[:previous_document]).to be_nil
287
287
  expect(assigns[:next_document]).to be_nil
288
288
  end
289
- it "should not set previous or next document if session[:search]['counter'] is nil" do
289
+ it "does not set previous or next document if session[:search]['counter'] is nil" do
290
290
  session[:search] = {}
291
- get :show, :id => doc_id
291
+ get :show, params: { id: doc_id }
292
292
  expect(assigns[:previous_document]).to be_nil
293
293
  expect(assigns[:next_document]).to be_nil
294
294
  end
295
- it "should set next document if counter present in session" do
295
+ it "sets next document if counter present in session" do
296
296
  session[:search] = @search_session.merge('counter' => 2)
297
- get :show, :id => doc_id
297
+ get :show, params: { id: doc_id }
298
298
  expect(assigns[:next_document]).to_not be_nil
299
299
  end
300
300
 
301
- it "should not break if solr returns an exception" do
301
+ it "does not break if solr returns an exception" do
302
302
  allow(controller).to receive(:get_previous_and_next_documents_for_search) {
303
303
  raise Blacklight::Exceptions::InvalidRequest.new "Error"
304
304
  }
305
- get :show, :id => doc_id
305
+ get :show, params: { id: doc_id }
306
306
  expect(assigns[:previous_document]).to be_nil
307
307
  expect(assigns[:next_document]).to be_nil
308
308
  end
@@ -310,15 +310,15 @@ describe CatalogController do
310
310
 
311
311
  # NOTE: status code is always 200 in isolation mode ...
312
312
  it "HTTP status code for GET should be 200", :integration => true do
313
- get :show, :id => doc_id
313
+ get :show, params: { id: doc_id }
314
314
  expect(response).to be_success
315
315
  end
316
- it "should render show.html.erb" do
316
+ it "renders show.html.erb" do
317
317
  @mock_response = double()
318
318
  @mock_document = double()
319
319
  allow(@mock_document).to receive_messages(:export_formats => {})
320
320
  allow(controller).to receive_messages(fetch: [@mock_response, @mock_document])
321
- get :show, :id => doc_id
321
+ get :show, params: { id: doc_id }
322
322
  expect(response).to render_template(:show)
323
323
  end
324
324
 
@@ -330,10 +330,10 @@ describe CatalogController do
330
330
  allow(controller).to receive_messages(:find => @mock_response )
331
331
  end
332
332
  before(:each) do
333
- get :show, :id => doc_id
333
+ get :show, params: { id: doc_id }
334
334
  @document = assigns[:document]
335
335
  end
336
- it "should be a SolrDocument" do
336
+ it "is a SolrDocument" do
337
337
  expect(@document).to be_instance_of(SolrDocument)
338
338
  end
339
339
  end
@@ -380,8 +380,8 @@ describe CatalogController do
380
380
  :get_single_doc_via_search => @mock_document)
381
381
  end
382
382
 
383
- it "should respond to an extension-registered format properly" do
384
- get :show, :id => doc_id, :format => "mock"
383
+ it "responds to an extension-registered format properly" do
384
+ get :show, params: { id: doc_id, format: 'mock' }
385
385
  expect(response).to be_success
386
386
  expect(response.body).to match /mock_export/
387
387
  end
@@ -404,12 +404,12 @@ describe CatalogController do
404
404
  allow(controller).to receive_messages(find: @mock_response)
405
405
 
406
406
  end
407
- it "should return an opensearch description" do
408
- get :opensearch, :format => 'xml'
407
+ it "returns an opensearch description" do
408
+ get :opensearch, params: { format: 'xml' }
409
409
  expect(response).to be_success
410
410
  end
411
- it "should return valid JSON" do
412
- get :opensearch,:format => 'json', :q => "a"
411
+ it "returns valid JSON" do
412
+ get :opensearch, params: { format: 'json', q: 'a' }
413
413
  expect(response).to be_success
414
414
  end
415
415
  end
@@ -424,69 +424,69 @@ describe CatalogController do
424
424
  SolrDocument.use_extension( Blacklight::Document::Sms )
425
425
  end
426
426
  describe "email" do
427
- it "should give error if no TO parameter" do
428
- post :email, :id => doc_id
427
+ it "gives error if no TO parameter" do
428
+ post :email, params: { id: doc_id }
429
429
  expect(request.flash[:error]).to eq "You must enter a recipient in order to send this message"
430
430
  end
431
- it "should give an error if the email address is not valid" do
432
- post :email, :id => doc_id, :to => 'test_bad_email'
431
+ it "gives an error if the email address is not valid" do
432
+ post :email, params: { id: doc_id, to: 'test_bad_email' }
433
433
  expect(request.flash[:error]).to eq "You must enter a valid email address"
434
434
  end
435
- it "should not give error if no Message parameter is set" do
436
- post :email, :id => doc_id, :to => 'test_email@projectblacklight.org'
435
+ it "does not give error if no Message parameter is set" do
436
+ post :email, params: { id: doc_id, to: 'test_email@projectblacklight.org' }
437
437
  expect(request.flash[:error]).to be_nil
438
438
  end
439
- it "should redirect back to the record upon success" do
439
+ it "redirects back to the record upon success" do
440
440
  mock_mailer = double
441
441
  allow(mock_mailer).to receive(:deliver)
442
442
  allow(RecordMailer).to receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer
443
443
 
444
- post :email, :id => doc_id, :to => 'test_email@projectblacklight.org', :message => 'xyz'
444
+ post :email, params: { id: doc_id, to: 'test_email@projectblacklight.org', message: 'xyz' }
445
445
  expect(request.flash[:error]).to be_nil
446
446
  expect(request).to redirect_to(solr_document_path(doc_id))
447
447
  end
448
- it "should render email_success for XHR requests" do
449
- xhr :post, :email, :id => doc_id, :to => 'test_email@projectblacklight.org'
448
+ it "renders email_success for XHR requests" do
449
+ post :email, xhr: true, params: { id: doc_id, to: 'test_email@projectblacklight.org' }
450
450
  expect(request).to render_template 'email_success'
451
451
  expect(request.flash[:success]).to eq "Email Sent"
452
452
  end
453
453
  end
454
454
  describe "sms" do
455
- it "should give error if no phone number is given" do
456
- post :sms, :id => doc_id, :carrier => 'att'
455
+ it "gives error if no phone number is given" do
456
+ post :sms, params: { id: doc_id, carrier: 'att' }
457
457
  expect(request.flash[:error]).to eq "You must enter a recipient's phone number in order to send this message"
458
458
  end
459
- it "should give an error when a carrier is not provided" do
460
- post :sms, :id => doc_id, :to => '5555555555', :carrier => ''
459
+ it "gives an error when a carrier is not provided" do
460
+ post :sms, params: { id: doc_id, to: '5555555555', carrier: '' }
461
461
  expect(request.flash[:error]).to eq "You must select a carrier"
462
462
  end
463
- it "should give an error when the phone number is not 10 digits" do
464
- post :sms, :id => doc_id, :to => '555555555', :carrier => 'txt.att.net'
463
+ it "gives an error when the phone number is not 10 digits" do
464
+ post :sms, params: { id: doc_id, to: '555555555', carrier: 'txt.att.net' }
465
465
  expect(request.flash[:error]).to eq "You must enter a valid 10 digit phone number"
466
466
  end
467
- it "should give an error when the carrier is not in our list of carriers" do
468
- post :sms, :id => doc_id, :to => '5555555555', :carrier => 'no-such-carrier'
467
+ it "gives an error when the carrier is not in our list of carriers" do
468
+ post :sms, params: { id: doc_id, to: '5555555555', carrier: 'no-such-carrier' }
469
469
  expect(request.flash[:error]).to eq "You must enter a valid carrier"
470
470
  end
471
- it "should allow punctuation in phone number" do
472
- post :sms, :id => doc_id, :to => '(555) 555-5555', :carrier => 'txt.att.net'
471
+ it "allows punctuation in phone number" do
472
+ post :sms, params: { id: doc_id, to: '(555) 555-5555', carrier: 'txt.att.net' }
473
473
  expect(request.flash[:error]).to be_nil
474
474
  expect(request).to redirect_to(solr_document_path(doc_id))
475
475
  end
476
- it "should send to the appropriate carrier email address" do
476
+ it "sends to the appropriate carrier email address" do
477
477
  mock_mailer = double
478
478
  allow(mock_mailer).to receive(:deliver)
479
479
  expect(RecordMailer).to receive(:sms_record).with(anything, { to: '5555555555@txt.att.net' }, hash_including(:host => 'test.host')).and_return mock_mailer
480
- post :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
480
+ post :sms, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
481
481
  end
482
- it "should redirect back to the record upon success" do
483
- post :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
482
+ it "redirects back to the record upon success" do
483
+ post :sms, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
484
484
  expect(request.flash[:error]).to eq nil
485
485
  expect(request).to redirect_to(solr_document_path(doc_id))
486
486
  end
487
487
 
488
- it "should render sms_success template for XHR requests" do
489
- xhr :post, :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
488
+ it "renders sms_success template for XHR requests" do
489
+ post :sms, xhr: true, params: { id: doc_id, to: '5555555555', carrier: 'txt.att.net' }
490
490
  expect(request).to render_template 'sms_success'
491
491
  expect(request.flash[:success]).to eq "SMS Sent"
492
492
  end
@@ -494,28 +494,28 @@ describe CatalogController do
494
494
  end
495
495
 
496
496
  describe "errors" do
497
- it "should return status 404 for a record that doesn't exist" do
497
+ it "returns status 404 for a record that doesn't exist" do
498
498
  @mock_response = double(documents: [])
499
499
  allow(controller).to receive_messages(:find => @mock_response)
500
- get :show, :id=>"987654321"
500
+ get :show, params: { id: "987654321" }
501
501
  expect(response.status).to eq 404
502
502
  expect(response.content_type).to eq Mime::HTML
503
503
  end
504
- it "should return status 404 for a record that doesn't exist even for non-html format" do
504
+ it "returns status 404 for a record that doesn't exist even for non-html format" do
505
505
  @mock_response = double(documents: [])
506
506
  allow(controller).to receive_messages(:find => @mock_response)
507
507
 
508
- get :show, :id=>"987654321", :format => "xml"
508
+ get :show, params: { id: "987654321", format: "xml" }
509
509
  expect(response.status).to eq 404
510
510
  expect(response.content_type).to eq Mime::XML
511
511
  end
512
512
 
513
- it "should redirect the user to the root url for a bad search" do
513
+ it "redirects the user to the root url for a bad search" do
514
514
  fake_error = Blacklight::Exceptions::InvalidRequest.new
515
515
  allow(Rails.env).to receive_messages(:test? => false)
516
516
  allow(controller).to receive(:search_results) { |*args| raise fake_error }
517
517
  expect(controller.logger).to receive(:error).with(fake_error)
518
- get :index, :q=>"+"
518
+ get :index, params: { q: '+' }
519
519
 
520
520
  expect(response.redirect_url).to eq root_url
521
521
  expect(request.flash[:notice]).to eq "Sorry, I don't understand your search."
@@ -523,12 +523,12 @@ describe CatalogController do
523
523
  expect(response.status).to eq 302
524
524
  end
525
525
 
526
- it "should return status 500 if the catalog path is raising an exception" do
526
+ it "returns status 500 if the catalog path is raising an exception" do
527
527
  fake_error = Blacklight::Exceptions::InvalidRequest.new
528
528
  allow(controller).to receive(:search_results) { |*args| raise fake_error }
529
529
  allow(controller.flash).to receive(:sweep)
530
530
  allow(controller).to receive(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
531
- expect { get :index, q: "+" }.to raise_error Blacklight::Exceptions::InvalidRequest
531
+ expect { get :index, params: { q: '+' } }.to raise_error Blacklight::Exceptions::InvalidRequest
532
532
  end
533
533
 
534
534
  end
@@ -540,7 +540,7 @@ describe CatalogController do
540
540
  allow(controller).to receive(:has_user_authentication_provider?) { false }
541
541
  end
542
542
 
543
- it "should not show user util links" do
543
+ it "does not show user util links" do
544
544
  get :index
545
545
  expect(response.body).to_not match /Login/
546
546
  end
@@ -548,14 +548,14 @@ describe CatalogController do
548
548
 
549
549
  describe "facet" do
550
550
  describe "requesting js" do
551
- it "should be successful" do
552
- xhr :get, :facet, id: 'format'
551
+ it "is successful" do
552
+ get :facet, xhr: true, params: { id: 'format' }
553
553
  expect(response).to be_successful
554
554
  end
555
555
  end
556
556
  describe "requesting html" do
557
- it "should be successful" do
558
- get :facet, id: 'format'
557
+ it "is successful" do
558
+ get :facet, params: { id: 'format' }
559
559
  expect(response).to be_successful
560
560
  expect(assigns[:response]).to be_kind_of Blacklight::Solr::Response
561
561
  expect(assigns[:facet]).to be_kind_of Blacklight::Configuration::FacetField
@@ -566,7 +566,7 @@ describe CatalogController do
566
566
  describe "requesting json" do
567
567
  render_views
568
568
  it "is successful" do
569
- get :facet, id: 'format', format: 'json'
569
+ get :facet, params: { id: 'format', format: 'json' }
570
570
  expect(response).to be_successful
571
571
  json = JSON.parse(response.body)
572
572
  expect(json["response"]["facets"]["items"].first["value"]).to eq 'Book'
@@ -575,7 +575,7 @@ describe CatalogController do
575
575
  end
576
576
 
577
577
  describe "#add_to_search_history" do
578
- it "should prepend the current search to the list" do
578
+ it "prepends the current search to the list" do
579
579
  session[:history] = []
580
580
  controller.send(:add_to_search_history, double(:id => 1))
581
581
  expect(session[:history]).to have(1).item
@@ -585,7 +585,7 @@ describe CatalogController do
585
585
  expect(session[:history].first).to eq 2
586
586
  end
587
587
 
588
- it "should remove searches from the list when the list gets too big" do
588
+ it "removes searches from the list when the list gets too big" do
589
589
  allow(controller).to receive(:blacklight_config).and_return(double(:search_history_window => 5))
590
590
  session[:history] = (0..4).to_a.reverse
591
591
 
@@ -601,7 +601,7 @@ describe CatalogController do
601
601
  describe "current_search_session" do
602
602
  let(:parameter_class) { ActionController::Parameters }
603
603
 
604
- it "should create a session if we're on an search action" do
604
+ it "creates a session if we're on an search action" do
605
605
  allow(controller).to receive_messages(:action_name => "index")
606
606
  allow(controller).to receive_messages(params: parameter_class.new(q: "x", page: 5))
607
607
  session = controller.send(:current_search_session)
@@ -609,13 +609,13 @@ describe CatalogController do
609
609
  expect(session.query_params).to_not include(:page => 5)
610
610
  end
611
611
 
612
- it "should create a session if a search context was provided" do
612
+ it "creates a session if a search context was provided" do
613
613
  allow(controller).to receive_messages(params: parameter_class.new(search_context: JSON.dump(:q => "x")))
614
614
  session = controller.send(:current_search_session)
615
615
  expect(session.query_params).to include("q" => "x")
616
616
  end
617
617
 
618
- it "should use an existing session if a search id was provided" do
618
+ it "uses an existing session if a search id was provided" do
619
619
  s = Search.create(:query_params => { :q => "x" })
620
620
  session[:history] ||= []
621
621
  session[:history] << s.id
@@ -625,7 +625,7 @@ describe CatalogController do
625
625
  expect(session).to eq(s)
626
626
  end
627
627
 
628
- it "should use an existing search session if the search is in the uri" do
628
+ it "uses an existing search session if the search is in the uri" do
629
629
  s = Search.create(:query_params => { :q => "x" })
630
630
  session[:search] ||= {}
631
631
  session[:search]['id'] = s.id
@@ -669,11 +669,11 @@ describe CatalogController do
669
669
  Rails.application.reload_routes!
670
670
  end
671
671
 
672
- it "should add the action to a list" do
672
+ it "adds the action to a list" do
673
673
  expect(CatalogController.blacklight_config.show.document_actions).to have_key(:like)
674
674
  end
675
675
 
676
- it "should define the action method" do
676
+ it "defines the action method" do
677
677
  expect(controller.respond_to?(:like)).to be true
678
678
  end
679
679
 
@@ -683,7 +683,7 @@ describe CatalogController do
683
683
  allow(controller).to receive(:validate_like_params).and_return(true)
684
684
  post :like
685
685
  end
686
- it "should call the supplied method on post" do
686
+ it "calls the supplied method on post" do
687
687
  expect(controller).to have_received(:perform_like)
688
688
  end
689
689
  end
@@ -691,7 +691,7 @@ describe CatalogController do
691
691
  describe "with failure" do
692
692
  describe "with invalid params" do
693
693
  before { allow(controller).to receive(:validate_like_params).and_return(false) }
694
- it "should not call the supplied method if validation failed" do
694
+ it "does not call the supplied method if validation failed" do
695
695
  expect(controller).not_to have_received(:perform_like)
696
696
  end
697
697
  end
@@ -700,15 +700,15 @@ describe CatalogController do
700
700
  end
701
701
 
702
702
  describe "search_action_url" do
703
- it "should be the same as the catalog url" do
704
- get :index, :page => 1
703
+ it "is the same as the catalog url" do
704
+ get :index, params: { page: 1 }
705
705
  expect(controller.send(:search_action_url, q: "xyz")).to eq root_url(q: "xyz")
706
706
  end
707
707
  end
708
708
 
709
709
  describe "search_facet_url" do
710
- it "should be the same as the catalog url" do
711
- get :index, :page => 1
710
+ it "is the same as the catalog url" do
711
+ get :index, params: { page: 1 }
712
712
  expect(controller.send(:search_facet_url, id: "some_facet", page: 5)).to eq facet_catalog_url(id: "some_facet")
713
713
  end
714
714
  end