blacklight 6.2.0 → 6.3.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 (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
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe Blacklight::Rendering::Pipeline do
5
+ include Capybara::RSpecMatchers
6
+ let(:document) { double }
7
+ let(:context) { double }
8
+ let(:options) { double }
9
+ let(:presenter) { described_class.new(values, field_config, document, context, options) }
10
+ describe "render" do
11
+ subject { presenter.render }
12
+ let(:values) { ['a', 'b'] }
13
+ let(:field_config) { Blacklight::Configuration::NullField.new }
14
+ it { is_expected.to eq "a and b" }
15
+
16
+ context "when separator_options are in the config" do
17
+ let(:values) { ['c', 'd'] }
18
+ let(:field_config) { Blacklight::Configuration::NullField.new(separator: nil, itemprop: nil, separator_options: { two_words_connector: '; '}) }
19
+ it { is_expected.to eq "c; d" }
20
+ end
21
+
22
+ context "when itemprop is in the config" do
23
+ let(:values) { ['a'] }
24
+ let(:field_config) { Blacklight::Configuration::NullField.new(separator: nil, itemprop: 'some-prop', separator_options: nil) }
25
+ it { is_expected.to have_selector("span[@itemprop='some-prop']", :text => "a") }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,287 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe Blacklight::ShowPresenter do
5
+ include Capybara::RSpecMatchers
6
+ let(:request_context) { double }
7
+ let(:config) { Blacklight::Configuration.new }
8
+
9
+ subject { presenter }
10
+ let(:presenter) { described_class.new(document, request_context, config) }
11
+ let(:parameter_class) { ActionController::Parameters }
12
+ let(:params) { parameter_class.new }
13
+ let(:search_state) { Blacklight::SearchState.new(params, config) }
14
+
15
+ let(:document) do
16
+ SolrDocument.new(id: 1,
17
+ 'link_to_search_true' => 'x',
18
+ 'link_to_search_named' => 'x',
19
+ 'qwer' => 'document qwer value',
20
+ 'mnbv' => 'document mnbv value')
21
+ end
22
+
23
+ before do
24
+ allow(request_context).to receive(:search_state).and_return(search_state)
25
+ end
26
+
27
+ describe "link_rel_alternates" do
28
+ before do
29
+ class MockDocument
30
+ include Blacklight::Solr::Document
31
+ end
32
+
33
+ module MockExtension
34
+ def self.extended(document)
35
+ document.will_export_as(:weird, "application/weird")
36
+ document.will_export_as(:weirder, "application/weirder")
37
+ document.will_export_as(:weird_dup, "application/weird")
38
+ end
39
+ def export_as_weird ; "weird" ; end
40
+ def export_as_weirder ; "weirder" ; end
41
+ def export_as_weird_dup ; "weird_dup" ; end
42
+ end
43
+
44
+ MockDocument.use_extension(MockExtension)
45
+
46
+ def mock_document_app_helper_url *args
47
+ solr_document_url(*args)
48
+ end
49
+
50
+ allow(request_context).to receive(:polymorphic_url) do |_, opts|
51
+ "url.#{opts[:format]}"
52
+ end
53
+ end
54
+
55
+ let(:document) { MockDocument.new(id: "MOCK_ID1") }
56
+
57
+ context "with no arguments" do
58
+ subject { presenter.link_rel_alternates }
59
+
60
+ it "generates <link rel=alternate> tags" do
61
+ tmp_value = Capybara.ignore_hidden_elements
62
+ Capybara.ignore_hidden_elements = false
63
+ document.export_formats.each_pair do |format, spec|
64
+ expect(subject).to have_selector("link[href$='.#{ format }']") do |matches|
65
+ expect(matches).to have(1).match
66
+ tag = matches[0]
67
+ expect(tag.attributes["rel"].value).to eq "alternate"
68
+ expect(tag.attributes["title"].value).to eq format.to_s
69
+ expect(tag.attributes["href"].value).to eq mock_document_app_helper_url(document, format: format)
70
+ end
71
+ end
72
+ Capybara.ignore_hidden_elements = tmp_value
73
+ end
74
+
75
+ it { is_expected.to be_html_safe }
76
+ end
77
+
78
+ context "with unique: true" do
79
+ subject { presenter.link_rel_alternates(unique: true) }
80
+
81
+ it "respects unique: true" do
82
+ tmp_value = Capybara.ignore_hidden_elements
83
+ Capybara.ignore_hidden_elements = false
84
+ expect(subject).to have_selector("link[type='application/weird']", count: 1)
85
+ Capybara.ignore_hidden_elements = tmp_value
86
+ end
87
+ end
88
+
89
+ context "with exclude" do
90
+ subject { presenter.link_rel_alternates(unique: true) }
91
+ it "excludes formats from :exclude" do
92
+ tmp_value = Capybara.ignore_hidden_elements
93
+ Capybara.ignore_hidden_elements = false
94
+ expect(subject).to_not have_selector("link[href$='.weird_dup']")
95
+ Capybara.ignore_hidden_elements = tmp_value
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "field_value" do
101
+ let(:config) do
102
+ Blacklight::Configuration.new.configure do |config|
103
+ config.add_show_field 'qwer'
104
+ config.add_show_field 'asdf', :helper_method => :render_asdf_document_show_field
105
+ config.add_show_field 'link_to_search_true', :link_to_search => true
106
+ config.add_show_field 'link_to_search_named', :link_to_search => :some_field
107
+ config.add_show_field 'highlight', :highlight => true
108
+ config.add_show_field 'solr_doc_accessor', :accessor => true
109
+ config.add_show_field 'explicit_accessor', :accessor => :solr_doc_accessor
110
+ config.add_show_field 'explicit_array_accessor', :accessor => [:solr_doc_accessor, :some_method]
111
+ config.add_show_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg
112
+ end
113
+ end
114
+
115
+ it 'html-escapes values' do
116
+ value = subject.field_value 'asdf', value: '<b>val1</b>'
117
+ expect(value).to eq '&lt;b&gt;val1&lt;/b&gt;'
118
+ end
119
+
120
+ it 'joins multivalued valued fields' do
121
+ value = subject.field_value 'asdf', value: ['<a', 'b']
122
+ expect(value).to eq '&lt;a and b'
123
+ end
124
+
125
+ it 'joins multivalued valued fields' do
126
+ value = subject.field_value 'asdf', value: ['a', 'b', 'c']
127
+ expect(value).to eq 'a, b, and c'
128
+ end
129
+
130
+ it "checks for an explicit value" do
131
+ expect(request_context).to_not receive(:render_asdf_document_show_field)
132
+ value = subject.field_value 'asdf', :value => 'val1'
133
+ expect(value).to eq 'val1'
134
+ end
135
+
136
+ it "checks for a helper method to call" do
137
+ allow(request_context).to receive(:render_asdf_document_show_field).and_return('custom asdf value')
138
+ value = subject.field_value 'asdf'
139
+ expect(value).to eq 'custom asdf value'
140
+ end
141
+
142
+ it "checks for a link_to_search" do
143
+ allow(request_context).to receive(:search_action_path).and_return('/foo')
144
+ allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
145
+ value = subject.field_value 'link_to_search_true'
146
+ expect(value).to eq 'bar'
147
+ end
148
+
149
+ it "checks for a link_to_search with a field name" do
150
+ allow(request_context).to receive(:search_action_path).and_return('/foo')
151
+ allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
152
+ value = subject.field_value 'link_to_search_named'
153
+ expect(value).to eq 'bar'
154
+ end
155
+
156
+ context "when no highlight field is available" do
157
+ before do
158
+ allow(document).to receive(:has_highlight_field?).and_return(false)
159
+ end
160
+ let(:value) { subject.field_value 'highlight' }
161
+ it "is blank" do
162
+ expect(value).to be_blank
163
+ end
164
+ end
165
+
166
+ it "checks for a highlighted field" do
167
+ allow(document).to receive(:has_highlight_field?).and_return(true)
168
+ allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
169
+ value = subject.field_value 'highlight'
170
+ expect(value).to eq '<em>highlight</em>'
171
+ end
172
+
173
+ it 'respects the HTML-safeness of multivalued highlight fields' do
174
+ allow(document).to receive(:has_highlight_field?).and_return(true)
175
+ allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe, '<em>other highlight</em>'.html_safe])
176
+ value = subject.field_value 'highlight'
177
+ expect(value).to eq '<em>highlight</em> and <em>other highlight</em>'
178
+ end
179
+
180
+ it "checks the document field value" do
181
+ value = subject.field_value 'qwer'
182
+ expect(value).to eq 'document qwer value'
183
+ end
184
+
185
+ it "works with show fields that aren't explicitly defined" do
186
+ value = subject.field_value 'mnbv'
187
+ expect(value).to eq 'document mnbv value'
188
+ end
189
+
190
+ it "calls an accessor on the solr document" do
191
+ allow(document).to receive_messages(solr_doc_accessor: "123")
192
+ value = subject.field_value 'solr_doc_accessor'
193
+ expect(value).to eq "123"
194
+ end
195
+
196
+ it "calls an explicit accessor on the solr document" do
197
+ allow(document).to receive_messages(solr_doc_accessor: "123")
198
+ value = subject.field_value 'explicit_accessor'
199
+ expect(value).to eq "123"
200
+ end
201
+
202
+ it "calls an explicit array-style accessor on the solr document" do
203
+ allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123")
204
+ value = subject.field_value 'explicit_array_accessor'
205
+ expect(value).to eq "123"
206
+ end
207
+
208
+ it "calls an accessor on the solr document with the field as an argument" do
209
+ allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123")
210
+ value = subject.field_value 'explicit_accessor_with_arg'
211
+ expect(value).to eq "123"
212
+ end
213
+ end
214
+
215
+ describe "#heading" do
216
+ it "falls back to an id" do
217
+ allow(document).to receive(:[]).with('id').and_return "xyz"
218
+ expect(subject.heading).to eq document.id
219
+ end
220
+
221
+ it "returns the value of the field" do
222
+ config.show.title_field = :x
223
+ allow(document).to receive(:has?).with(:x).and_return(true)
224
+ allow(document).to receive(:[]).with(:x).and_return("value")
225
+ expect(subject.heading).to eq "value"
226
+ end
227
+
228
+ it "returns the first present value" do
229
+ config.show.title_field = [:x, :y]
230
+ allow(document).to receive(:has?).with(:x).and_return(false)
231
+ allow(document).to receive(:has?).with(:y).and_return(true)
232
+ allow(document).to receive(:[]).with(:y).and_return("value")
233
+ expect(subject.heading).to eq "value"
234
+ end
235
+ end
236
+
237
+ describe "#html_title" do
238
+ it "falls back to an id" do
239
+ allow(document).to receive(:[]).with('id').and_return "xyz"
240
+ expect(subject.html_title).to eq document.id
241
+ end
242
+
243
+ it "returns the value of the field" do
244
+ config.show.html_title_field = :x
245
+ allow(document).to receive(:has?).with(:x).and_return(true)
246
+ allow(document).to receive(:fetch).with(:x, nil).and_return("value")
247
+ expect(subject.html_title).to eq "value"
248
+ end
249
+
250
+ it "returns the first present value" do
251
+ config.show.html_title_field = [:x, :y]
252
+ allow(document).to receive(:has?).with(:x).and_return(false)
253
+ allow(document).to receive(:has?).with(:y).and_return(true)
254
+ allow(document).to receive(:fetch).with(:y, nil).and_return("value")
255
+ expect(subject.html_title).to eq "value"
256
+ end
257
+ end
258
+
259
+ describe '#field_values' do
260
+ context 'for a field with the helper_method option' do
261
+ let(:field_name) { 'field_with_helper' }
262
+ let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
263
+
264
+ before do
265
+ document['field_with_helper'] = 'value'
266
+ end
267
+
268
+ it "checks call the helper method with arguments" do
269
+ allow(request_context).to receive(:render_field_with_helper) do |*args|
270
+ args.first
271
+ end
272
+
273
+ render_options = { a: 1 }
274
+
275
+ options = subject.send(:field_values, field_config, a: 1)
276
+
277
+ expect(options).to include :document, :field, :value, :config, :a
278
+ expect(options[:document]).to eq document
279
+ expect(options[:field]).to eq 'field_with_helper'
280
+ expect(options[:value]).to eq ['value']
281
+ expect(options[:config]).to eq field_config
282
+ expect(options[:a]).to eq 1
283
+ end
284
+ end
285
+ end
286
+ end
287
+
@@ -4,49 +4,49 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
4
  describe "Routing" do
5
5
  describe "Paths Generated by Custom Routes:" do
6
6
  # paths generated by custom routes
7
- it "should have a path for showing the email form" do
7
+ it "has a path for showing the email form" do
8
8
  expect(:get => "/catalog/email").to route_to(:controller => 'catalog', :action => 'email')
9
9
  end
10
- it "should have a path for sending the email" do
10
+ it "has a path for sending the email" do
11
11
  expect(:post => "/catalog/email").to route_to(:controller => 'catalog', :action => 'email')
12
12
  end
13
- it "should map GET {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
13
+ it "maps GET {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
14
14
  expect(:get => "/catalog/sms").to route_to(:controller => 'catalog', :action => 'sms')
15
15
  end
16
- it "should map POST {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
16
+ it "maps POST {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do
17
17
  expect(:post => "/catalog/sms").to route_to(:controller => 'catalog', :action => 'sms')
18
18
  end
19
- it "should map { :controller => 'catalog', :action => 'show', :id => 666 } to /catalog/666" do
19
+ it "maps { :controller => 'catalog', :action => 'show', :id => 666 } to /catalog/666" do
20
20
  expect(:get => "/catalog/666").to route_to(:controller => 'catalog', :action => 'show', :id => "666")
21
21
  end
22
22
  end
23
23
 
24
24
 
25
25
  describe "solr_document_path for SolrDocument", :test => true do
26
- it "should route correctly" do
26
+ it "routes correctly" do
27
27
  expect(:get => solr_document_path(SolrDocument.new(:id => 'asdf'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'asdf')
28
28
  end
29
29
 
30
30
  context "should escape solr document ids" do
31
31
 
32
- it "should pass-through url-valid ids" do
32
+ it "pass-throughs url-valid ids" do
33
33
  expect(:get => solr_document_path(SolrDocument.new(:id => 'qwerty'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'qwerty')
34
34
  end
35
35
 
36
- it "should route url-like ids" do
36
+ it "routes url-like ids" do
37
37
  skip "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
38
38
  expect(:get => solr_document_path(SolrDocument.new(:id => 'http://example.com'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'http://example.com')
39
39
  end
40
40
 
41
- it "should route ids with whitespace" do
41
+ it "routes ids with whitespace" do
42
42
  expect(:get => solr_document_path(SolrDocument.new(:id => 'mm 123'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'mm 123')
43
43
  end
44
44
 
45
- it "should route ids with a literal '+'" do
45
+ it "routes ids with a literal '+'" do
46
46
  expect(:get => solr_document_path(SolrDocument.new(:id => 'this+that'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'this+that')
47
47
  end
48
48
 
49
- it "should route ids with a literal '/" do
49
+ it "routes ids with a literal '/" do
50
50
  skip "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though"
51
51
  expect(:get => solr_document_path(SolrDocument.new(:id => 'and/or'))).to route_to(:controller => 'catalog', :action => 'show', :id => 'and/or')
52
52
  end
@@ -53,7 +53,12 @@ RSpec.configure do |config|
53
53
  # instead of true.
54
54
  config.use_transactional_fixtures = true
55
55
 
56
- config.include Devise::TestHelpers, type: :controller
56
+ if Rails.version > '5'
57
+ # This is for an unreleased version of Devise (will either be 4.2 or 5.0)
58
+ config.include Devise::Test::ControllerHelpers, type: :controller
59
+ else
60
+ config.include Devise::TestHelpers, type: :controller
61
+ end
57
62
  config.infer_spec_type_from_file_location!
58
63
 
59
64
  config.include(ControllerLevelHelpers, type: :helper)
@@ -61,4 +66,8 @@ RSpec.configure do |config|
61
66
 
62
67
  config.include(ControllerLevelHelpers, type: :view)
63
68
  config.before(:each, type: :view) { initialize_controller_helpers(view) }
69
+
70
+ unless Rails.version > '5'
71
+ config.include BackportTest, type: :controller
72
+ end
64
73
  end
@@ -0,0 +1,38 @@
1
+ # Backport the Rails 5 controller test methods to Rails 4
2
+ module BackportTest
3
+ def delete(*args)
4
+ (action, rest) = *args
5
+ rest ||= {}
6
+ if rest[:xhr]
7
+ @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
8
+ end
9
+ super(action, rest[:params])
10
+ end
11
+
12
+ def get(*args)
13
+ (action, rest) = *args
14
+ rest ||= {}
15
+ if rest[:xhr]
16
+ @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
17
+ end
18
+ super(action, rest[:params])
19
+ end
20
+
21
+ def post(*args)
22
+ (action, rest) = *args
23
+ rest ||= {}
24
+ if rest[:xhr]
25
+ @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
26
+ end
27
+ super(action, rest[:params])
28
+ end
29
+
30
+ def put(*args)
31
+ (action, rest) = *args
32
+ rest ||= {}
33
+ if rest[:xhr]
34
+ @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
35
+ end
36
+ super(action, rest[:params])
37
+ end
38
+ end
@@ -1,12 +1,4 @@
1
-
2
- if ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
3
- gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
4
- gem 'rspec-mocks', github: 'rspec/rspec-mocks' # we need 3.5.0 to be released
5
- gem 'rspec-expectations', github: 'rspec/rspec-expectations' # we need 3.5.0 to be released
6
- gem 'rspec-support', github: 'rspec/rspec-support' # we need 3.5.0 to be released
7
- gem 'rspec', github: 'rspec/rspec' # we need 3.5.0 to be released
8
- gem 'rspec-core', github: 'rspec/rspec-core' # we need 3.5.0 to be released
9
- gem 'rspec-rails', github: 'rspec/rspec-rails' # we need 3.5.0 to be released
10
- gem 'kaminari', github: 'amatsuda/kaminari' # need > 0.16.3
1
+ if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
2
+ gem 'rails-controller-testing'
11
3
  gem 'deprecation', github: 'jcoyne/deprecation', branch: 'no_alias_method_chain'
12
4
  end