blacklight 7.5.1 → 7.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +23 -34
- data/.travis.yml +3 -3
- data/VERSION +1 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -2
- data/app/helpers/blacklight/catalog_helper_behavior.rb +0 -2
- data/app/presenters/blacklight/document_presenter.rb +27 -36
- data/app/presenters/blacklight/field_presenter.rb +31 -6
- data/app/presenters/blacklight/index_presenter.rb +2 -2
- data/app/presenters/blacklight/show_presenter.rb +3 -3
- data/app/views/catalog/_constraints.html.erb +1 -1
- data/app/views/catalog/_facet_pagination.html.erb +2 -2
- data/app/views/catalog/_field.json.jbuilder +2 -2
- data/app/views/catalog/_index.html.erb +3 -3
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_show.html.erb +3 -3
- data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
- data/app/views/catalog/_start_over.html.erb +1 -0
- data/app/views/catalog/_thumbnail.html.erb +1 -1
- data/app/views/catalog/index.json.jbuilder +2 -1
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/catalog/show.json.jbuilder +2 -1
- data/app/views/layouts/blacklight/base.html.erb +2 -2
- data/config/locales/blacklight.ar.yml +2 -0
- data/config/locales/blacklight.de.yml +2 -0
- data/config/locales/blacklight.en.yml +2 -0
- data/config/locales/blacklight.es.yml +2 -0
- data/config/locales/blacklight.fr.yml +2 -0
- data/config/locales/blacklight.hu.yml +2 -0
- data/config/locales/blacklight.it.yml +2 -0
- data/config/locales/blacklight.nl.yml +2 -0
- data/config/locales/blacklight.pt-BR.yml +2 -0
- data/config/locales/blacklight.sq.yml +2 -0
- data/config/locales/blacklight.zh.yml +2 -0
- data/lib/blacklight/configuration/field.rb +5 -4
- data/spec/helpers/blacklight_helper_spec.rb +17 -0
- data/spec/helpers/catalog_helper_spec.rb +0 -7
- data/spec/presenters/blacklight/document_presenter_spec.rb +22 -62
- data/spec/presenters/blacklight/field_presenter_spec.rb +268 -0
- data/spec/presenters/blacklight/index_presenter_spec.rb +0 -142
- data/spec/presenters/blacklight/show_presenter_spec.rb +0 -177
- metadata +6 -3
@@ -0,0 +1,268 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Blacklight::FieldPresenter, api: true do
|
4
|
+
subject(:presenter) { described_class.new(request_context, document, field_config, options) }
|
5
|
+
|
6
|
+
let(:request_context) { double('View context', search_state: search_state, should_render_field?: true, blacklight_config: config) }
|
7
|
+
let(:document) do
|
8
|
+
SolrDocument.new(id: 1,
|
9
|
+
'link_to_facet_true' => 'x',
|
10
|
+
'link_to_facet_named' => 'x',
|
11
|
+
'qwer' => 'document qwer value',
|
12
|
+
'some_field' => [1, 2])
|
13
|
+
end
|
14
|
+
let(:options) { {} }
|
15
|
+
let(:params) { {} }
|
16
|
+
let(:controller) { double }
|
17
|
+
let(:search_state) { Blacklight::SearchState.new(params, config, controller) }
|
18
|
+
|
19
|
+
let(:field_config) { config.index_fields[field_name] }
|
20
|
+
let(:field_name) { 'asdf' }
|
21
|
+
let(:config) do
|
22
|
+
Blacklight::Configuration.new.configure do |config|
|
23
|
+
config.add_index_field 'qwer'
|
24
|
+
config.add_index_field 'asdf', helper_method: :render_asdf_index_field
|
25
|
+
config.add_index_field 'link_to_facet_true', link_to_facet: true
|
26
|
+
config.add_index_field 'link_to_facet_named', link_to_facet: :some_field
|
27
|
+
config.add_index_field 'highlight', highlight: true
|
28
|
+
config.add_index_field 'solr_doc_accessor', accessor: true
|
29
|
+
config.add_index_field 'explicit_accessor', accessor: :solr_doc_accessor
|
30
|
+
config.add_index_field 'explicit_array_accessor', accessor: [:solr_doc_accessor, :some_method]
|
31
|
+
config.add_index_field 'explicit_values', values: ->(_config, _doc) { ['some-value'] }
|
32
|
+
config.add_index_field 'alias', field: 'qwer'
|
33
|
+
config.add_index_field 'with_default', default: 'value'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#render' do
|
38
|
+
subject(:result) { presenter.render }
|
39
|
+
|
40
|
+
context 'when an explicit html value is provided' do
|
41
|
+
let(:options) { { value: '<b>val1</b>' } }
|
42
|
+
|
43
|
+
it { is_expected.to eq '<b>val1</b>' }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when an explicit array value with unsafe characters is provided' do
|
47
|
+
let(:options) { { value: ['<a', 'b'] } }
|
48
|
+
|
49
|
+
it { is_expected.to eq '<a and b' }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when an explicit array value is provided' do
|
53
|
+
let(:options) { { value: %w[a b c] } }
|
54
|
+
|
55
|
+
it { is_expected.to eq 'a, b, and c' }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when an explicit value is provided' do
|
59
|
+
let(:options) { { value: 'asdf' } }
|
60
|
+
|
61
|
+
it { is_expected.to eq 'asdf' }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when field has a helper method' do
|
65
|
+
before do
|
66
|
+
allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
|
67
|
+
end
|
68
|
+
|
69
|
+
it { is_expected.to eq 'custom asdf value' }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when field has link_to_facet with true' do
|
73
|
+
before do
|
74
|
+
allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_facet_true' => ['x'] }).and_return('/foo')
|
75
|
+
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
76
|
+
end
|
77
|
+
|
78
|
+
let(:field_name) { 'link_to_facet_true' }
|
79
|
+
|
80
|
+
it { is_expected.to eq 'bar' }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when field has link_to_facet with a field name' do
|
84
|
+
before do
|
85
|
+
allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo')
|
86
|
+
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:field_name) { 'link_to_facet_named' }
|
90
|
+
|
91
|
+
it { is_expected.to eq 'bar' }
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when no highlight field is available' do
|
95
|
+
before do
|
96
|
+
allow(document).to receive(:has_highlight_field?).and_return(false)
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:field_name) { 'highlight' }
|
100
|
+
|
101
|
+
it { is_expected.to be_blank }
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when highlight field is available' do
|
105
|
+
before do
|
106
|
+
allow(document).to receive(:has_highlight_field?).and_return(true)
|
107
|
+
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
108
|
+
end
|
109
|
+
|
110
|
+
let(:field_name) { 'highlight' }
|
111
|
+
|
112
|
+
it { is_expected.to eq '<em>highlight</em>' }
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when no options are provided' do
|
116
|
+
let(:field_name) { 'qwer' }
|
117
|
+
|
118
|
+
it "checks the document field value" do
|
119
|
+
expect(subject).to eq 'document qwer value'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when accessor is true' do
|
124
|
+
before do
|
125
|
+
allow(document).to receive_messages(solr_doc_accessor: "123")
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:field_name) { 'solr_doc_accessor' }
|
129
|
+
|
130
|
+
it { is_expected.to eq '123' }
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when accessor is set to a value' do
|
134
|
+
let(:field_name) { 'explicit_accessor' }
|
135
|
+
|
136
|
+
it 'calls the accessor with the field_name as the argument' do
|
137
|
+
expect(document).to receive(:solr_doc_accessor).with('explicit_accessor').and_return("123")
|
138
|
+
|
139
|
+
expect(subject).to eq '123'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when accessor is set to an array' do
|
144
|
+
let(:field_name) { 'explicit_array_accessor' }
|
145
|
+
|
146
|
+
it 'calls the accessors on the return of the preceeding' do
|
147
|
+
allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123")
|
148
|
+
|
149
|
+
expect(subject).to eq '123'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when the values lambda is provided' do
|
154
|
+
let(:field_name) { 'explicit_values' }
|
155
|
+
|
156
|
+
it 'calls the accessors on the return of the preceeding' do
|
157
|
+
expect(subject).to eq 'some-value'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'when the field is an alias' do
|
162
|
+
let(:field_name) { 'alias' }
|
163
|
+
|
164
|
+
it { is_expected.to eq 'document qwer value' }
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'when the field has a default' do
|
168
|
+
let(:field_name) { 'with_default' }
|
169
|
+
|
170
|
+
it { is_expected.to eq 'value' }
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'for a field with the helper_method option' do
|
174
|
+
let(:field_name) { 'field_with_helper' }
|
175
|
+
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
|
176
|
+
let(:document) do
|
177
|
+
SolrDocument.new(id: 1, 'field_with_helper' => 'value')
|
178
|
+
end
|
179
|
+
let(:options) { { a: 1 } }
|
180
|
+
|
181
|
+
it "checks call the helper method with arguments" do
|
182
|
+
allow(request_context).to receive(:render_field_with_helper) do |*args|
|
183
|
+
args.first
|
184
|
+
end
|
185
|
+
|
186
|
+
expect(result).to include :document, :field, :value, :config, :a
|
187
|
+
expect(result[:document]).to eq document
|
188
|
+
expect(result[:field]).to eq 'field_with_helper'
|
189
|
+
expect(result[:value]).to eq ['value']
|
190
|
+
expect(result[:config]).to eq field_config
|
191
|
+
expect(result[:a]).to eq 1
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#label' do
|
197
|
+
let(:field_config) { Blacklight::Configuration::Field.new(field: 'some_field') }
|
198
|
+
|
199
|
+
it 'calculates the field label from the field configuration' do
|
200
|
+
allow(field_config).to receive(:display_label).with('index', anything).and_return('some label')
|
201
|
+
|
202
|
+
expect(presenter.label).to eq 'some label'
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'sends along a count of document values so i18n can do pluralization' do
|
206
|
+
allow(field_config).to receive(:display_label).with('index', count: 2).and_return('values')
|
207
|
+
|
208
|
+
expect(presenter.label).to eq 'values'
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe '#render_field?' do
|
213
|
+
subject { presenter.render_field? }
|
214
|
+
|
215
|
+
let(:field_config) { double('field config', if: true, unless: false) }
|
216
|
+
|
217
|
+
before do
|
218
|
+
allow(presenter).to receive_messages(document_has_value?: true)
|
219
|
+
end
|
220
|
+
|
221
|
+
it { is_expected.to be true }
|
222
|
+
|
223
|
+
context 'when the view context says not to render the field' do
|
224
|
+
let(:request_context) { double('View context', should_render_field?: false, blacklight_config: config) }
|
225
|
+
|
226
|
+
before do
|
227
|
+
allow(field_config).to receive_messages(if: false)
|
228
|
+
end
|
229
|
+
|
230
|
+
it { is_expected.to be false }
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe '#any?' do
|
235
|
+
subject { presenter.any? }
|
236
|
+
|
237
|
+
context 'when the document has the field value' do
|
238
|
+
let(:field_config) { double(field: 'asdf', highlight: false, accessor: nil, default: nil, values: nil) }
|
239
|
+
|
240
|
+
before do
|
241
|
+
allow(document).to receive(:fetch).with('asdf', nil).and_return(['value'])
|
242
|
+
end
|
243
|
+
|
244
|
+
it { is_expected.to be true }
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when the document has a highlight field value' do
|
248
|
+
let(:field_config) { double(field: 'asdf', highlight: true) }
|
249
|
+
|
250
|
+
before do
|
251
|
+
allow(document).to receive(:has_highlight_field?).with('asdf').and_return(true)
|
252
|
+
allow(document).to receive(:highlight_field).with('asdf').and_return(['value'])
|
253
|
+
end
|
254
|
+
|
255
|
+
it { is_expected.to be true }
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'when the field is a model accessor' do
|
259
|
+
let(:field_config) { double(field: 'asdf', highlight: false, accessor: true) }
|
260
|
+
|
261
|
+
before do
|
262
|
+
allow(document).to receive(:send).with('asdf').and_return(['value'])
|
263
|
+
end
|
264
|
+
|
265
|
+
it { is_expected.to be true }
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
@@ -24,148 +24,6 @@ RSpec.describe Blacklight::IndexPresenter, api: true do
|
|
24
24
|
allow(request_context).to receive(:search_state).and_return(search_state)
|
25
25
|
end
|
26
26
|
|
27
|
-
describe '#field_value' do
|
28
|
-
subject { presenter.field_value field }
|
29
|
-
|
30
|
-
let(:field) { config.index_fields[field_name] }
|
31
|
-
let(:field_name) { 'asdf' }
|
32
|
-
let(:config) do
|
33
|
-
Blacklight::Configuration.new.configure do |config|
|
34
|
-
config.add_index_field 'qwer'
|
35
|
-
config.add_index_field 'asdf', helper_method: :render_asdf_index_field
|
36
|
-
config.add_index_field 'link_to_facet_true', link_to_facet: true
|
37
|
-
config.add_index_field 'link_to_facet_named', link_to_facet: :some_field
|
38
|
-
config.add_index_field 'highlight', highlight: true
|
39
|
-
config.add_index_field 'solr_doc_accessor', accessor: true
|
40
|
-
config.add_index_field 'explicit_accessor', accessor: :solr_doc_accessor
|
41
|
-
config.add_index_field 'alias', field: 'qwer'
|
42
|
-
config.add_index_field 'with_default', default: 'value'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when an explicit value is provided' do
|
47
|
-
subject { presenter.field_value field, value: 'asdf' }
|
48
|
-
|
49
|
-
it { is_expected.to eq 'asdf' }
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'when field has a helper method' do
|
53
|
-
before do
|
54
|
-
allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value')
|
55
|
-
end
|
56
|
-
|
57
|
-
it { is_expected.to eq 'custom asdf value' }
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when field has link_to_facet with true' do
|
61
|
-
before do
|
62
|
-
allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_facet_true' => ['x'] }).and_return('/foo')
|
63
|
-
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
64
|
-
end
|
65
|
-
|
66
|
-
let(:field_name) { 'link_to_facet_true' }
|
67
|
-
|
68
|
-
it { is_expected.to eq 'bar' }
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'when field has link_to_facet with a field name' do
|
72
|
-
before do
|
73
|
-
allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo')
|
74
|
-
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
75
|
-
end
|
76
|
-
|
77
|
-
let(:field_name) { 'link_to_facet_named' }
|
78
|
-
|
79
|
-
it { is_expected.to eq 'bar' }
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when no highlight field is available' do
|
83
|
-
before do
|
84
|
-
allow(document).to receive(:has_highlight_field?).and_return(false)
|
85
|
-
end
|
86
|
-
|
87
|
-
let(:field_name) { 'highlight' }
|
88
|
-
|
89
|
-
it { is_expected.to be_blank }
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when highlight field is available' do
|
93
|
-
before do
|
94
|
-
allow(document).to receive(:has_highlight_field?).and_return(true)
|
95
|
-
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
96
|
-
end
|
97
|
-
|
98
|
-
let(:field_name) { 'highlight' }
|
99
|
-
|
100
|
-
it { is_expected.to eq '<em>highlight</em>' }
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'when no options are provided' do
|
104
|
-
let(:field_name) { 'qwer' }
|
105
|
-
|
106
|
-
it "checks the document field value" do
|
107
|
-
expect(subject).to eq 'document qwer value'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when accessor is true' do
|
112
|
-
before do
|
113
|
-
allow(document).to receive_messages(solr_doc_accessor: "123")
|
114
|
-
end
|
115
|
-
|
116
|
-
let(:field_name) { 'solr_doc_accessor' }
|
117
|
-
|
118
|
-
it { is_expected.to eq '123' }
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'when accessor is set to a value' do
|
122
|
-
let(:field_name) { 'explicit_accessor' }
|
123
|
-
|
124
|
-
it 'calls the accessor with the field_name as the argument' do
|
125
|
-
expect(document).to receive(:solr_doc_accessor).with('explicit_accessor').and_return("123")
|
126
|
-
|
127
|
-
expect(subject).to eq '123'
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'when the field is an alias' do
|
132
|
-
let(:field_name) { 'alias' }
|
133
|
-
|
134
|
-
it { is_expected.to eq 'document qwer value' }
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'when the field has a default' do
|
138
|
-
let(:field_name) { 'with_default' }
|
139
|
-
|
140
|
-
it { is_expected.to eq 'value' }
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe '#field_values' do
|
145
|
-
context 'for a field with the helper_method option' do
|
146
|
-
let(:field_name) { 'field_with_helper' }
|
147
|
-
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
|
148
|
-
let(:document) do
|
149
|
-
SolrDocument.new(id: 1, 'field_with_helper' => 'value')
|
150
|
-
end
|
151
|
-
|
152
|
-
it "checks call the helper method with arguments" do
|
153
|
-
allow(request_context).to receive(:render_field_with_helper) do |*args|
|
154
|
-
args.first
|
155
|
-
end
|
156
|
-
|
157
|
-
options = subject.send(:field_values, field_config, a: 1)
|
158
|
-
|
159
|
-
expect(options).to include :document, :field, :value, :config, :a
|
160
|
-
expect(options[:document]).to eq document
|
161
|
-
expect(options[:field]).to eq 'field_with_helper'
|
162
|
-
expect(options[:value]).to eq ['value']
|
163
|
-
expect(options[:config]).to eq field_config
|
164
|
-
expect(options[:a]).to eq 1
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
27
|
describe '#fields' do
|
170
28
|
let(:field) { instance_double(Blacklight::Configuration::Field) }
|
171
29
|
|
@@ -107,158 +107,6 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
describe '#field_value' do
|
111
|
-
subject { presenter.field_value field }
|
112
|
-
|
113
|
-
let(:field) { config.show_fields[field_name] }
|
114
|
-
let(:field_name) { 'asdf' }
|
115
|
-
let(:config) do
|
116
|
-
Blacklight::Configuration.new.configure do |config|
|
117
|
-
config.add_show_field 'qwer'
|
118
|
-
config.add_show_field 'asdf', helper_method: :render_asdf_document_show_field
|
119
|
-
config.add_show_field 'link_to_facet_true', link_to_facet: true
|
120
|
-
config.add_show_field 'link_to_facet_named', link_to_facet: :some_field
|
121
|
-
config.add_show_field 'highlight', highlight: true
|
122
|
-
config.add_show_field 'solr_doc_accessor', accessor: true
|
123
|
-
config.add_show_field 'explicit_accessor', accessor: :solr_doc_accessor
|
124
|
-
config.add_show_field 'explicit_array_accessor', accessor: [:solr_doc_accessor, :some_method]
|
125
|
-
config.add_show_field 'explicit_values', values: ->(_config, _doc) { ['some-value'] }
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'when an explicit html value is provided' do
|
130
|
-
subject { presenter.field_value field, value: '<b>val1</b>' }
|
131
|
-
|
132
|
-
it { is_expected.to eq '<b>val1</b>' }
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'when an explicit array value with unsafe characters is provided' do
|
136
|
-
subject { presenter.field_value field, value: ['<a', 'b'] }
|
137
|
-
|
138
|
-
it { is_expected.to eq '<a and b' }
|
139
|
-
end
|
140
|
-
|
141
|
-
context 'when an explicit array value is provided' do
|
142
|
-
subject { presenter.field_value field, value: %w[a b c] }
|
143
|
-
|
144
|
-
it { is_expected.to eq 'a, b, and c' }
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when an explicit value is provided' do
|
148
|
-
subject { presenter.field_value field, value: 'val1' }
|
149
|
-
|
150
|
-
it { is_expected.to eq 'val1' }
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'when field has a helper method' do
|
154
|
-
before do
|
155
|
-
allow(request_context).to receive(:render_asdf_document_show_field).and_return('custom asdf value')
|
156
|
-
end
|
157
|
-
|
158
|
-
it { is_expected.to eq 'custom asdf value' }
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when field has link_to_facet with true' do
|
162
|
-
before do
|
163
|
-
allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_facet_true' => ['x'] }).and_return('/foo')
|
164
|
-
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
165
|
-
end
|
166
|
-
|
167
|
-
let(:field_name) { 'link_to_facet_true' }
|
168
|
-
|
169
|
-
it { is_expected.to eq 'bar' }
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when field has link_to_facet with a field name' do
|
173
|
-
before do
|
174
|
-
allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo')
|
175
|
-
allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar')
|
176
|
-
end
|
177
|
-
|
178
|
-
let(:field_name) { 'link_to_facet_named' }
|
179
|
-
|
180
|
-
it { is_expected.to eq 'bar' }
|
181
|
-
end
|
182
|
-
|
183
|
-
context 'when no highlight field is available' do
|
184
|
-
before do
|
185
|
-
allow(document).to receive(:has_highlight_field?).and_return(false)
|
186
|
-
end
|
187
|
-
|
188
|
-
let(:field_name) { 'highlight' }
|
189
|
-
|
190
|
-
it { is_expected.to be_blank }
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'when highlight field is available' do
|
194
|
-
before do
|
195
|
-
allow(document).to receive(:has_highlight_field?).and_return(true)
|
196
|
-
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe])
|
197
|
-
end
|
198
|
-
|
199
|
-
let(:field_name) { 'highlight' }
|
200
|
-
|
201
|
-
it { is_expected.to eq '<em>highlight</em>' }
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'when highlight returns multiple values' do
|
205
|
-
before do
|
206
|
-
allow(document).to receive(:has_highlight_field?).and_return(true)
|
207
|
-
allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe, '<em>other highlight</em>'.html_safe])
|
208
|
-
end
|
209
|
-
|
210
|
-
let(:field_name) { 'highlight' }
|
211
|
-
|
212
|
-
it { is_expected.to eq '<em>highlight</em> and <em>other highlight</em>' }
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'when no options are provided' do
|
216
|
-
let(:field_name) { 'qwer' }
|
217
|
-
|
218
|
-
it "checks the document field value" do
|
219
|
-
expect(subject).to eq 'document qwer value'
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'when accessor is true' do
|
224
|
-
before do
|
225
|
-
allow(document).to receive_messages(solr_doc_accessor: "123")
|
226
|
-
end
|
227
|
-
|
228
|
-
let(:field_name) { 'solr_doc_accessor' }
|
229
|
-
|
230
|
-
it { is_expected.to eq '123' }
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'when accessor is set to a value' do
|
234
|
-
let(:field_name) { 'explicit_accessor' }
|
235
|
-
|
236
|
-
it 'calls the accessor with the field_name as the argument' do
|
237
|
-
expect(document).to receive(:solr_doc_accessor).with('explicit_accessor').and_return("123")
|
238
|
-
|
239
|
-
expect(subject).to eq '123'
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
context 'when accessor is set to an array' do
|
244
|
-
let(:field_name) { 'explicit_array_accessor' }
|
245
|
-
|
246
|
-
it 'calls the accessors on the return of the preceeding' do
|
247
|
-
allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123")
|
248
|
-
|
249
|
-
expect(subject).to eq '123'
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context 'when the values lambda is provided' do
|
254
|
-
let(:field_name) { 'explicit_values' }
|
255
|
-
|
256
|
-
it 'calls the accessors on the return of the preceeding' do
|
257
|
-
expect(subject).to eq 'some-value'
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
110
|
describe '#fields' do
|
263
111
|
let(:field) { instance_double(Blacklight::Configuration::Field) }
|
264
112
|
|
@@ -322,29 +170,4 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
|
|
322
170
|
expect(subject.html_title).to eq 'hardcoded'
|
323
171
|
end
|
324
172
|
end
|
325
|
-
|
326
|
-
describe '#field_values' do
|
327
|
-
context 'for a field with the helper_method option' do
|
328
|
-
let(:field_name) { 'field_with_helper' }
|
329
|
-
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }
|
330
|
-
let(:document) do
|
331
|
-
SolrDocument.new(id: 1, 'field_with_helper' => 'value')
|
332
|
-
end
|
333
|
-
|
334
|
-
it "checks call the helper method with arguments" do
|
335
|
-
allow(request_context).to receive(:render_field_with_helper) do |*args|
|
336
|
-
args.first
|
337
|
-
end
|
338
|
-
|
339
|
-
options = subject.send(:field_values, field_config, a: 1)
|
340
|
-
|
341
|
-
expect(options).to include :document, :field, :value, :config, :a
|
342
|
-
expect(options[:document]).to eq document
|
343
|
-
expect(options[:field]).to eq 'field_with_helper'
|
344
|
-
expect(options[:value]).to eq ['value']
|
345
|
-
expect(options[:config]).to eq field_config
|
346
|
-
expect(options[:a]).to eq 1
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
173
|
end
|