blacklight 4.7.0 → 4.8.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +13 -12
  4. data/Gemfile +37 -2
  5. data/VERSION +1 -1
  6. data/app/assets/stylesheets/blacklight/{_blacklight_base.css.scss → _blacklight_base.scss} +0 -0
  7. data/app/assets/stylesheets/blacklight/{_bookmark.css.scss → _bookmark.scss} +0 -0
  8. data/app/assets/stylesheets/blacklight/{_catalog.css.scss → _catalog.scss} +0 -0
  9. data/app/assets/stylesheets/blacklight/{_dropdown.css.scss → _dropdown.scss} +0 -0
  10. data/app/assets/stylesheets/blacklight/{_facets.css.scss → _facets.scss} +0 -0
  11. data/app/assets/stylesheets/blacklight/{_footer.css.scss → _footer.scss} +0 -0
  12. data/app/assets/stylesheets/blacklight/{_group.css.scss → _group.scss} +0 -0
  13. data/app/assets/stylesheets/blacklight/{_header.css.scss → _header.scss} +0 -0
  14. data/app/assets/stylesheets/blacklight/{_layout.css.scss → _layout.scss} +0 -0
  15. data/app/assets/stylesheets/blacklight/{_mixins.css.scss → _mixins.scss} +0 -0
  16. data/app/assets/stylesheets/blacklight/{_modal.css.scss → _modal.scss} +0 -0
  17. data/app/assets/stylesheets/blacklight/{_print.css.scss → _print.scss} +0 -0
  18. data/app/assets/stylesheets/blacklight/{_responsive.css.scss → _responsive.scss} +0 -0
  19. data/app/assets/stylesheets/blacklight/{_search_history.css.scss → _search_history.scss} +0 -0
  20. data/app/assets/stylesheets/blacklight/{blacklight.css.scss → blacklight.scss} +0 -0
  21. data/app/assets/stylesheets/blacklight/{blacklight_defaults.css.scss → blacklight_defaults.scss} +0 -0
  22. data/app/assets/stylesheets/blacklight/responsive_partials/{_catalog.css.scss → _catalog.scss} +0 -0
  23. data/app/assets/stylesheets/blacklight/responsive_partials/{_facets.css.scss → _facets.scss} +0 -0
  24. data/app/assets/stylesheets/blacklight/responsive_partials/{_header.css.scss → _header.scss} +0 -0
  25. data/app/helpers/blacklight/blacklight_helper_behavior.rb +2 -2
  26. data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -1
  27. data/app/helpers/blacklight/facets_helper_behavior.rb +1 -0
  28. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +2 -2
  29. data/blacklight.gemspec +5 -6
  30. data/lib/blacklight/catalog.rb +1 -1
  31. data/lib/blacklight/catalog/search_context.rb +6 -6
  32. data/lib/blacklight/solr/document.rb +29 -21
  33. data/lib/blacklight/solr_helper.rb +6 -4
  34. data/lib/generators/blacklight/templates/{blacklight.css.scss → blacklight.scss} +0 -0
  35. data/spec/controllers/application_controller_spec.rb +3 -3
  36. data/spec/controllers/bookmarks_controller_spec.rb +11 -11
  37. data/spec/controllers/catalog_controller_spec.rb +117 -117
  38. data/spec/controllers/search_history_controller_spec.rb +8 -8
  39. data/spec/features/alternate_controller_spec.rb +7 -5
  40. data/spec/features/record_view_spec.rb +4 -1
  41. data/spec/features/search_filters_spec.rb +37 -24
  42. data/spec/features/search_pagination_spec.rb +11 -7
  43. data/spec/features/search_results_spec.rb +22 -14
  44. data/spec/features/search_sort_spec.rb +3 -1
  45. data/spec/features/search_spec.rb +6 -0
  46. data/spec/helpers/blacklight_helper_spec.rb +175 -166
  47. data/spec/helpers/catalog_helper_spec.rb +59 -59
  48. data/spec/helpers/facets_helper_spec.rb +118 -118
  49. data/spec/helpers/hash_as_hidden_fields_spec.rb +14 -8
  50. data/spec/helpers/html_head_helper_spec.rb +51 -45
  51. data/spec/helpers/render_constraints_helper_spec.rb +5 -6
  52. data/spec/helpers/search_history_constraints_helper_spec.rb +21 -21
  53. data/spec/lib/blacklight/solr_response/group_response_spec.rb +2 -2
  54. data/spec/lib/blacklight_configurable_spec.rb +16 -16
  55. data/spec/lib/blacklight_configuration_spec.rb +132 -132
  56. data/spec/lib/blacklight_email_spec.rb +4 -4
  57. data/spec/lib/blacklight_sms_spec.rb +4 -4
  58. data/spec/lib/blacklight_solr_document_dublin_core_spec.rb +6 -6
  59. data/spec/lib/blacklight_solr_document_marc_spec.rb +3 -3
  60. data/spec/lib/blacklight_solr_document_more_like_this_spec.rb +4 -4
  61. data/spec/lib/blacklight_solr_document_spec.rb +36 -36
  62. data/spec/lib/blacklight_solr_response_spec.rb +42 -42
  63. data/spec/lib/blacklight_spec.rb +5 -5
  64. data/spec/lib/blacklight_user_spec.rb +5 -5
  65. data/spec/lib/facet_paginator_spec.rb +12 -12
  66. data/spec/lib/marc_export_spec.rb +746 -746
  67. data/spec/lib/search_fields_spec.rb +13 -13
  68. data/spec/lib/solr_helper_spec.rb +255 -250
  69. data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
  70. data/spec/lib/tasks/solr_marc_task_spec.rb +6 -6
  71. data/spec/lib/utils_spec.rb +11 -11
  72. data/spec/models/bookmark_spec.rb +7 -6
  73. data/spec/models/record_mailer_spec.rb +16 -16
  74. data/spec/models/search_spec.rb +8 -8
  75. data/spec/models/solr_document_spec.rb +7 -7
  76. data/spec/requests/alternate_controller_spec.rb +3 -3
  77. data/spec/routing/catalog_routing_spec.rb +10 -15
  78. data/spec/spec_helper.rb +6 -4
  79. data/spec/support/assert_difference.rb +2 -2
  80. data/spec/support/features.rb +11 -0
  81. data/spec/support/features/session_helpers.rb +3 -3
  82. data/spec/support/include_text.rb +2 -2
  83. data/spec/test_app_templates/Gemfile.extra +2 -15
  84. data/spec/test_app_templates/lib/generators/test_app_generator.rb +17 -6
  85. data/spec/views/catalog/_constraints.html.erb_spec.rb +7 -7
  86. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +12 -12
  87. data/spec/views/catalog/_document.html.erb_spec.rb +1 -1
  88. data/spec/views/catalog/_facets.html.erb_spec.rb +13 -13
  89. data/spec/views/catalog/_index_default.erb_spec.rb +20 -20
  90. data/spec/views/catalog/_show_default.erb_spec.rb +20 -20
  91. data/spec/views/catalog/_show_sidebar.erb_spec.rb +6 -6
  92. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -3
  93. data/spec/views/catalog/index.atom.builder_spec.rb +28 -28
  94. data/spec/views/catalog/index.html.erb_spec.rb +6 -6
  95. metadata +35 -57
  96. data/gemfiles/rails3.gemfile +0 -25
  97. data/gemfiles/rails4.gemfile +0 -24
@@ -8,34 +8,34 @@ describe BookmarksController do
8
8
  describe "update" do
9
9
  it "has a 204 status code when creating a new one" do
10
10
  xhr :put, :update, :id => '2007020969', :format => :js
11
- response.should be_success
12
- response.code.should == "204"
11
+ expect(response).to be_success
12
+ expect(response.code).to eq("204")
13
13
  end
14
14
 
15
15
  it "has a 500 status code when fails is success" do
16
- @controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
17
- @controller.stub_chain(:current_or_guest_user, :persisted?).and_return(true)
18
- @controller.stub_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
16
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
17
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :persisted?).and_return(true)
18
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)
19
19
  xhr :put, :update, :id => 'iamabooboo', :format => :js
20
- response.code.should == "500"
20
+ expect(response.code).to eq("500")
21
21
  end
22
22
  end
23
23
 
24
24
  describe "delete" do
25
25
  it "has a 204 status code when delete is success" do
26
26
  xhr :delete, :destroy, :id => '2007020969', :format => :js
27
- response.should be_success
28
- response.code.should == "204"
27
+ expect(response).to be_success
28
+ expect(response.code).to eq("204")
29
29
  end
30
30
 
31
31
  it "has a 500 status code when delete is not success" do
32
32
  bm = double(Bookmark)
33
- @controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
34
- @controller.stub_chain(:current_or_guest_user, :bookmarks, :delete).and_return(false)
33
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
34
+ allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :delete).and_return(false)
35
35
 
36
36
  xhr :delete, :destroy, :id => 'pleasekillme', :format => :js
37
37
  #
38
- response.code.should == "500"
38
+ expect(response.code).to eq("500")
39
39
  end
40
40
  end
41
41
 
@@ -23,68 +23,68 @@ describe CatalogController do
23
23
 
24
24
  describe "with format :html" do
25
25
  it "should have no search history if no search criteria" do
26
- controller.should_receive(:get_search_results)
26
+ expect(controller).to receive(:get_search_results)
27
27
  session[:history] = []
28
28
  get :index
29
- session[:history].length.should == 0
29
+ expect(session[:history].length).to eq(0)
30
30
  end
31
31
 
32
32
  # check each user manipulated parameter
33
33
  it "should have docs and facets for query with results", :integration => true do
34
34
  get :index, :q => @user_query
35
- assigns_response.docs.size.should > 1
35
+ expect(assigns_response.docs.size).to be > 1
36
36
  assert_facets_have_values(assigns_response.facets)
37
37
  end
38
38
  it "should have docs and facets for existing facet value", :integration => true do
39
39
  get :index, :f => @facet_query
40
- assigns_response.docs.size.should > 1
40
+ expect(assigns_response.docs.size).to be > 1
41
41
  assert_facets_have_values(assigns_response.facets)
42
42
  end
43
43
  it "should have docs and facets for non-default results per page", :integration => true do
44
44
  num_per_page = 7
45
45
  get :index, :per_page => num_per_page
46
- assigns_response.docs.size.should == num_per_page
46
+ expect(assigns_response.docs.size).to eq(num_per_page)
47
47
  assert_facets_have_values(assigns_response.facets)
48
48
  end
49
49
 
50
50
  it "should have docs and facets for second page", :integration => true do
51
51
  page = 2
52
52
  get :index, :page => page
53
- assigns_response.docs.size.should > 1
54
- assigns_response.params[:start].to_i.should == (page-1) * @controller.blacklight_config[:default_solr_params][:rows]
53
+ expect(assigns_response.docs.size).to be > 1
54
+ expect(assigns_response.params[:start].to_i).to eq((page-1) * @controller.blacklight_config[:default_solr_params][:rows])
55
55
  assert_facets_have_values(assigns_response.facets)
56
56
  end
57
57
 
58
58
  it "should have no docs or facet values for query without results", :integration => true do
59
59
  get :index, :q => @no_docs_query
60
60
 
61
- assigns_response.docs.size.should == 0
61
+ expect(assigns_response.docs.size).to eq(0)
62
62
  assigns_response.facets.each do |facet|
63
- facet.items.size.should == 0
63
+ expect(facet.items.size).to eq(0)
64
64
  end
65
65
  end
66
66
 
67
67
  it "should have a spelling suggestion for an appropriately poor query", :integration => true do
68
68
  get :index, :q => 'boo'
69
- assigns_response.spelling.words.should_not be_nil
69
+ expect(assigns_response.spelling.words).not_to be_nil
70
70
  end
71
71
 
72
72
  describe "session" do
73
73
  before do
74
- controller.stub(:get_search_results)
74
+ allow(controller).to receive(:get_search_results)
75
75
  end
76
76
  it "should include :search key with hash" do
77
77
  get :index
78
- session[:search].should_not be_nil
79
- session[:search].should be_kind_of(Hash)
78
+ expect(session[:search]).not_to be_nil
79
+ expect(session[:search]).to be_kind_of(Hash)
80
80
  end
81
81
  it "should include search hash with key :q" do
82
82
  get :index, :q => @user_query
83
- session[:search].should_not be_nil
84
- session[:search].keys.should include(:id)
83
+ expect(session[:search]).not_to be_nil
84
+ expect(session[:search].keys).to include('id')
85
85
 
86
- search = Search.find(session[:search][:id])
87
- expect(search.query_params[:q]).to eq @user_query
86
+ search = Search.find(session[:search]['id'])
87
+ expect(search.query_params['q']).to eq @user_query
88
88
  end
89
89
  end
90
90
 
@@ -92,7 +92,7 @@ describe CatalogController do
92
92
  describe "for default query" do
93
93
  it "should get documents when no query", :integration => true do
94
94
  get :index
95
- assigns_response.docs.size.should > 1
95
+ expect(assigns_response.docs.size).to be > 1
96
96
  end
97
97
  it "should get facets when no query", :integration => true do
98
98
  get :index
@@ -101,29 +101,29 @@ describe CatalogController do
101
101
  end
102
102
 
103
103
  it "should render index.html.erb" do
104
- controller.stub(:get_search_results)
104
+ allow(controller).to receive(:get_search_results)
105
105
  get :index
106
- response.should render_template(:index)
106
+ expect(response).to render_template(:index)
107
107
  end
108
108
 
109
109
  # NOTE: status code is always 200 in isolation mode ...
110
110
  it "HTTP status code for GET should be 200", :integration => true do
111
111
  get :index
112
- response.should be_success
112
+ expect(response).to be_success
113
113
  end
114
114
  end
115
115
 
116
116
  describe "with format :rss" do
117
117
  it "should get the feed", :integration => true do
118
118
  get :index, :format => 'rss'
119
- response.should be_success
119
+ expect(response).to be_success
120
120
  end
121
121
  end
122
122
 
123
123
  describe "with format :json" do
124
124
  before do
125
125
  get :index, :format => 'json'
126
- response.should be_success
126
+ expect(response).to be_success
127
127
  end
128
128
  let(:json) { JSON.parse(response.body)['response'] }
129
129
  let(:pages) { json["pages"] }
@@ -131,29 +131,29 @@ describe CatalogController do
131
131
  let(:facets) { json["facets"] }
132
132
 
133
133
  it "should get the pages" do
134
- pages["total_count"].should == 30
135
- pages["current_page"].should == 1
136
- pages["total_pages"].should == 3
134
+ expect(pages["total_count"]).to eq(30)
135
+ expect(pages["current_page"]).to eq(1)
136
+ expect(pages["total_pages"]).to eq(3)
137
137
  end
138
138
 
139
139
  it "should get the documents" do
140
- docs.size.should == 10
140
+ expect(docs.size).to eq(10)
141
141
  expect(docs.first.keys).to match_array(["published_display", "author_display", "lc_callnum_display", "pub_date", "subtitle_display", "format", "material_type_display", "title_display", "id", "subject_topic_facet", "language_facet", "score"])
142
142
  end
143
143
 
144
144
  it "should get the facets" do
145
- facets.length.should == 9
146
- facets.first.should == {"name"=>"format", "label" => "Format", "items"=>[{"value"=>"Book", "hits"=>30, "label"=>"Book"}]}
145
+ expect(facets.length).to eq(9)
146
+ expect(facets.first).to eq({"name"=>"format", "label" => "Format", "items"=>[{"value"=>"Book", "hits"=>30, "label"=>"Book"}]})
147
147
  end
148
148
 
149
149
  describe "facets" do
150
150
  let(:query_facet_items) { facets.last['items'] }
151
151
  let(:regular_facet_items) { facets.first['items'] }
152
152
  it "should have items with labels and values" do
153
- query_facet_items.first['label'].should == 'within 10 Years'
154
- query_facet_items.first['value'].should == 'years_10'
155
- regular_facet_items.first['label'].should == "Book"
156
- regular_facet_items.first['value'].should == "Book"
153
+ expect(query_facet_items.first['label']).to eq('within 10 Years')
154
+ expect(query_facet_items.first['value']).to eq('years_10')
155
+ expect(regular_facet_items.first['label']).to eq("Book")
156
+ expect(regular_facet_items.first['value']).to eq("Book")
157
157
  end
158
158
  end
159
159
  end
@@ -165,7 +165,7 @@ describe CatalogController do
165
165
 
166
166
  it "should set counter value into session[:search]" do
167
167
  put :update, :id => doc_id, :counter => 3
168
- session[:search][:counter].should == "3"
168
+ expect(session[:search]['counter']).to eq("3")
169
169
  end
170
170
 
171
171
  it "should redirect to show action for doc id" do
@@ -182,14 +182,14 @@ describe CatalogController do
182
182
  describe "with format :html" do
183
183
  it "should get document", :integration => true do
184
184
  get :show, :id => doc_id
185
- assigns[:document].should_not be_nil
185
+ expect(assigns[:document]).not_to be_nil
186
186
  end
187
187
  end
188
188
 
189
189
  describe "with format :json" do
190
190
  it "should get the feed" do
191
191
  get :show, id: doc_id, format: 'json'
192
- response.should be_success
192
+ expect(response).to be_success
193
193
  json = JSON.parse response.body
194
194
  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"])
195
195
  end
@@ -199,59 +199,59 @@ describe CatalogController do
199
199
  before do
200
200
  @mock_response = double()
201
201
  @mock_document = double()
202
- @mock_document.stub(:export_formats => {})
203
- controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
202
+ allow(@mock_document).to receive_messages(:export_formats => {})
203
+ allow(controller).to receive_messages(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
204
204
  :get_previous_and_next_documents_for_search => [double(:total => 5), [double("a"), @mock_document, double("b")]])
205
205
 
206
206
  current_search = Search.create(:query_params => { :q => ""})
207
- controller.stub(:current_search_session => current_search)
207
+ allow(controller).to receive_messages(:current_search_session => current_search)
208
208
 
209
209
  @search_session = { :id => current_search.id }
210
210
  end
211
211
  it "should set previous document if counter present in session" do
212
- session[:search] = @search_session.merge(:counter => 2)
212
+ session[:search] = @search_session.merge('counter' => 2)
213
213
  get :show, :id => doc_id
214
- assigns[:previous_document].should_not be_nil
214
+ expect(assigns[:previous_document]).not_to be_nil
215
215
  end
216
216
  it "should not set previous or next document if session is blank" do
217
217
  get :show, :id => doc_id
218
- assigns[:previous_document].should be_nil
219
- assigns[:next_document].should be_nil
218
+ expect(assigns[:previous_document]).to be_nil
219
+ expect(assigns[:next_document]).to be_nil
220
220
  end
221
- it "should not set previous or next document if session[:search][:counter] is nil" do
221
+ it "should not set previous or next document if session[:search]['counter'] is nil" do
222
222
  session[:search] = {}
223
223
  get :show, :id => doc_id
224
- assigns[:previous_document].should be_nil
225
- assigns[:next_document].should be_nil
224
+ expect(assigns[:previous_document]).to be_nil
225
+ expect(assigns[:next_document]).to be_nil
226
226
  end
227
227
  it "should set next document if counter present in session" do
228
- session[:search] = @search_session.merge(:counter => 2)
228
+ session[:search] = @search_session.merge('counter' => 2)
229
229
  get :show, :id => doc_id
230
- assigns[:next_document].should_not be_nil
230
+ expect(assigns[:next_document]).not_to be_nil
231
231
  end
232
232
  end
233
233
 
234
234
  # NOTE: status code is always 200 in isolation mode ...
235
235
  it "HTTP status code for GET should be 200", :integration => true do
236
236
  get :show, :id => doc_id
237
- response.should be_success
237
+ expect(response).to be_success
238
238
  end
239
239
  it "should render show.html.erb" do
240
240
  @mock_response = double()
241
241
  @mock_document = double()
242
- @mock_document.stub(:export_formats => {})
243
- controller.stub(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
242
+ allow(@mock_document).to receive_messages(:export_formats => {})
243
+ allow(controller).to receive_messages(:get_solr_response_for_doc_id => [@mock_response, @mock_document],
244
244
  :get_single_doc_via_search => @mock_document)
245
245
  get :show, :id => doc_id
246
- response.should render_template(:show)
246
+ expect(response).to render_template(:show)
247
247
  end
248
248
 
249
249
  describe "@document" do
250
250
  before do
251
251
  @mock_response = double()
252
- @mock_response.stub(:docs => [{ :id => 'my_fake_doc' }])
252
+ allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }])
253
253
  @mock_document = double()
254
- controller.stub(:find => @mock_response,
254
+ allow(controller).to receive_messages(:find => @mock_response,
255
255
  :get_single_doc_via_search => @mock_document)
256
256
  end
257
257
  before(:each) do
@@ -259,7 +259,7 @@ describe CatalogController do
259
259
  @document = assigns[:document]
260
260
  end
261
261
  it "should be a SolrDocument" do
262
- @document.should be_instance_of(SolrDocument)
262
+ expect(@document).to be_instance_of(SolrDocument)
263
263
  end
264
264
  end
265
265
 
@@ -276,12 +276,12 @@ describe CatalogController do
276
276
  end
277
277
  before do
278
278
  @mock_response = double()
279
- @mock_response.stub(:docs => [{ :id => 'my_fake_doc' }])
279
+ allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }])
280
280
  @mock_document = double()
281
- controller.stub(:find => @mock_response,
281
+ allow(controller).to receive_messages(:find => @mock_response,
282
282
  :get_single_doc_via_search => @mock_document)
283
283
 
284
- controller.stub(:find => @mock_response,
284
+ allow(controller).to receive_messages(:find => @mock_response,
285
285
  :get_single_doc_via_search => @mock_document)
286
286
  end
287
287
 
@@ -299,8 +299,8 @@ describe CatalogController do
299
299
 
300
300
  it "should respond to an extension-registered format properly" do
301
301
  get :show, :id => doc_id, :format => "mock" # This no longer works: :format => "mock"
302
- response.should be_success
303
- response.body.should =~ /mock_export/
302
+ expect(response).to be_success
303
+ expect(response.body).to match(/mock_export/)
304
304
  end
305
305
 
306
306
 
@@ -316,18 +316,18 @@ describe CatalogController do
316
316
  before do
317
317
  @mock_response = double()
318
318
  @mock_document = double()
319
- @mock_response.stub(:docs => [{ :id => 'my_fake_doc' }, { :id => 'my_other_doc'}])
319
+ allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }, { :id => 'my_other_doc'}])
320
320
  @mock_document = double()
321
- controller.stub(:find => @mock_response,
321
+ allow(controller).to receive_messages(:find => @mock_response,
322
322
  :get_single_doc_via_search => @mock_document)
323
323
  end
324
324
  it "should return an opensearch description" do
325
325
  get :opensearch, :format => 'xml'
326
- response.should be_success
326
+ expect(response).to be_success
327
327
  end
328
328
  it "should return valid JSON" do
329
329
  get :opensearch,:format => 'json', :q => "a"
330
- response.should be_success
330
+ expect(response).to be_success
331
331
  end
332
332
  end
333
333
  #=end
@@ -336,9 +336,9 @@ describe CatalogController do
336
336
  before do
337
337
  @mock_response = double()
338
338
  @mock_document = double()
339
- @mock_response.stub(:docs => [{ :id => 'my_fake_doc' }, { :id => 'my_other_doc'}])
339
+ allow(@mock_response).to receive_messages(:docs => [{ :id => 'my_fake_doc' }, { :id => 'my_other_doc'}])
340
340
  @mock_document = double()
341
- controller.stub(:find => @mock_response,
341
+ allow(controller).to receive_messages(:find => @mock_response,
342
342
  :get_single_doc_via_search => @mock_document)
343
343
  end
344
344
  before(:each) do
@@ -349,24 +349,24 @@ describe CatalogController do
349
349
  describe "email" do
350
350
  it "should give error if no TO paramater" do
351
351
  post :email, :id => doc_id
352
- request.flash[:error].should == "You must enter a recipient in order to send this message"
352
+ expect(request.flash[:error]).to eq("You must enter a recipient in order to send this message")
353
353
  end
354
354
  it "should give an error if the email address is not valid" do
355
355
  post :email, :id => doc_id, :to => 'test_bad_email'
356
- request.flash[:error].should == "You must enter a valid email address"
356
+ expect(request.flash[:error]).to eq("You must enter a valid email address")
357
357
  end
358
358
  it "should not give error if no Message paramater is set" do
359
359
  post :email, :id => doc_id, :to => 'test_email@projectblacklight.org'
360
- request.flash[:error].should be_nil
360
+ expect(request.flash[:error]).to be_nil
361
361
  end
362
362
  it "should redirect back to the record upon success" do
363
363
  mock_mailer = double
364
- mock_mailer.should_receive(:deliver)
365
- RecordMailer.should_receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer
364
+ expect(mock_mailer).to receive(:deliver)
365
+ expect(RecordMailer).to receive(:email_record).with(anything, { :to => 'test_email@projectblacklight.org', :message => 'xyz' }, hash_including(:host => 'test.host')).and_return mock_mailer
366
366
 
367
367
  post :email, :id => doc_id, :to => 'test_email@projectblacklight.org', :message => 'xyz'
368
- request.flash[:error].should be_nil
369
- request.should redirect_to(catalog_path(doc_id))
368
+ expect(request.flash[:error]).to be_nil
369
+ expect(request).to redirect_to(catalog_path(doc_id))
370
370
  end
371
371
 
372
372
  it "should render email_sent for XHR requests" do
@@ -378,29 +378,29 @@ describe CatalogController do
378
378
  describe "sms" do
379
379
  it "should give error if no phone number is given" do
380
380
  post :sms, :id => doc_id, :carrier => 'att'
381
- request.flash[:error].should == "You must enter a recipient's phone number in order to send this message"
381
+ expect(request.flash[:error]).to eq("You must enter a recipient's phone number in order to send this message")
382
382
  end
383
383
  it "should give an error when a carrier is not provided" do
384
384
  post :sms, :id => doc_id, :to => '5555555555', :carrier => ''
385
- request.flash[:error].should == "You must select a carrier"
385
+ expect(request.flash[:error]).to eq("You must select a carrier")
386
386
  end
387
387
  it "should give an error when the phone number is not 10 digits" do
388
388
  post :sms, :id => doc_id, :to => '555555555', :carrier => 'txt.att.net'
389
- request.flash[:error].should == "You must enter a valid 10 digit phone number"
389
+ expect(request.flash[:error]).to eq("You must enter a valid 10 digit phone number")
390
390
  end
391
391
  it "should give an error when the carrier is not in our list of carriers" do
392
392
  post :sms, :id => doc_id, :to => '5555555555', :carrier => 'no-such-carrier'
393
- request.flash[:error].should == "You must enter a valid carrier"
393
+ expect(request.flash[:error]).to eq("You must enter a valid carrier")
394
394
  end
395
395
  it "should allow punctuation in phone number" do
396
396
  post :sms, :id => doc_id, :to => '(555) 555-5555', :carrier => 'txt.att.net'
397
- request.flash[:error].should be_nil
398
- request.should redirect_to(catalog_path(doc_id))
397
+ expect(request.flash[:error]).to be_nil
398
+ expect(request).to redirect_to(catalog_path(doc_id))
399
399
  end
400
400
  it "should redirect back to the record upon success" do
401
401
  post :sms, :id => doc_id, :to => '5555555555', :carrier => 'txt.att.net'
402
- request.flash[:error].should be_nil
403
- request.should redirect_to(catalog_path(doc_id))
402
+ expect(request.flash[:error]).to be_nil
403
+ expect(request).to redirect_to(catalog_path(doc_id))
404
404
  end
405
405
 
406
406
  it "should render sms_sent template for XHR requests" do
@@ -414,36 +414,36 @@ describe CatalogController do
414
414
  describe "errors" do
415
415
  it "should return status 404 for a record that doesn't exist" do
416
416
  @mock_response = double()
417
- @mock_response.stub(:docs => [])
417
+ allow(@mock_response).to receive_messages(:docs => [])
418
418
  @mock_document = double()
419
- controller.stub(:find => @mock_response,
419
+ allow(controller).to receive_messages(:find => @mock_response,
420
420
  :get_single_doc_via_search => @mock_document)
421
421
  get :show, :id=>"987654321"
422
- request.flash[:notice].should == "Sorry, you have requested a record that doesn't exist."
423
- response.should render_template('index')
424
- response.status.should == 404
422
+ expect(request.flash[:notice]).to eq("Sorry, you have requested a record that doesn't exist.")
423
+ expect(response).to render_template('index')
424
+ expect(response.status).to eq(404)
425
425
  end
426
426
  it "should redirect the user to the root url for a bad search" do
427
427
  req = {}
428
428
  res = {}
429
429
  fake_error = RSolr::Error::Http.new(req, res)
430
- controller.stub(:get_search_results) { |*args| raise fake_error }
431
- controller.logger.should_receive(:error).with(fake_error)
430
+ allow(controller).to receive(:get_search_results) { |*args| raise fake_error }
431
+ expect(controller.logger).to receive(:error).with(fake_error)
432
432
  get :index, :q=>"+"
433
433
 
434
- response.redirect_url.should == root_url
435
- request.flash[:notice].should == "Sorry, I don't understand your search."
436
- response.should_not be_success
437
- response.status.should == 302
434
+ expect(response.redirect_url).to eq(root_url)
435
+ expect(request.flash[:notice]).to eq("Sorry, I don't understand your search.")
436
+ expect(response).not_to be_success
437
+ expect(response.status).to eq(302)
438
438
  end
439
439
  it "should return status 500 if the catalog path is raising an exception" do
440
440
 
441
441
  req = {}
442
442
  res = {}
443
443
  fake_error = RSolr::Error::Http.new(req, res)
444
- controller.stub(:get_search_results) { |*args| raise fake_error }
445
- controller.flash.stub(:sweep)
446
- controller.stub(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
444
+ allow(controller).to receive(:get_search_results) { |*args| raise fake_error }
445
+ allow(controller.flash).to receive(:sweep)
446
+ allow(controller).to receive(:flash).and_return(:notice => I18n.t('blacklight.search.errors.request_error'))
447
447
  expect {
448
448
  get :index, :q=>"+"
449
449
  }.to raise_error
@@ -455,18 +455,18 @@ describe CatalogController do
455
455
  render_views
456
456
 
457
457
  before do
458
- controller.stub(:has_user_authentication_provider?) { false }
458
+ allow(controller).to receive(:has_user_authentication_provider?) { false }
459
459
  @mock_response = double()
460
460
  @mock_document = double()
461
- @mock_response.stub(:docs => [], :total => 1, :facets => [], :facet_queries => {}, :facet_by_field_name => nil)
461
+ allow(@mock_response).to receive_messages(:docs => [], :total => 1, :facets => [], :facet_queries => {}, :facet_by_field_name => nil)
462
462
  @mock_document = double()
463
- controller.stub(:find => @mock_response,
463
+ allow(controller).to receive_messages(:find => @mock_response,
464
464
  :get_single_doc_via_search => @mock_document)
465
465
  end
466
466
 
467
467
  it "should not show user util links" do
468
468
  get :index
469
- response.body.should_not =~ /Login/
469
+ expect(response.body).not_to match(/Login/)
470
470
  end
471
471
  end
472
472
 
@@ -474,22 +474,22 @@ describe CatalogController do
474
474
  describe "requesting js" do
475
475
  it "should be successful" do
476
476
  xhr :get, :facet, id: 'format'
477
- response.should be_successful
477
+ expect(response).to be_successful
478
478
  end
479
479
  end
480
480
  describe "requesting html" do
481
481
  it "should be successful" do
482
482
  get :facet, id: 'format'
483
- response.should be_successful
484
- assigns[:pagination].should be_kind_of Blacklight::Solr::FacetPaginator
483
+ expect(response).to be_successful
484
+ expect(assigns[:pagination]).to be_kind_of Blacklight::Solr::FacetPaginator
485
485
  end
486
486
  end
487
487
  describe "requesting json" do
488
488
  it "should be successful" do
489
489
  get :facet, id: 'format', format: 'json'
490
- response.should be_successful
490
+ expect(response).to be_successful
491
491
  json = JSON.parse(response.body)
492
- json["response"]["facets"]["items"].first["value"].should == 'Book'
492
+ expect(json["response"]["facets"]["items"].first["value"]).to eq('Book')
493
493
  end
494
494
  end
495
495
  end
@@ -497,8 +497,8 @@ describe CatalogController do
497
497
  describe 'render_search_results_as_json' do
498
498
  before do
499
499
  controller.instance_variable_set :@document_list, [{id: '123', title_t: 'Book1'}, {id: '456', title_t: 'Book2'}]
500
- controller.stub(:pagination_info).and_return({current_page: 1, next_page: 2, prev_page: nil})
501
- controller.stub(:search_facets_as_json).and_return(
500
+ allow(controller).to receive(:pagination_info).and_return({current_page: 1, next_page: 2, prev_page: nil})
501
+ allow(controller).to receive(:search_facets_as_json).and_return(
502
502
  [{name: "format", label: "Format", items: [{value: 'Book', hits: 30, label: 'Book'}]}])
503
503
  end
504
504
 
@@ -527,18 +527,18 @@ describe CatalogController do
527
527
  it "should prepend the current search to the list" do
528
528
  session[:history] = []
529
529
  controller.send(:add_to_search_history, double(:id => 1))
530
- expect(session[:history]).to have(1).item
530
+ expect(session[:history].size).to eq(1)
531
531
 
532
532
  controller.send(:add_to_search_history, double(:id => 2))
533
- expect(session[:history]).to have(2).items
533
+ expect(session[:history].size).to eq(2)
534
534
  expect(session[:history].first).to eq 2
535
535
  end
536
536
 
537
537
  it "should remove searches from the list when the list gets too big" do
538
- controller.stub(:blacklight_config).and_return(double(:search_history_window => 5))
538
+ allow(controller).to receive(:blacklight_config).and_return(double(:search_history_window => 5))
539
539
  session[:history] = (0..4).to_a.reverse
540
540
 
541
- expect(session[:history]).to have(5).items
541
+ expect(session[:history].size).to eq(5)
542
542
  controller.send(:add_to_search_history, double(:id => 5))
543
543
  controller.send(:add_to_search_history, double(:id => 6))
544
544
  controller.send(:add_to_search_history, double(:id => 7))
@@ -549,15 +549,15 @@ describe CatalogController do
549
549
 
550
550
  describe "current_search_session" do
551
551
  it "should create a session if we're on an search action" do
552
- controller.stub(:action_name => "index")
553
- controller.stub(:params => { :q => "x", :page => 5})
552
+ allow(controller).to receive_messages(:action_name => "index")
553
+ allow(controller).to receive_messages(:params => { :q => "x", :page => 5})
554
554
  session = controller.send(:current_search_session)
555
555
  expect(session.query_params).to include(:q => "x")
556
556
  expect(session.query_params).to_not include(:page => 5)
557
557
  end
558
558
 
559
559
  it "should create a session if a search context was provided" do
560
- controller.stub(:params => { :search_context => JSON.dump(:q => "x")})
560
+ allow(controller).to receive_messages(:params => { :search_context => JSON.dump(:q => "x")})
561
561
  session = controller.send(:current_search_session)
562
562
  expect(session.query_params).to include("q" => "x")
563
563
  end
@@ -566,7 +566,7 @@ describe CatalogController do
566
566
  s = Search.create(:query_params => { :q => "x" })
567
567
  session[:history] ||= []
568
568
  session[:history] << s.id
569
- controller.stub(:params => { :search_id => s.id})
569
+ allow(controller).to receive_messages(:params => { :search_id => s.id})
570
570
  session = controller.send(:current_search_session)
571
571
  expect(session.query_params).to include(:q => "x")
572
572
  expect(session).to eq(s)
@@ -575,7 +575,7 @@ describe CatalogController do
575
575
  it "should use an existing search session if the search is in the uri" do
576
576
  s = Search.create(:query_params => { :q => "x" })
577
577
  session[:search] ||= {}
578
- session[:search][:id] = s.id
578
+ session[:search]['id'] = s.id
579
579
  session[:history] ||= []
580
580
  session[:history] << s.id
581
581
  session = controller.send(:current_search_session)
@@ -588,10 +588,10 @@ end
588
588
 
589
589
  # there must be at least one facet, and each facet must have at least one value
590
590
  def assert_facets_have_values(facets)
591
- facets.size.should > 1
591
+ expect(facets.size).to be > 1
592
592
  # should have at least one value for each facet
593
593
  facets.each do |facet|
594
- facet.items.size.should >= 1
594
+ expect(facet.items.size).to be >= 1
595
595
  end
596
596
  end
597
597