blacklight 5.5.1 → 5.5.2

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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/VERSION +1 -1
  4. data/app/helpers/blacklight/blacklight_helper_behavior.rb +8 -16
  5. data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -1
  6. data/app/helpers/blacklight/facets_helper_behavior.rb +1 -1
  7. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -1
  8. data/app/helpers/blacklight/url_helper_behavior.rb +5 -1
  9. data/app/views/catalog/_view_type_group.html.erb +1 -1
  10. data/blacklight.gemspec +2 -1
  11. data/gemfiles/rails3.gemfile +1 -1
  12. data/gemfiles/rails4.1.gemfile +1 -1
  13. data/gemfiles/rails4.gemfile +1 -1
  14. data/lib/blacklight/catalog.rb +0 -1
  15. data/lib/blacklight/solr/facet_paginator.rb +22 -10
  16. data/lib/generators/blacklight/install_generator.rb +1 -1
  17. data/spec/controllers/bookmarks_controller_spec.rb +6 -6
  18. data/spec/controllers/catalog_controller_spec.rb +48 -48
  19. data/spec/features/alternate_controller_spec.rb +3 -3
  20. data/spec/features/record_view_spec.rb +1 -1
  21. data/spec/features/search_filters_spec.rb +4 -4
  22. data/spec/features/search_results_spec.rb +12 -12
  23. data/spec/helpers/blacklight_helper_spec.rb +83 -83
  24. data/spec/helpers/catalog_helper_spec.rb +37 -37
  25. data/spec/helpers/configuration_helper_spec.rb +39 -39
  26. data/spec/helpers/facets_helper_spec.rb +37 -37
  27. data/spec/helpers/render_constraints_helper_spec.rb +6 -1
  28. data/spec/helpers/search_history_constraints_helper_spec.rb +9 -9
  29. data/spec/helpers/url_helper_spec.rb +49 -39
  30. data/spec/lib/blacklight/configurable_spec.rb +5 -5
  31. data/spec/lib/blacklight/configuration_spec.rb +8 -8
  32. data/spec/lib/blacklight/facet_paginator_spec.rb +25 -0
  33. data/spec/lib/blacklight/routes_spec.rb +4 -4
  34. data/spec/lib/blacklight/search_fields_spec.rb +3 -3
  35. data/spec/lib/blacklight/solr/document_spec.rb +2 -2
  36. data/spec/lib/blacklight/solr_helper_spec.rb +37 -37
  37. data/spec/lib/blacklight/solr_response/group_response_spec.rb +1 -1
  38. data/spec/lib/blacklight/solr_response_spec.rb +31 -31
  39. data/spec/lib/document_presenter_spec.rb +41 -41
  40. data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
  41. data/spec/models/record_mailer_spec.rb +1 -1
  42. data/spec/models/search_spec.rb +1 -1
  43. data/spec/routing/catalog_routing_spec.rb +2 -2
  44. data/spec/spec_helper.rb +1 -0
  45. data/spec/support/include_text.rb +2 -3
  46. data/spec/views/catalog/_constraints.html.erb_spec.rb +7 -7
  47. data/spec/views/catalog/_document.html.erb_spec.rb +4 -4
  48. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +2 -2
  49. data/spec/views/catalog/_facets.html.erb_spec.rb +6 -6
  50. data/spec/views/catalog/_index_default.erb_spec.rb +10 -10
  51. data/spec/views/catalog/_index_header_default.html.erb_spec.rb +5 -5
  52. data/spec/views/catalog/_show_default.erb_spec.rb +10 -10
  53. data/spec/views/catalog/_show_sidebar.erb_spec.rb +5 -5
  54. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +1 -1
  55. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +4 -4
  56. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +5 -2
  57. data/spec/views/catalog/facet.html.erb_spec.rb +5 -5
  58. data/spec/views/catalog/index.atom.builder_spec.rb +2 -2
  59. data/spec/views/catalog/index.html.erb_spec.rb +5 -5
  60. data/spec/views/catalog/show.html.erb_spec.rb +8 -8
  61. data/tasks/blacklight.rake +1 -2
  62. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f505877f6844d0240c6ceb14695e1addd5a9348c
4
- data.tar.gz: 38c117040379ce80b28cf0e09b5de46ac8ab9f74
3
+ metadata.gz: e6f521c7766d2dd6e7b718a222296f2d0dad680a
4
+ data.tar.gz: 324a81ef36346eca1526cbe54ccbfc604703a7aa
5
5
  SHA512:
6
- metadata.gz: a3f530b8c8d637783ee9fb1b049cc0a0f86b0a29160dcb181bbac9bfadb511ce6738d3fae194e89e9ca41c9dc438a3447a1662fe6f242d8652da307f9004742b
7
- data.tar.gz: b91b2be73a23c411503d3a8243a409c1a14b7544d93ff7ec69b4fe2ed3abc790821bda6acfaf3724d35f8fd1900723a27f1477022a7cd2e72303fbc6ade10eb6
6
+ metadata.gz: 9d826574a0c0c6562857e3e846f323bd9e9bcc27d29b4f7efdb394c8c7a9c8372a43be6ea7972cdce406fc57d3f373616be37c54f1aa35edcbaad45c5703e690
7
+ data.tar.gz: 5aa333a5d25378061b79c61d0c94e07a912b197a6234e6ef9153749b7b8a04ff8eb65fd21d9e68b928ffb510885bcdcebad0bcbc157fb4605e7e5cf0209f2669
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gemspec path: File.expand_path('..', __FILE__)
9
9
  gem 'simplecov', '~> 0.7.1', require: false
10
10
  gem 'coveralls', require: false
11
11
 
12
- gem 'engine_cart', '~> 0.3.0'
12
+ gem 'engine_cart', '~> 0.4'
13
13
 
14
14
  group :test do
15
15
  gem "blacklight-marc", "~> 5.0", github: "projectblacklight/blacklight_marc"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.5.1
1
+ 5.5.2
@@ -410,13 +410,10 @@ module Blacklight::BlacklightHelperBehavior
410
410
  # @return [String]
411
411
  def render_document_index_with_view view, documents, locals = {}
412
412
  document_index_path_templates.each do |str|
413
- # XXX rather than handling this logic through exceptions, maybe there's a Rails internals method
414
- # for determining if a partial template exists..
415
- begin
416
- return render(:partial => (str % { :index_view_type => view }), :locals => locals.merge(:documents => documents) )
417
- rescue ActionView::MissingTemplate
418
- nil
419
- end
413
+ partial = str % { index_view_type: view }
414
+ logger.debug "Looking for document index partial #{partial}"
415
+ template = lookup_context.find_all(partial, lookup_context.prefixes, true, locals.keys + [:documents], {}).first
416
+ return template.render(self, locals.merge(documents: documents)) if template
420
417
  end
421
418
 
422
419
  return ""
@@ -502,15 +499,10 @@ module Blacklight::BlacklightHelperBehavior
502
499
  end
503
500
 
504
501
  document_partial_path_templates.each do |str|
505
- # XXX rather than handling this logic through exceptions, maybe there's a Rails internals method
506
- # for determining if a partial template exists..
507
- begin
508
- partial = str % { action_name: base_name, format: format, index_view_type: document_index_view_type }
509
- logger.debug "Looking for document partial #{partial}"
510
- return render partial: partial, locals: locals.merge(document: doc)
511
- rescue ActionView::MissingTemplate
512
- nil
513
- end
502
+ partial = str % { action_name: base_name, format: format, index_view_type: document_index_view_type }
503
+ logger.debug "Looking for document partial #{partial}"
504
+ template = lookup_context.find_all(partial, lookup_context.prefixes, true, locals.keys + [:document], {}).first
505
+ return template.render(self, locals.merge(document: doc)) if template
514
506
  end
515
507
 
516
508
  return ''
@@ -131,7 +131,7 @@ module Blacklight::CatalogHelperBehavior
131
131
  # @param [SolrDocument]
132
132
  # @return [Boolean]
133
133
  def has_thumbnail? document
134
- blacklight_config.view_config(document_index_view_type).thumbnail_method or
134
+ blacklight_config.view_config(document_index_view_type).thumbnail_method.present? or
135
135
  blacklight_config.view_config(document_index_view_type).thumbnail_field && document.has?(blacklight_config.view_config(document_index_view_type).thumbnail_field)
136
136
  end
137
137
 
@@ -188,7 +188,7 @@ module Blacklight::FacetsHelperBehavior
188
188
  facet_config = facet_configuration_for_field(field)
189
189
 
190
190
  value = if item.respond_to? :label
191
- value = item.label
191
+ item.label
192
192
  else
193
193
  facet_value_for_facet_item(item)
194
194
  end
@@ -33,12 +33,13 @@ module Blacklight::RenderConstraintsHelperBehavior
33
33
  # @return [String]
34
34
  def render_constraints_query(localized_params = params)
35
35
  # So simple don't need a view template, we can just do it here.
36
+ scope = localized_params.delete(:route_set) || self
36
37
  return "".html_safe if localized_params[:q].blank?
37
38
 
38
39
  render_constraint_element(constraint_query_label(localized_params),
39
40
  localized_params[:q],
40
41
  :classes => ["query"],
41
- :remove => url_for(localized_params.merge(:q=>nil, :action=>'index')))
42
+ :remove => scope.url_for(localized_params.merge(:q=>nil, :action=>'index')))
42
43
  end
43
44
 
44
45
  ##
@@ -115,7 +115,11 @@ module Blacklight::UrlHelperBehavior
115
115
  query_params[:page] = ((counter - 1)/ per_page) + 1
116
116
  end
117
117
 
118
- link_url = scope.url_for(query_params)
118
+ link_url = if query_params.empty?
119
+ search_action_path(only_path: true)
120
+ else
121
+ scope.url_for(query_params)
122
+ end
119
123
  label = opts.delete(:label)
120
124
 
121
125
  if link_url =~ /bookmarks/
@@ -1,4 +1,4 @@
1
- <% if has_alternative_views? -%>
1
+ <% if show_sort_and_per_page? and has_alternative_views? -%>
2
2
  <div class="view-type">
3
3
  <span class="sr-only"><%= t('blacklight.search.view_title') %></span>
4
4
  <div class="view-type-group btn-group">
data/blacklight.gemspec CHANGED
@@ -26,8 +26,9 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.add_development_dependency "jettywrapper", ">= 1.7.0"
28
28
  s.add_development_dependency "blacklight-marc", "~> 5.0"
29
- s.add_development_dependency "rspec-rails", "~> 2.99"
29
+ s.add_development_dependency "rspec-rails", "~> 3.0"
30
30
  s.add_development_dependency "rspec-its"
31
+ s.add_development_dependency "rspec-collection_matchers", ">= 1.0"
31
32
  s.add_development_dependency "capybara"
32
33
  s.add_development_dependency "poltergeist"
33
34
  s.add_development_dependency 'engine_cart', ">= 0.1.0"
@@ -6,4 +6,4 @@ if File.exists?(file)
6
6
  instance_eval File.read(file)
7
7
  end
8
8
 
9
- gem 'rails', "3.2.17"
9
+ gem 'rails', "3.2.19"
@@ -9,4 +9,4 @@ end
9
9
  gem 'sass', '~> 3.2.15'
10
10
  gem 'sprockets', '~> 2.11.0'
11
11
 
12
- gem 'rails', '4.1.0'
12
+ gem 'rails', '4.1.4'
@@ -10,4 +10,4 @@ end
10
10
  gem 'sass', '~> 3.2.15'
11
11
  gem 'sprockets', '~> 2.11.0'
12
12
 
13
- gem 'rails', '4.0.3'
13
+ gem 'rails', '4.0.8'
@@ -75,7 +75,6 @@ module Blacklight::Catalog
75
75
  @response = get_facet_field_response(@facet.field, params)
76
76
  @display_facet = @response.facets.first
77
77
 
78
- # @pagination was deprecated in Blacklight 5.1
79
78
  @pagination = facet_paginator(@facet, @display_facet)
80
79
 
81
80
 
@@ -25,7 +25,7 @@ module Blacklight::Solr
25
25
  class << self; attr_accessor :request_keys end # create a class method
26
26
  def request_keys ; self.class.request_keys ; end # shortcut
27
27
 
28
- attr_reader :total_count, :items, :offset, :limit, :sort
28
+ attr_reader :offset, :limit, :sort
29
29
 
30
30
  # all_facet_values is a list of facet value objects returned by solr,
31
31
  # asking solr for n+1 facet values.
@@ -40,8 +40,17 @@ module Blacklight::Solr
40
40
  @limit = arguments[:limit].to_s.to_i
41
41
  # count is solr's default
42
42
  @sort = arguments[:sort] || "count"
43
- @total_count = all_facet_values.size
44
- @items = items_for_limit(all_facet_values)
43
+
44
+ @all = all_facet_values
45
+ end
46
+
47
+ # The number of records solr gave us when we asked for limit + 1 records at the current offset
48
+ def total_count
49
+ @all.size
50
+ end
51
+
52
+ def items
53
+ items_for_limit(@all)
45
54
  end
46
55
 
47
56
  def prev_page
@@ -73,20 +82,19 @@ module Blacklight::Solr
73
82
  deprecation_deprecate :has_next?
74
83
 
75
84
  def last_page?
76
- current_page >= total_pages
85
+ total_count <= limit
77
86
  end
78
87
 
79
88
  def first_page?
80
89
  current_page == 1
81
90
  end
82
91
 
92
+ # We're implementing total_pages so that this matches the API from kaminari, even though we can't
93
+ # know the total number of pages.
94
+ # https://github.com/amatsuda/kaminari/blob/v0.16.1/lib/kaminari/models/page_scope_methods.rb#L21
83
95
  def total_pages
84
- if limit == 0 #check for divide by zero
85
- 1
86
- else
87
- (total_count.to_f / limit).ceil
88
- end
89
- end
96
+ -1
97
+ end
90
98
 
91
99
  # Pass in a desired solr facet solr key ('count' or 'index', see
92
100
  # http://wiki.apache.org/solr/SimpleFacetParameters#facet.limit
@@ -99,6 +107,10 @@ module Blacklight::Solr
99
107
  params.merge(request_keys[:sort] => sort_method, request_keys[:page] => nil)
100
108
  end
101
109
 
110
+ def as_json(_ = nil)
111
+ { 'items' => items.as_json, 'limit' => limit, 'offset' => offset, 'sort' => sort }
112
+ end
113
+
102
114
  private
103
115
  # setting limit to 0 implies no limit
104
116
  # @return an array of facets on the page
@@ -27,7 +27,7 @@ module Blacklight
27
27
  copy_file "config/jetty.yml"
28
28
 
29
29
  append_to_file "Rakefile",
30
- "\nZIP_URL = \"https://github.com/projectblacklight/blacklight-jetty/archive/v4.6.0.zip\"\n" +
30
+ "\nZIP_URL = \"https://github.com/projectblacklight/blacklight-jetty/archive/v4.9.0.zip\"\n" +
31
31
  "require 'jettywrapper'\n"
32
32
  end
33
33
 
@@ -10,10 +10,10 @@ describe BookmarksController do
10
10
  end
11
11
 
12
12
  it "has a 500 status code when fails is success" do
13
- @controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
14
- @controller.stub_chain(:current_or_guest_user, :persisted?).and_return(true)
15
- @controller.stub_chain(:current_or_guest_user, :bookmarks, :where, :exists?).and_return(false)
16
- @controller.stub_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
13
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
14
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :persisted?).and_return(true)
15
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :exists?).and_return(false)
16
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
17
17
  xhr :put, :update, :id => 'iamabooboo', :format => :js
18
18
  expect(response.code).to eq "500"
19
19
  end
@@ -33,8 +33,8 @@ describe BookmarksController do
33
33
 
34
34
  it "has a 500 status code when delete is not success" do
35
35
  bm = double(Bookmark)
36
- @controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
37
- @controller.stub_chain(:current_or_guest_user, :bookmarks, :where, :first).and_return(double('bookmark', delete: nil, destroyed?: false))
36
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
37
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :first).and_return(double('bookmark', delete: nil, destroyed?: false))
38
38
 
39
39
  xhr :delete, :destroy, :id => 'pleasekillme', :format => :js
40
40
 
@@ -22,7 +22,7 @@ describe CatalogController do
22
22
  let(:user_query) { 'history' } # query that will get results
23
23
 
24
24
  it "should have no search history if no search criteria" do
25
- controller.should_receive(:get_search_results)
25
+ allow(controller).to receive(:get_search_results)
26
26
  session[:history] = []
27
27
  get :index
28
28
  expect(session[:history]).to be_empty
@@ -70,7 +70,7 @@ describe CatalogController do
70
70
 
71
71
  describe "session" do
72
72
  before do
73
- controller.stub(:get_search_results)
73
+ allow(controller).to receive(:get_search_results)
74
74
  end
75
75
  it "should include search hash with key :q" do
76
76
  get :index, q: user_query
@@ -95,7 +95,7 @@ describe CatalogController do
95
95
  end
96
96
 
97
97
  it "should render index.html.erb" do
98
- controller.stub(:get_search_results)
98
+ allow(controller).to receive(:get_search_results)
99
99
  get :index
100
100
  expect(response).to render_template(:index)
101
101
  end
@@ -156,8 +156,8 @@ describe CatalogController do
156
156
  let(:blacklight_config) { Blacklight::Configuration.new }
157
157
 
158
158
  before :each do
159
- @controller.stub blacklight_config: blacklight_config
160
- @controller.stub get_search_results: [double, double]
159
+ allow(@controller).to receive_messages blacklight_config: blacklight_config
160
+ allow(@controller).to receive_messages get_search_results: [double, double]
161
161
  end
162
162
 
163
163
  it "should not render when the config is false" do
@@ -185,7 +185,7 @@ describe CatalogController do
185
185
  end
186
186
 
187
187
  it "with a symbol, it should call a controller method" do
188
- subject.should_receive(:render_some_yaml) do
188
+ expect(subject).to receive(:render_some_yaml) do
189
189
  subject.render nothing: true, layout: false
190
190
  end
191
191
 
@@ -256,12 +256,12 @@ describe CatalogController do
256
256
  before do
257
257
  @mock_response = double()
258
258
  @mock_document = double()
259
- @mock_document.stub(:export_formats => {})
260
- controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
259
+ allow(@mock_document).to receive_messages(:export_formats => {})
260
+ allow(controller).to receive_messages(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
261
261
  :get_previous_and_next_documents_for_search => [double(:total => 5), [double("a"), @mock_document, double("b")]])
262
262
 
263
263
  current_search = Search.create(:query_params => { :q => ""})
264
- controller.stub(:current_search_session => current_search)
264
+ allow(controller).to receive_messages(:current_search_session => current_search)
265
265
 
266
266
  @search_session = { :id => current_search.id }
267
267
  end
@@ -296,18 +296,18 @@ describe CatalogController do
296
296
  it "should render show.html.erb" do
297
297
  @mock_response = double()
298
298
  @mock_document = double()
299
- @mock_document.stub(:export_formats => {})
300
- controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document])
299
+ allow(@mock_document).to receive_messages(:export_formats => {})
300
+ allow(controller).to receive_messages(:get_solr_response_for_doc_id => [@mock_response, @mock_document])
301
301
  get :show, :id => doc_id
302
- response.should render_template(:show)
302
+ expect(response).to render_template(:show)
303
303
  end
304
304
 
305
305
  describe "@document" do
306
306
  before do
307
307
  @mock_response = double()
308
- @mock_response.stub(documents: [SolrDocument.new(id: 'my_fake_doc')])
308
+ allow(@mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc')])
309
309
  @mock_document = double()
310
- controller.stub(:find => @mock_response )
310
+ allow(controller).to receive_messages(:find => @mock_response )
311
311
  end
312
312
  before(:each) do
313
313
  get :show, :id => doc_id
@@ -332,9 +332,9 @@ describe CatalogController do
332
332
 
333
333
  before do
334
334
  @mock_response = double()
335
- @mock_response.stub(:docs => [{ :id => 'my_fake_doc' }])
335
+ allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }])
336
336
  @mock_document = double()
337
- controller.stub(find: @mock_response)
337
+ allow(controller).to receive_messages(find: @mock_response)
338
338
  end
339
339
 
340
340
  before(:each) do
@@ -351,12 +351,12 @@ describe CatalogController do
351
351
 
352
352
  before do
353
353
  @mock_response = double()
354
- @mock_response.stub(:documents => [SolrDocument.new(id: 'my_fake_doc')])
354
+ allow(@mock_response).to receive_messages(:documents => [SolrDocument.new(id: 'my_fake_doc')])
355
355
  @mock_document = double()
356
- controller.stub(:find => @mock_response,
356
+ allow(controller).to receive_messages(:find => @mock_response,
357
357
  :get_single_doc_via_search => @mock_document)
358
358
 
359
- controller.stub(:find => @mock_response,
359
+ allow(controller).to receive_messages(:find => @mock_response,
360
360
  :get_single_doc_via_search => @mock_document)
361
361
  end
362
362
 
@@ -379,9 +379,9 @@ describe CatalogController do
379
379
  before do
380
380
  @mock_response = double()
381
381
  @mock_document = double()
382
- @mock_response.stub(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')])
382
+ allow(@mock_response).to receive_messages(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')])
383
383
  @mock_document = double()
384
- controller.stub(find: @mock_response)
384
+ allow(controller).to receive_messages(find: @mock_response)
385
385
 
386
386
  end
387
387
  it "should return an opensearch description" do
@@ -398,7 +398,7 @@ describe CatalogController do
398
398
  doc_id = '2007020969'
399
399
  let(:mock_response) { double(documents: [SolrDocument.new(id: 'my_fake_doc'), SolrDocument.new(id: 'my_other_doc')]) }
400
400
  before do
401
- controller.stub(find: mock_response)
401
+ allow(controller).to receive_messages(find: mock_response)
402
402
  request.env["HTTP_REFERER"] = "/catalog/#{doc_id}"
403
403
  SolrDocument.use_extension( Blacklight::Solr::Document::Email )
404
404
  SolrDocument.use_extension( Blacklight::Solr::Document::Sms )
@@ -418,8 +418,8 @@ describe CatalogController do
418
418
  end
419
419
  it "should redirect back to the record upon success" do
420
420
  mock_mailer = double
421
- mock_mailer.should_receive(:deliver)
422
- RecordMailer.should_receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer
421
+ allow(mock_mailer).to receive(:deliver)
422
+ allow(RecordMailer).to receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer
423
423
 
424
424
  post :email, :id => doc_id, :to => 'test_email@projectblacklight.org', :message => 'xyz'
425
425
  expect(request.flash[:error]).to be_nil
@@ -456,8 +456,8 @@ describe CatalogController do
456
456
  end
457
457
  it "should redirect back to the record upon success" do
458
458
  post :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
459
- request.flash[:error].should be_nil
460
- request.should redirect_to(catalog_path(doc_id))
459
+ expect(request.flash[:error]).to eq nil
460
+ expect(request).to redirect_to(catalog_path(doc_id))
461
461
  end
462
462
 
463
463
  it "should render sms_sent template for XHR requests" do
@@ -471,14 +471,14 @@ describe CatalogController do
471
471
  describe "errors" do
472
472
  it "should return status 404 for a record that doesn't exist" do
473
473
  @mock_response = double(documents: [])
474
- controller.stub(:find => @mock_response)
474
+ allow(controller).to receive_messages(:find => @mock_response)
475
475
  get :show, :id=>"987654321"
476
476
  expect(response.status).to eq 404
477
477
  expect(response.content_type).to eq Mime::HTML
478
478
  end
479
479
  it "should return status 404 for a record that doesn't exist even for non-html format" do
480
480
  @mock_response = double(documents: [])
481
- controller.stub(:find => @mock_response)
481
+ allow(controller).to receive_messages(:find => @mock_response)
482
482
 
483
483
  get :show, :id=>"987654321", :format => "xml"
484
484
  expect(response.status).to eq 404
@@ -489,9 +489,9 @@ describe CatalogController do
489
489
  req = {}
490
490
  res = {}
491
491
  fake_error = RSolr::Error::Http.new(req, res)
492
- Rails.env.stub(:test? => false)
493
- controller.stub(:get_search_results) { |*args| raise fake_error }
494
- controller.logger.should_receive(:error).with(fake_error)
492
+ allow(Rails.env).to receive_messages(:test? => false)
493
+ allow(controller).to receive(:get_search_results) { |*args| raise fake_error }
494
+ expect(controller.logger).to receive(:error).with(fake_error)
495
495
  get :index, :q=>"+"
496
496
 
497
497
  expect(response.redirect_url).to eq root_url
@@ -504,9 +504,9 @@ describe CatalogController do
504
504
  req = {}
505
505
  res = {}
506
506
  fake_error = RSolr::Error::Http.new(req, res)
507
- controller.stub(:get_search_results) { |*args| raise fake_error }
508
- controller.flash.stub(:sweep)
509
- controller.stub(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
507
+ allow(controller).to receive(:get_search_results) { |*args| raise fake_error }
508
+ allow(controller.flash).to receive(:sweep)
509
+ allow(controller).to receive(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
510
510
  expect {
511
511
  get :index, :q=>"+"
512
512
  }.to raise_error
@@ -518,7 +518,7 @@ describe CatalogController do
518
518
  render_views
519
519
 
520
520
  before do
521
- controller.stub(:has_user_authentication_provider?) { false }
521
+ allow(controller).to receive(:has_user_authentication_provider?) { false }
522
522
  end
523
523
 
524
524
  it "should not show user util links" do
@@ -557,8 +557,8 @@ describe CatalogController do
557
557
  describe 'render_search_results_as_json' do
558
558
  before do
559
559
  controller.instance_variable_set :@document_list, [{id: '123', title_t: 'Book1'}, {id: '456', title_t: 'Book2'}]
560
- controller.stub(:pagination_info).and_return({current_page: 1, next_page: 2, prev_page: nil})
561
- controller.stub(:search_facets_as_json).and_return(
560
+ allow(controller).to receive(:pagination_info).and_return({current_page: 1, next_page: 2, prev_page: nil})
561
+ allow(controller).to receive(:search_facets_as_json).and_return(
562
562
  [{name: "format", label: "Format", items: [{value: 'Book', hits: 30, label: 'Book'}]}])
563
563
  end
564
564
 
@@ -595,7 +595,7 @@ describe CatalogController do
595
595
  end
596
596
 
597
597
  it "should remove searches from the list when the list gets too big" do
598
- controller.stub(:blacklight_config).and_return(double(:search_history_window => 5))
598
+ allow(controller).to receive(:blacklight_config).and_return(double(:search_history_window => 5))
599
599
  session[:history] = (0..4).to_a.reverse
600
600
 
601
601
  expect(session[:history]).to have(5).items
@@ -609,15 +609,15 @@ describe CatalogController do
609
609
 
610
610
  describe "current_search_session" do
611
611
  it "should create a session if we're on an search action" do
612
- controller.stub(:action_name => "index")
613
- controller.stub(:params => { :q => "x", :page => 5})
612
+ allow(controller).to receive_messages(:action_name => "index")
613
+ allow(controller).to receive_messages(:params => { :q => "x", :page => 5})
614
614
  session = controller.send(:current_search_session)
615
615
  expect(session.query_params).to include(:q => "x")
616
616
  expect(session.query_params).to_not include(:page => 5)
617
617
  end
618
618
 
619
619
  it "should create a session if a search context was provided" do
620
- controller.stub(:params => { :search_context => JSON.dump(:q => "x")})
620
+ allow(controller).to receive_messages(:params => { :search_context => JSON.dump(:q => "x")})
621
621
  session = controller.send(:current_search_session)
622
622
  expect(session.query_params).to include("q" => "x")
623
623
  end
@@ -626,7 +626,7 @@ describe CatalogController do
626
626
  s = Search.create(:query_params => { :q => "x" })
627
627
  session[:history] ||= []
628
628
  session[:history] << s.id
629
- controller.stub(:params => { :search_id => s.id})
629
+ allow(controller).to receive_messages(:params => { :search_id => s.id})
630
630
  session = controller.send(:current_search_session)
631
631
  expect(session.query_params).to include(:q => "x")
632
632
  expect(session).to eq(s)
@@ -647,16 +647,16 @@ describe CatalogController do
647
647
  describe "#has_search_parameters?" do
648
648
  subject { controller.has_search_parameters? }
649
649
  describe "none" do
650
- before { controller.stub(params: { }) }
651
- it { should be_false }
650
+ before { allow(controller).to receive_messages(params: { }) }
651
+ it { should be false }
652
652
  end
653
653
  describe "with a query" do
654
- before { controller.stub(params: { q: 'hello' }) }
655
- it { should be_true }
654
+ before { allow(controller).to receive_messages(params: { q: 'hello' }) }
655
+ it { should be true }
656
656
  end
657
657
  describe "with a facet" do
658
- before { controller.stub(params: { f: { "field" => ["value"]} }) }
659
- it { should be_true }
658
+ before { allow(controller).to receive_messages(params: { f: { "field" => ["value"]} }) }
659
+ it { should be true }
660
660
  end
661
661
  end
662
662