blacklight 6.3.0 → 6.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38e64adb886cc4afffadc21d807dd85b7f919bef
4
- data.tar.gz: 6d422b5862b493b3f5b4db3d163c3dbed749bae3
3
+ metadata.gz: e5f399d49a4b81d638fd3a6b7dd2a79595895ef6
4
+ data.tar.gz: 3ab2a5bfb36436d5c2febb62c6fa24f1b3026830
5
5
  SHA512:
6
- metadata.gz: 0b9ff4de640f01ff5ee90d2a10b6b8d2d36b7c746890ab7f19403c85a6cc92a1afe058d5ea79a616aaefe4c8f4f777210c5452e112b26c066e2743cfb99f154c
7
- data.tar.gz: 6ff37f57181bd54aa43531ef7beae404c787b2c94bab6a2fbe3d0652420ab3f3c1f03b1efb3e7a934ae09ba1c82c7bb381b87d992796742e899b81fc203cccb1
6
+ metadata.gz: e83719b79cde64ee06a25074789458719b414c34c9eee9b4ae693c8b1a0bbdfe321acd0002421331aec2725c8d1fd957175dc1dda11873d1d79f79096fbccff6
7
+ data.tar.gz: d90c449b77e6a30c0aee64967f6cb9b4048e131d1ff2e94b4238ad133505994606ce00da1ea90d5cc1359e39797d49d318d304550ebf9e4890fe15aad25e422b
data/Gemfile CHANGED
@@ -35,7 +35,7 @@ else
35
35
  end
36
36
 
37
37
  if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
38
- gem 'rspec-rails', '>= 3.5.0.beta4', '~> 3.5'
38
+ # noop
39
39
  elsif ENV['RAILS_VERSION'] =~ /^4\.2/
40
40
  gem 'responders', "~> 2.0"
41
41
  gem 'sass-rails', ">= 5.0"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.3.0
1
+ 6.3.1
@@ -13,7 +13,7 @@ Blacklight = function() {
13
13
 
14
14
  listeners: function () {
15
15
  var listeners = [];
16
- if (Turbolinks && Turbolinks.supported) {
16
+ if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
17
17
  // Turbolinks 5
18
18
  if (Turbolinks.BrowserAdapter) {
19
19
  listeners.push('turbolinks:load');
@@ -12,7 +12,7 @@ module Blacklight::SearchContext
12
12
  module ClassMethods
13
13
  # Save the submitted search parameters in the search session
14
14
  def record_search_parameters opts = { only: :index}
15
- before_action :current_search_session, opts
15
+ before_action :set_current_search_session, opts
16
16
  end
17
17
  end
18
18
 
@@ -28,10 +28,16 @@ module Blacklight::SearchContext
28
28
 
29
29
  # The current search session
30
30
  def current_search_session
31
+ @current_search_session ||= find_search_session
32
+ end
31
33
 
32
- @current_search_session ||= if start_new_search_session?
33
- find_or_initialize_search_session_from_params search_state.to_h
34
- elsif params[:search_context].present?
34
+ # Persist the current search session id to the user's session
35
+ def set_current_search_session
36
+ search_session['id'] = current_search_session.id if current_search_session
37
+ end
38
+
39
+ def find_search_session
40
+ if params[:search_context].present?
35
41
  find_or_initialize_search_session_from_params JSON.load(params[:search_context])
36
42
  elsif params[:search_id].present?
37
43
  begin
@@ -40,6 +46,8 @@ module Blacklight::SearchContext
40
46
  rescue ActiveRecord::RecordNotFound
41
47
  nil
42
48
  end
49
+ elsif start_new_search_session?
50
+ find_or_initialize_search_session_from_params search_state.to_h
43
51
  elsif search_session['id']
44
52
  begin
45
53
  searches_from_history.find(search_session['id'])
@@ -47,10 +55,6 @@ module Blacklight::SearchContext
47
55
  nil
48
56
  end
49
57
  end
50
-
51
- search_session['id'] = @current_search_session.id if @current_search_session
52
-
53
- @current_search_session
54
58
  end
55
59
 
56
60
  ##
@@ -160,11 +160,13 @@ module Blacklight::BlacklightHelperBehavior
160
160
  # @param [String] field
161
161
  # @param [Hash] opts
162
162
  # @options opts [String] :value
163
- # TODO: deprecate and use render_field_value
163
+ # @deprecated use IndexPresenter#field_value
164
164
  def render_index_field_value *args
165
165
  render_field_value(*args)
166
166
  end
167
+ deprecation_deprecate render_index_field_value: 'replaced by IndexPresenter#field_value'
167
168
 
169
+ # @deprecated use IndexPresenter#field_value
168
170
  def render_field_value(*args)
169
171
  options = args.extract_options!
170
172
  document = args.shift || options[:document]
@@ -172,6 +174,7 @@ module Blacklight::BlacklightHelperBehavior
172
174
  field = args.shift || options[:field]
173
175
  presenter(document).field_value field, options.except(:document, :field)
174
176
  end
177
+ deprecation_deprecate render_field_value: 'replaced by IndexPresenter#field_value'
175
178
 
176
179
  ##
177
180
  # Render the show field label for a document
@@ -218,10 +221,12 @@ module Blacklight::BlacklightHelperBehavior
218
221
  # @param [String] field
219
222
  # @param [Hash] opts
220
223
  # @options opts [String] :value
221
- # TODO: deprecate and use render_field_value
224
+ # @deprecated use ShowPresenter#field_value
222
225
  def render_document_show_field_value *args
223
226
  render_field_value(*args)
224
227
  end
228
+ deprecation_deprecate render_document_show_field_value: 'replaced by ShowPresenter#field_value'
229
+
225
230
 
226
231
  ##
227
232
  # Get the value of the document's "title" field, or a placeholder
@@ -332,7 +337,8 @@ module Blacklight::BlacklightHelperBehavior
332
337
  when 'index'
333
338
  index_presenter(document)
334
339
  else
335
- raise "Unable to determine presenter type for #{action_name} on #{controller_name}"
340
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, "Unable to determine presenter type for #{action_name} on #{controller_name}, falling back on deprecated Blacklight::DocumentPresenter")
341
+ presenter_class.new(document, self)
336
342
  end
337
343
  end
338
344
 
@@ -127,10 +127,16 @@ module Blacklight
127
127
 
128
128
  # @deprecated
129
129
  def render_field_value(values, field_config = Configuration::NullField.new)
130
- FieldPresenter.new(@controller, @document, field_config, value: values).render
130
+ field_values(field_config, value: Array(values))
131
131
  end
132
132
  deprecation_deprecate render_field_value: 'Use FieldPresenter instead'
133
133
 
134
+ # @deprecated
135
+ def render_values(values, field_config = Configuration::NullField.new)
136
+ field_values(field_config, value: Array(values))
137
+ end
138
+ deprecation_deprecate render_values: 'Use FieldPresenter instead'
139
+
134
140
  private
135
141
 
136
142
  def index_presenter
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
3
  class IndexPresenter
4
+ extend Deprecation
5
+ self.deprecation_horizon = 'Blacklight version 7.0.0'
6
+
7
+ attr_reader :document, :configuration, :view_context
8
+
4
9
  # @param [SolrDocument] document
5
- # @param [ActionController::Base] controller scope for linking and generating urls
10
+ # @param [ActionView::Base] view context scope for linking and generating urls
6
11
  # @param [Blacklight::Configuration] configuration
7
- def initialize(document, controller, configuration = controller.blacklight_config)
12
+ def initialize(document, view_context, configuration = view_context.blacklight_config)
8
13
  @document = document
14
+ @view_context = view_context
9
15
  @configuration = configuration
10
- @controller = controller
11
16
  end
12
17
 
13
18
  ##
@@ -21,17 +26,23 @@ module Blacklight
21
26
  value = case field_or_string_or_proc
22
27
  when Symbol
23
28
  config = field_config(field_or_string_or_proc)
24
- @document[field_or_string_or_proc]
29
+ document[field_or_string_or_proc]
25
30
  when Proc
26
- field_or_string_or_proc.call(@document, opts)
31
+ field_or_string_or_proc.call(document, opts)
27
32
  when String
28
33
  field_or_string_or_proc
29
34
  end
30
35
 
31
- value ||= @document.id
36
+ value ||= document.id
32
37
  field_values(config, value: value)
33
38
  end
34
39
 
40
+ # @deprecated
41
+ def render_document_index_label(*args)
42
+ label(*args)
43
+ end
44
+ deprecation_deprecate render_document_index_label: 'Use #label instead'
45
+
35
46
  ##
36
47
  # Render the index field label for a document
37
48
  #
@@ -45,6 +56,30 @@ module Blacklight
45
56
  field_values(field_config, options)
46
57
  end
47
58
 
59
+ # @deprecated
60
+ def render_index_field_value(*args)
61
+ field_value(*args)
62
+ end
63
+ deprecation_deprecate render_index_field_value: 'replaced by #field_value'
64
+
65
+ # @deprecated
66
+ def get_field_values(field_config, options={})
67
+ field_values(field_config, options)
68
+ end
69
+ deprecation_deprecate get_field_values: "replaced by #field_value"
70
+
71
+ # @deprecated
72
+ def render_field_values(values, field_config = Configuration::NullField.new)
73
+ field_values(field_config, value: Array(values))
74
+ end
75
+ deprecation_deprecate render_field_values: "replaced by #field_value"
76
+
77
+ # @deprecated
78
+ def render_values(values, field_config = Configuration::NullField.new)
79
+ field_values(field_config, value: Array(values))
80
+ end
81
+ deprecation_deprecate render_values: "replaced by #field_value"
82
+
48
83
  private
49
84
 
50
85
  ##
@@ -59,11 +94,11 @@ module Blacklight
59
94
  # @param [Blacklight::Configuration::Field] solr field configuration
60
95
  # @param [Hash] options additional options to pass to the rendering helpers
61
96
  def field_values(field_config, options={})
62
- FieldPresenter.new(@controller, @document, field_config, options).render
97
+ FieldPresenter.new(view_context, document, field_config, options).render
63
98
  end
64
99
 
65
100
  def field_config(field)
66
- @configuration.index_fields.fetch(field) { Configuration::NullField.new(field) }
101
+ configuration.index_fields.fetch(field) { Configuration::NullField.new(field) }
67
102
  end
68
103
  end
69
104
  end
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
3
  class ShowPresenter
4
+ extend Deprecation
5
+ self.deprecation_horizon = 'Blacklight version 7.0.0'
6
+
7
+ attr_reader :document, :configuration, :view_context
8
+
4
9
  # @param [SolrDocument] document
5
- # @param [ActionController::Base] controller scope for linking and generating urls
10
+ # @param [ActionView::Base] view context scope for linking and generating urls
6
11
  # @param [Blacklight::Configuration] configuration
7
- def initialize(document, controller, configuration = controller.blacklight_config)
12
+ def initialize(document, view_context, configuration = view_context.blacklight_config)
8
13
  @document = document
14
+ @view_context = view_context
9
15
  @configuration = configuration
10
- @controller = controller
11
16
  end
12
17
 
13
18
  ##
@@ -20,7 +25,7 @@ module Blacklight
20
25
  # @option options [Array<String>] :exclude array of format shortnames to not include in the output
21
26
  # @deprecated moved to ShowPresenter#link_rel_alternates
22
27
  def link_rel_alternates(options = {})
23
- LinkAlternatePresenter.new(@controller, @document, options).render
28
+ LinkAlternatePresenter.new(view_context, document, options).render
24
29
  end
25
30
 
26
31
  ##
@@ -32,7 +37,7 @@ module Blacklight
32
37
  def html_title
33
38
  if view_config.html_title_field
34
39
  fields = Array.wrap(view_config.html_title_field)
35
- f = fields.detect { |field| @document.has? field }
40
+ f = fields.detect { |field| document.has? field }
36
41
  f ||= 'id'
37
42
  field_values(field_config(f))
38
43
  else
@@ -40,6 +45,12 @@ module Blacklight
40
45
  end
41
46
  end
42
47
 
48
+ # @deprecated
49
+ def document_show_html_title
50
+ html_title
51
+ end
52
+ deprecation_deprecate document_show_html_title: "use #html_title"
53
+
43
54
  ##
44
55
  # Get the value of the document's "title" field, or a placeholder
45
56
  # value (if empty)
@@ -48,11 +59,17 @@ module Blacklight
48
59
  # @return [String]
49
60
  def heading
50
61
  fields = Array.wrap(view_config.title_field)
51
- f = fields.detect { |field| @document.has? field }
52
- f ||= @configuration.document_model.unique_key
53
- field_values(field_config(f), value: @document[f])
62
+ f = fields.detect { |field| document.has? field }
63
+ f ||= configuration.document_model.unique_key
64
+ field_values(field_config(f), value: document[f])
54
65
  end
55
66
 
67
+ # @deprecated
68
+ def document_heading
69
+ heading
70
+ end
71
+ deprecation_deprecate document_heading: "replaced by #heading"
72
+
56
73
  ##
57
74
  # Render the show field value for a document
58
75
  #
@@ -65,6 +82,30 @@ module Blacklight
65
82
  field_values(field_config(field), options)
66
83
  end
67
84
 
85
+ # @deprecated
86
+ def render_document_show_field_value(*args)
87
+ field_value(*args)
88
+ end
89
+ deprecation_deprecate render_document_show_field_value: 'replaced by #field_value'
90
+
91
+ # @deprecated
92
+ def get_field_values(field_config, options={})
93
+ field_values(field_config, options)
94
+ end
95
+ deprecation_deprecate get_field_values: "replaced by #field_value"
96
+
97
+ # @deprecated
98
+ def render_field_values(values, field_config = Configuration::NullField.new)
99
+ field_values(field_config, value: Array(values))
100
+ end
101
+ deprecation_deprecate render_field_values: "replaced by #field_value"
102
+
103
+ # @deprecated
104
+ def render_values(values, field_config = Configuration::NullField.new)
105
+ field_values(field_config, value: Array(values))
106
+ end
107
+ deprecation_deprecate render_values: "replaced by #field_value"
108
+
68
109
  private
69
110
 
70
111
  ##
@@ -79,15 +120,15 @@ module Blacklight
79
120
  # @param [Blacklight::Configuration::Field] solr field configuration
80
121
  # @param [Hash] options additional options to pass to the rendering helpers
81
122
  def field_values(field_config, options={})
82
- FieldPresenter.new(@controller, @document, field_config, options).render
123
+ FieldPresenter.new(view_context, document, field_config, options).render
83
124
  end
84
125
 
85
126
  def view_config
86
- @configuration.view_config(:show)
127
+ configuration.view_config(:show)
87
128
  end
88
129
 
89
130
  def field_config(field)
90
- @configuration.show_fields.fetch(field) { Configuration::NullField.new(field) }
131
+ configuration.show_fields.fetch(field) { Configuration::NullField.new(field) }
91
132
  end
92
133
  end
93
134
  end
@@ -1,10 +1,11 @@
1
+ <% doc_presenter = index_presenter(document) %>
1
2
  <%# default partial to display solr document fields in catalog index view -%>
2
3
  <dl class="document-metadata dl-horizontal dl-invert">
3
4
 
4
5
  <% index_fields(document).each do |field_name, field| -%>
5
6
  <% if should_render_index_field? document, field %>
6
7
  <dt class="blacklight-<%= field_name.parameterize %>"><%= render_index_field_label document, field: field_name %></dt>
7
- <dd class="blacklight-<%= field_name.parameterize %>"><%= render_index_field_value document, field: field_name %></dd>
8
+ <dd class="blacklight-<%= field_name.parameterize %>"><%= doc_presenter.field_value field_name %></dd>
8
9
  <% end -%>
9
10
  <% end -%>
10
11
 
@@ -1,9 +1,10 @@
1
+ <% doc_presenter = show_presenter(document) %>
1
2
  <%# default partial to display solr document fields in catalog show view -%>
2
3
  <dl class="dl-horizontal dl-invert">
3
4
  <% document_show_fields(document).each do |field_name, field| -%>
4
5
  <% if should_render_show_field? document, field %>
5
6
  <dt class="blacklight-<%= field_name.parameterize %>"><%= render_document_show_field_label document, field: field_name %></dt>
6
- <dd class="blacklight-<%= field_name.parameterize %>"><%= render_document_show_field_value document, field: field_name %></dd>
7
+ <dd class="blacklight-<%= field_name.parameterize %>"><%= doc_presenter.field_value field_name %></dd>
7
8
  <% end -%>
8
9
  <% end -%>
9
10
  </dl>
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.add_dependency "twitter-typeahead-rails", '~> 0.11'
36
36
 
37
37
  s.add_development_dependency "solr_wrapper"
38
- s.add_development_dependency "rspec-rails", ">= 3.4", "< 4"
38
+ s.add_development_dependency "rspec-rails", "~> 3.5"
39
39
  s.add_development_dependency "rspec-its"
40
40
  s.add_development_dependency "rspec-collection_matchers", ">= 1.0"
41
41
  s.add_development_dependency "capybara", '~> 2.6.0'
@@ -2,7 +2,7 @@
2
2
  class CreateSearches < ActiveRecord::Migration
3
3
  def self.up
4
4
  create_table :searches do |t|
5
- t.text :query_params
5
+ t.binary :query_params
6
6
  t.integer :user_id, index: true
7
7
  t.string :user_type
8
8
 
@@ -6,7 +6,7 @@ class CreateBookmarks < ActiveRecord::Migration
6
6
  t.string :user_type
7
7
  t.string :document_id, index: true
8
8
  t.string :document_type
9
- t.string :title
9
+ t.binary :title
10
10
  t.timestamps null: false
11
11
  end
12
12
  end
@@ -165,6 +165,7 @@ describe BlacklightHelper do
165
165
  describe "#render_index_field_value" do
166
166
  let(:presenter) { double }
167
167
  before do
168
+ allow(Deprecation).to receive(:warn)
168
169
  allow(helper).to receive(:presenter).with(doc).and_return(presenter)
169
170
  end
170
171
 
@@ -191,6 +192,7 @@ describe BlacklightHelper do
191
192
  let(:presenter) { double }
192
193
  before do
193
194
  allow(helper).to receive(:presenter).with(doc).and_return(presenter)
195
+ allow(Deprecation).to receive(:warn)
194
196
  end
195
197
 
196
198
  let(:doc) { double }
@@ -428,4 +428,12 @@ describe Blacklight::DocumentPresenter do
428
428
  end
429
429
  end
430
430
  end
431
+
432
+ describe '#render_values' do
433
+ it 'renders field values as a string' do
434
+ expect(subject.render_values('x')).to eq 'x'
435
+ expect(subject.render_values(['x', 'y'])).to eq 'x and y'
436
+ expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z'
437
+ end
438
+ end
431
439
  end
@@ -143,5 +143,31 @@ describe Blacklight::IndexPresenter do
143
143
  end
144
144
  end
145
145
  end
146
+
147
+ describe 'deprecated methods' do
148
+ before do
149
+ allow(Deprecation).to receive(:warn)
150
+ end
151
+
152
+ let(:field_config) { config.add_index_field 'qwerty' }
153
+
154
+ describe '#get_field_values' do
155
+ it 'renders values for the given field' do
156
+ expect(subject.get_field_values(field_config, value: ['x', 'y'])).to eq 'x and y'
157
+ end
158
+ end
159
+
160
+ describe '#render_field_values' do
161
+ it 'renders values for the given field' do
162
+ expect(subject.render_field_values('x')).to eq 'x'
163
+ end
164
+ end
165
+
166
+ describe '#render_values' do
167
+ it 'renders values for the given field' do
168
+ expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z'
169
+ end
170
+ end
171
+ end
146
172
  end
147
173
 
@@ -283,5 +283,31 @@ describe Blacklight::ShowPresenter do
283
283
  end
284
284
  end
285
285
  end
286
+
287
+ describe 'deprecated methods' do
288
+ before do
289
+ allow(Deprecation).to receive(:warn)
290
+ end
291
+
292
+ let(:field_config) { config.add_index_field 'qwerty' }
293
+
294
+ describe '#get_field_values' do
295
+ it 'renders values for the given field' do
296
+ expect(subject.get_field_values(field_config, value: ['x', 'y'])).to eq 'x and y'
297
+ end
298
+ end
299
+
300
+ describe '#render_field_values' do
301
+ it 'renders values for the given field' do
302
+ expect(subject.render_field_values('x')).to eq 'x'
303
+ end
304
+ end
305
+
306
+ describe '#render_values' do
307
+ it 'renders values for the given field' do
308
+ expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z'
309
+ end
310
+ end
311
+ end
286
312
  end
287
313
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.0
4
+ version: 6.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2016-07-01 00:00:00.000000000 Z
20
+ date: 2016-07-07 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -161,22 +161,16 @@ dependencies:
161
161
  name: rspec-rails
162
162
  requirement: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '3.4'
167
- - - "<"
164
+ - - "~>"
168
165
  - !ruby/object:Gem::Version
169
- version: '4'
166
+ version: '3.5'
170
167
  type: :development
171
168
  prerelease: false
172
169
  version_requirements: !ruby/object:Gem::Requirement
173
170
  requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- version: '3.4'
177
- - - "<"
171
+ - - "~>"
178
172
  - !ruby/object:Gem::Version
179
- version: '4'
173
+ version: '3.5'
180
174
  - !ruby/object:Gem::Dependency
181
175
  name: rspec-its
182
176
  requirement: !ruby/object:Gem::Requirement