blacklight 5.5.1 → 5.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +8 -16
- data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/facets_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -1
- data/app/helpers/blacklight/url_helper_behavior.rb +5 -1
- data/app/views/catalog/_view_type_group.html.erb +1 -1
- data/blacklight.gemspec +2 -1
- data/gemfiles/rails3.gemfile +1 -1
- data/gemfiles/rails4.1.gemfile +1 -1
- data/gemfiles/rails4.gemfile +1 -1
- data/lib/blacklight/catalog.rb +0 -1
- data/lib/blacklight/solr/facet_paginator.rb +22 -10
- data/lib/generators/blacklight/install_generator.rb +1 -1
- data/spec/controllers/bookmarks_controller_spec.rb +6 -6
- data/spec/controllers/catalog_controller_spec.rb +48 -48
- data/spec/features/alternate_controller_spec.rb +3 -3
- data/spec/features/record_view_spec.rb +1 -1
- data/spec/features/search_filters_spec.rb +4 -4
- data/spec/features/search_results_spec.rb +12 -12
- data/spec/helpers/blacklight_helper_spec.rb +83 -83
- data/spec/helpers/catalog_helper_spec.rb +37 -37
- data/spec/helpers/configuration_helper_spec.rb +39 -39
- data/spec/helpers/facets_helper_spec.rb +37 -37
- data/spec/helpers/render_constraints_helper_spec.rb +6 -1
- data/spec/helpers/search_history_constraints_helper_spec.rb +9 -9
- data/spec/helpers/url_helper_spec.rb +49 -39
- data/spec/lib/blacklight/configurable_spec.rb +5 -5
- data/spec/lib/blacklight/configuration_spec.rb +8 -8
- data/spec/lib/blacklight/facet_paginator_spec.rb +25 -0
- data/spec/lib/blacklight/routes_spec.rb +4 -4
- data/spec/lib/blacklight/search_fields_spec.rb +3 -3
- data/spec/lib/blacklight/solr/document_spec.rb +2 -2
- data/spec/lib/blacklight/solr_helper_spec.rb +37 -37
- data/spec/lib/blacklight/solr_response/group_response_spec.rb +1 -1
- data/spec/lib/blacklight/solr_response_spec.rb +31 -31
- data/spec/lib/document_presenter_spec.rb +41 -41
- data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
- data/spec/models/record_mailer_spec.rb +1 -1
- data/spec/models/search_spec.rb +1 -1
- data/spec/routing/catalog_routing_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/support/include_text.rb +2 -3
- data/spec/views/catalog/_constraints.html.erb_spec.rb +7 -7
- data/spec/views/catalog/_document.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_facets.html.erb_spec.rb +6 -6
- data/spec/views/catalog/_index_default.erb_spec.rb +10 -10
- data/spec/views/catalog/_index_header_default.html.erb_spec.rb +5 -5
- data/spec/views/catalog/_show_default.erb_spec.rb +10 -10
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +5 -5
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_thumbnail_default.erb_spec.rb +4 -4
- data/spec/views/catalog/_view_type_group.html.erb_spec.rb +5 -2
- data/spec/views/catalog/facet.html.erb_spec.rb +5 -5
- data/spec/views/catalog/index.atom.builder_spec.rb +2 -2
- data/spec/views/catalog/index.html.erb_spec.rb +5 -5
- data/spec/views/catalog/show.html.erb_spec.rb +8 -8
- data/tasks/blacklight.rake +1 -2
- metadata +18 -4
@@ -14,7 +14,7 @@ describe CatalogHelper do
|
|
14
14
|
|
15
15
|
mock_response = Kaminari.paginate_array(mock_docs).page(current_page).per(per_page)
|
16
16
|
|
17
|
-
mock_response.
|
17
|
+
allow(mock_response).to receive(:docs).and_return(mock_docs.slice(start, per_page))
|
18
18
|
mock_response
|
19
19
|
end
|
20
20
|
|
@@ -62,7 +62,7 @@ describe CatalogHelper do
|
|
62
62
|
|
63
63
|
it "should use the model_name from the response" do
|
64
64
|
response = mock_response :total => 1
|
65
|
-
response.
|
65
|
+
allow(response).to receive(:model_name).and_return(double(:human => 'thingy'))
|
66
66
|
|
67
67
|
html = page_entries_info(response)
|
68
68
|
expect(html).to eq "<strong>1</strong> thingy found"
|
@@ -126,82 +126,82 @@ describe CatalogHelper do
|
|
126
126
|
|
127
127
|
describe "should_autofocus_on_search_box?" do
|
128
128
|
it "should be focused if we're on a catalog-like index page without query or facet parameters" do
|
129
|
-
helper.
|
130
|
-
expect(helper.should_autofocus_on_search_box?).to
|
129
|
+
allow(helper).to receive_messages(controller: CatalogController.new, action_name: "index", has_search_parameters?: false)
|
130
|
+
expect(helper.should_autofocus_on_search_box?).to be true
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should not be focused if we're not on a catalog controller" do
|
134
|
-
helper.
|
135
|
-
expect(helper.should_autofocus_on_search_box?).to
|
134
|
+
allow(helper).to receive_messages(controller: ApplicationController.new)
|
135
|
+
expect(helper.should_autofocus_on_search_box?).to be false
|
136
136
|
end
|
137
137
|
|
138
138
|
it "should not be focused if we're not on a catalog controller index" do
|
139
|
-
helper.
|
140
|
-
expect(helper.should_autofocus_on_search_box?).to
|
139
|
+
allow(helper).to receive_messages(controller: CatalogController.new, action_name: "show")
|
140
|
+
expect(helper.should_autofocus_on_search_box?).to be false
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should not be focused if a search parameters are provided" do
|
144
|
-
helper.
|
145
|
-
expect(helper.should_autofocus_on_search_box?).to
|
144
|
+
allow(helper).to receive_messages(controller: CatalogController.new, action_name: "index", has_search_parameters?: true)
|
145
|
+
expect(helper.should_autofocus_on_search_box?).to be false
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
149
|
describe "has_thumbnail?" do
|
150
150
|
it "should have a thumbnail if a thumbnail_method is configured" do
|
151
|
-
helper.
|
151
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
|
152
152
|
document = double()
|
153
|
-
expect(helper.has_thumbnail? document).to
|
153
|
+
expect(helper.has_thumbnail? document).to be true
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should have a thumbnail if a thumbnail_field is configured and it exists in the document" do
|
157
|
-
helper.
|
157
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
|
158
158
|
document = double(:has? => true)
|
159
|
-
expect(helper.has_thumbnail? document).to
|
159
|
+
expect(helper.has_thumbnail? document).to be true
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should not have a thumbnail if the thumbnail_field is missing from the document" do
|
163
|
-
helper.
|
163
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
|
164
164
|
document = double(:has? => false)
|
165
|
-
expect(helper.has_thumbnail? document).to
|
165
|
+
expect(helper.has_thumbnail? document).to be false
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should not have a thumbnail if none of the fields are configured" do
|
169
|
-
helper.
|
170
|
-
expect(helper.has_thumbnail? double()).to
|
169
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))
|
170
|
+
expect(helper.has_thumbnail? double()).to be_falsey
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
174
|
describe "render_thumbnail_tag" do
|
175
175
|
let(:document) { double }
|
176
176
|
it "should call the provided thumbnail method" do
|
177
|
-
helper.
|
178
|
-
helper.
|
177
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
|
178
|
+
allow(helper).to receive_messages(:xyz => "some-thumbnail")
|
179
179
|
|
180
|
-
helper.
|
180
|
+
allow(helper).to receive(:link_to_document).with(document, :label => "some-thumbnail")
|
181
181
|
helper.render_thumbnail_tag document
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should create an image tag from the given field" do
|
185
|
-
helper.
|
185
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
|
186
186
|
|
187
|
-
document.
|
188
|
-
document.
|
187
|
+
allow(document).to receive(:has?).with(:xyz).and_return(true)
|
188
|
+
allow(document).to receive(:first).with(:xyz).and_return("http://example.com/some.jpg")
|
189
189
|
|
190
|
-
helper.
|
190
|
+
allow(helper).to receive(:link_to_document).with(document, :label => image_tag("http://example.com/some.jpg"))
|
191
191
|
helper.render_thumbnail_tag document
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should not link to the document if the url options are false" do
|
195
|
-
helper.
|
196
|
-
helper.
|
195
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
|
196
|
+
allow(helper).to receive_messages(:xyz => "some-thumbnail")
|
197
197
|
|
198
198
|
result = helper.render_thumbnail_tag document, {}, false
|
199
199
|
expect(result).to eq "some-thumbnail"
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should not link to the document if the url options have :suppress_link" do
|
203
|
-
helper.
|
204
|
-
helper.
|
203
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
|
204
|
+
allow(helper).to receive_messages(:xyz => "some-thumbnail")
|
205
205
|
|
206
206
|
result = helper.render_thumbnail_tag document, {}, suppress_link: true
|
207
207
|
expect(result).to eq "some-thumbnail"
|
@@ -209,13 +209,13 @@ describe CatalogHelper do
|
|
209
209
|
|
210
210
|
|
211
211
|
it "should return nil if no thumbnail is available" do
|
212
|
-
helper.
|
212
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))
|
213
213
|
expect(helper.render_thumbnail_tag document).to be_nil
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should return nil if no thumbnail is returned from the thumbnail method" do
|
217
|
-
helper.
|
218
|
-
helper.
|
217
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
|
218
|
+
allow(helper).to receive_messages(:xyz => nil)
|
219
219
|
|
220
220
|
expect(helper.render_thumbnail_tag document).to be_nil
|
221
221
|
end
|
@@ -223,17 +223,17 @@ describe CatalogHelper do
|
|
223
223
|
|
224
224
|
describe "thumbnail_url" do
|
225
225
|
it "should pull the configured thumbnail field out of the document" do
|
226
|
-
helper.
|
226
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
|
227
227
|
document = double()
|
228
|
-
document.
|
229
|
-
document.
|
228
|
+
allow(document).to receive(:has?).with(:xyz).and_return(true)
|
229
|
+
allow(document).to receive(:first).with(:xyz).and_return("asdf")
|
230
230
|
expect(helper.thumbnail_url document).to eq("asdf")
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should return nil if the thumbnail field doesn't exist" do
|
234
|
-
helper.
|
234
|
+
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
|
235
235
|
document = double()
|
236
|
-
document.
|
236
|
+
allow(document).to receive(:has?).with(:xyz).and_return(false)
|
237
237
|
expect(helper.thumbnail_url document).to be_nil
|
238
238
|
end
|
239
239
|
end
|
@@ -5,33 +5,33 @@ describe BlacklightConfigurationHelper do
|
|
5
5
|
let(:config_value) { double() }
|
6
6
|
|
7
7
|
before :each do
|
8
|
-
helper.
|
8
|
+
allow(helper).to receive_messages(blacklight_config: blacklight_config)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#index_fields" do
|
12
12
|
it "should pass through the configuration" do
|
13
|
-
blacklight_config.
|
13
|
+
allow(blacklight_config).to receive_messages(index_fields: config_value)
|
14
14
|
expect(helper.index_fields).to eq config_value
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#sort_fields" do
|
19
19
|
it "should convert the sort fields to select-ready values" do
|
20
|
-
blacklight_config.
|
20
|
+
allow(blacklight_config).to receive_messages(sort_fields: { 'a' => double(key: 'a', label: 'a'), 'b' => double(key: 'b', label: 'b'), c: double(key: 'c', if: false) })
|
21
21
|
expect(helper.sort_fields).to eq [['a', 'a'], ['b', 'b']]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#active_sort_fields" do
|
26
26
|
it "should restrict the configured sort fields to only those that should be displayed" do
|
27
|
-
blacklight_config.
|
27
|
+
allow(blacklight_config).to receive_messages(sort_fields: { a: double(if: false, unless: false), b: double(if:true, unless: true) })
|
28
28
|
expect(helper.active_sort_fields).to be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#document_show_fields" do
|
33
33
|
it "should pass through the configuration" do
|
34
|
-
blacklight_config.
|
34
|
+
allow(blacklight_config).to receive_messages(show_fields: config_value)
|
35
35
|
expect(helper.document_show_fields).to eq config_value
|
36
36
|
end
|
37
37
|
end
|
@@ -45,7 +45,7 @@ describe BlacklightConfigurationHelper do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should default to the first configured index view" do
|
48
|
-
blacklight_config.
|
48
|
+
allow(blacklight_config).to receive_messages(view: { a: true, b: true})
|
49
49
|
expect(helper.default_document_index_view_type).to eq :a
|
50
50
|
end
|
51
51
|
end
|
@@ -58,17 +58,17 @@ describe BlacklightConfigurationHelper do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should filter views using :if/:unless configuration" do
|
61
|
-
helper.document_index_views.
|
62
|
-
helper.document_index_views.
|
63
|
-
helper.document_index_views.
|
64
|
-
helper.document_index_views.
|
61
|
+
expect(helper.document_index_views).to have_key :list
|
62
|
+
expect(helper.document_index_views).to_not have_key :abc
|
63
|
+
expect(helper.document_index_views).to_not have_key :def
|
64
|
+
expect(helper.document_index_views).to_not have_key :xyz
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "#has_alternative_views?" do
|
69
69
|
subject { helper.has_alternative_views?}
|
70
70
|
describe "with a single view defined" do
|
71
|
-
it { should
|
71
|
+
it { should be false }
|
72
72
|
end
|
73
73
|
|
74
74
|
describe "with multiple views defined" do
|
@@ -77,13 +77,13 @@ describe BlacklightConfigurationHelper do
|
|
77
77
|
blacklight_config.view.xyz
|
78
78
|
end
|
79
79
|
|
80
|
-
it { should
|
80
|
+
it { should be true }
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe "#spell_check_max" do
|
85
85
|
it "should pass through the configuration" do
|
86
|
-
blacklight_config.
|
86
|
+
allow(blacklight_config).to receive_messages(spell_max: config_value)
|
87
87
|
expect(helper.spell_check_max).to eq config_value
|
88
88
|
end
|
89
89
|
end
|
@@ -91,8 +91,8 @@ describe BlacklightConfigurationHelper do
|
|
91
91
|
describe "#index_field_label" do
|
92
92
|
let(:document) { double }
|
93
93
|
it "should look up the label to display for the given document and field" do
|
94
|
-
helper.
|
95
|
-
helper.
|
94
|
+
allow(helper).to receive(:index_fields).and_return({ "my_field" => double(label: "some label") })
|
95
|
+
allow(helper).to receive(:solr_field_label).with("some label", :"blacklight.search.fields.index.my_field", :"blacklight.search.fields.my_field")
|
96
96
|
helper.index_field_label document, "my_field"
|
97
97
|
end
|
98
98
|
end
|
@@ -100,8 +100,8 @@ describe BlacklightConfigurationHelper do
|
|
100
100
|
describe "#document_show_field_label" do
|
101
101
|
let(:document) { double }
|
102
102
|
it "should look up the label to display for the given document and field" do
|
103
|
-
helper.
|
104
|
-
helper.
|
103
|
+
allow(helper).to receive(:document_show_fields).and_return({ "my_field" => double(label: "some label") })
|
104
|
+
allow(helper).to receive(:solr_field_label).with("some label", :"blacklight.search.fields.show.my_field", :"blacklight.search.fields.my_field")
|
105
105
|
helper.document_show_field_label document, "my_field"
|
106
106
|
end
|
107
107
|
end
|
@@ -109,22 +109,22 @@ describe BlacklightConfigurationHelper do
|
|
109
109
|
describe "#facet_field_label" do
|
110
110
|
let(:document) { double }
|
111
111
|
it "should look up the label to display for the given document and field" do
|
112
|
-
blacklight_config.
|
113
|
-
helper.
|
112
|
+
allow(blacklight_config).to receive(:facet_fields).and_return({ "my_field" => double(label: "some label") })
|
113
|
+
allow(helper).to receive(:solr_field_label).with("some label", :"blacklight.search.fields.facet.my_field", :"blacklight.search.fields.my_field")
|
114
114
|
helper.facet_field_label "my_field"
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
describe "#solr_field_label" do
|
119
119
|
it "should look up the label as an i18n string" do
|
120
|
-
helper.
|
120
|
+
allow(helper).to receive(:t).with(:some_key).and_return "my label"
|
121
121
|
label = helper.solr_field_label :some_key
|
122
122
|
|
123
123
|
expect(label).to eq "my label"
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should pass the provided i18n keys to I18n.t" do
|
127
|
-
helper.
|
127
|
+
allow(helper).to receive(:t).with(:key_a, default: [:key_b, "default text"])
|
128
128
|
|
129
129
|
label = helper.solr_field_label "default text", :key_a, :key_b
|
130
130
|
end
|
@@ -132,31 +132,31 @@ describe BlacklightConfigurationHelper do
|
|
132
132
|
|
133
133
|
describe "#default_per_page" do
|
134
134
|
it "should be the configured default per page" do
|
135
|
-
helper.
|
135
|
+
allow(helper).to receive_messages(blacklight_config: double(default_per_page: 42))
|
136
136
|
expect(helper.default_per_page).to eq 42
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should be the first per-page value if a default isn't set" do
|
140
|
-
helper.
|
140
|
+
allow(helper).to receive_messages(blacklight_config: double(default_per_page: nil, per_page: [11, 22]))
|
141
141
|
expect(helper.default_per_page).to eq 11
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
describe "#default_sort_field" do
|
146
146
|
it "should be the configured default field" do
|
147
|
-
helper.
|
147
|
+
allow(helper).to receive_messages(blacklight_config: double(sort_fields: { a: double(default: nil), b: double(key: 'b', default: true) }))
|
148
148
|
expect(helper.default_sort_field.key).to eq 'b'
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should be the first per-page value if a default isn't set" do
|
152
|
-
helper.
|
152
|
+
allow(helper).to receive_messages(blacklight_config: double(sort_fields: { a: double(key: 'a', default: nil), b: double(key: 'b', default: nil) }))
|
153
153
|
expect(helper.default_sort_field.key).to eq 'a'
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
describe "#per_page_options_for_select" do
|
158
158
|
it "should be the per-page values formatted as options_for_select" do
|
159
|
-
helper.
|
159
|
+
allow(helper).to receive_messages(blacklight_config: double(per_page: [11, 22, 33]))
|
160
160
|
expect(helper.per_page_options_for_select).to include ["11<span class=\"sr-only\"> per page</span>", 11]
|
161
161
|
expect(helper.per_page_options_for_select).to include ["22<span class=\"sr-only\"> per page</span>", 22]
|
162
162
|
expect(helper.per_page_options_for_select).to include ["33<span class=\"sr-only\"> per page</span>", 33]
|
@@ -167,21 +167,21 @@ describe BlacklightConfigurationHelper do
|
|
167
167
|
let(:field_config) { double('field config', if: true, unless: false) }
|
168
168
|
|
169
169
|
before do
|
170
|
-
helper.
|
170
|
+
allow(helper).to receive_messages(document_has_value?: true)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "should be true" do
|
174
|
-
expect(helper.should_render_field?(field_config)).to
|
174
|
+
expect(helper.should_render_field?(field_config)).to be true
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should be false if the :if condition is false" do
|
178
|
-
field_config.
|
179
|
-
expect(helper.should_render_field?(field_config)).to
|
178
|
+
allow(field_config).to receive_messages(if: false)
|
179
|
+
expect(helper.should_render_field?(field_config)).to be false
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should be false if the :unless condition is true" do
|
183
|
-
field_config.
|
184
|
-
expect(helper.should_render_field?(field_config)).to
|
183
|
+
allow(field_config).to receive_messages(unless: true)
|
184
|
+
expect(helper.should_render_field?(field_config)).to be false
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
@@ -192,21 +192,21 @@ describe BlacklightConfigurationHelper do
|
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should execute a helper method" do
|
195
|
-
helper.
|
196
|
-
expect(helper.evaluate_configuration_conditional(:my_helper)).to
|
195
|
+
allow(helper).to receive_messages(:my_helper => true)
|
196
|
+
expect(helper.evaluate_configuration_conditional(:my_helper)).to be true
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should call a helper to determine if it should render a field" do
|
200
200
|
a = double
|
201
|
-
helper.
|
202
|
-
expect(helper.evaluate_configuration_conditional(:my_helper_with_an_arg, a)).to
|
201
|
+
allow(helper).to receive(:my_helper_with_an_arg).with(a).and_return(true)
|
202
|
+
expect(helper.evaluate_configuration_conditional(:my_helper_with_an_arg, a)).to be true
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should evaluate a Proc to determine if it should render a field" do
|
206
206
|
one_arg_lambda = lambda { |context, a| true }
|
207
207
|
two_arg_lambda = lambda { |context, a, b| true }
|
208
|
-
expect(helper.evaluate_configuration_conditional(one_arg_lambda, 1)).to
|
209
|
-
expect(helper.evaluate_configuration_conditional(two_arg_lambda, 1, 2)).to
|
208
|
+
expect(helper.evaluate_configuration_conditional(one_arg_lambda, 1)).to be true
|
209
|
+
expect(helper.evaluate_configuration_conditional(two_arg_lambda, 1, 2)).to be true
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -224,7 +224,7 @@ describe BlacklightConfigurationHelper do
|
|
224
224
|
config.add_search_field 'no_display', :qt => 'something', :include_in_simple_select => false
|
225
225
|
end
|
226
226
|
|
227
|
-
helper.
|
227
|
+
allow(helper).to receive_messages(blacklight_config: @config)
|
228
228
|
end
|
229
229
|
|
230
230
|
it "should return proper options_for_select arguments" do
|
@@ -6,7 +6,7 @@ describe FacetsHelper do
|
|
6
6
|
let(:blacklight_config) { Blacklight::Configuration.new }
|
7
7
|
|
8
8
|
before(:each) do
|
9
|
-
helper.
|
9
|
+
allow(helper).to receive(:blacklight_config).and_return blacklight_config
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "has_facet_values?" do
|
@@ -40,7 +40,7 @@ describe FacetsHelper do
|
|
40
40
|
config.add_facet_field 'lambda_no_show', :show => lambda { |context, config, field| false }
|
41
41
|
end
|
42
42
|
|
43
|
-
helper.
|
43
|
+
allow(helper).to receive_messages(:blacklight_config => @config)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should render facets with items" do
|
@@ -58,14 +58,14 @@ describe FacetsHelper do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should call a helper to determine if it should render a field" do
|
61
|
-
helper.
|
61
|
+
allow(helper).to receive_messages(:my_helper => true)
|
62
62
|
a = double(:items => [1,2], :name=>'helper_show')
|
63
63
|
expect(helper.should_render_facet?(a)).to be true
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should call a helper to determine if it should render a field" do
|
67
67
|
a = double(:items => [1,2], :name=>'helper_with_an_arg_show')
|
68
|
-
helper.
|
68
|
+
allow(helper).to receive(:my_helper_with_an_arg).with(@config.facet_fields['helper_with_an_arg_show'], a).and_return(true)
|
69
69
|
expect(helper.should_render_facet?(a)).to be true
|
70
70
|
end
|
71
71
|
|
@@ -86,7 +86,7 @@ describe FacetsHelper do
|
|
86
86
|
config.add_facet_field 'no_collapse', collapse: false
|
87
87
|
end
|
88
88
|
|
89
|
-
helper.
|
89
|
+
allow(helper).to receive_messages(blacklight_config: @config)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should be collapsed by default" do
|
@@ -109,18 +109,18 @@ describe FacetsHelper do
|
|
109
109
|
it "should retrieve the facet from the response given a string" do
|
110
110
|
facet_config = double(:query => nil)
|
111
111
|
facet_field = double()
|
112
|
-
helper.
|
112
|
+
allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
113
113
|
|
114
114
|
@response = double()
|
115
|
-
@response.
|
115
|
+
allow(@response).to receive(:facet_by_field_name).with('a').and_return(facet_field)
|
116
116
|
|
117
117
|
expect(helper.facet_by_field_name('a')).to eq facet_field
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should also work for facet query fields" do
|
121
121
|
facet_config = double(:query => {})
|
122
|
-
helper.
|
123
|
-
helper.
|
122
|
+
allow(helper).to receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
|
123
|
+
allow(helper).to receive(:create_rsolr_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
|
124
124
|
|
125
125
|
helper.facet_by_field_name 'a_query_facet_field'
|
126
126
|
end
|
@@ -137,7 +137,7 @@ describe FacetsHelper do
|
|
137
137
|
}
|
138
138
|
|
139
139
|
before(:each) do
|
140
|
-
helper.
|
140
|
+
allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
141
141
|
|
142
142
|
@response = double(:facet_queries => {
|
143
143
|
'field:search' => 10,
|
@@ -149,7 +149,7 @@ describe FacetsHelper do
|
|
149
149
|
|
150
150
|
it"should convert the query facets into a double RSolr FacetField" do
|
151
151
|
field = helper.facet_by_field_name('my_query_facet_field')
|
152
|
-
field.
|
152
|
+
expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
153
153
|
|
154
154
|
expect(field.name).to eq'my_query_facet_field'
|
155
155
|
expect(field.items.size).to eq 2
|
@@ -169,14 +169,14 @@ describe FacetsHelper do
|
|
169
169
|
}
|
170
170
|
|
171
171
|
before(:each) do
|
172
|
-
helper.
|
172
|
+
allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
173
173
|
|
174
174
|
@response = double(:facet_pivot => { 'field_a,field_b' => [{:field => 'field_a', :value => 'a', :count => 10, :pivot => [{:field => 'field_b', :value => 'b', :count => 2}]}]})
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should convert the pivot facet into a double RSolr FacetField" do
|
178
178
|
field = helper.facet_by_field_name('my_pivot_facet_field')
|
179
|
-
field.
|
179
|
+
expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
180
180
|
|
181
181
|
expect(field.name).to eq 'my_pivot_facet_field'
|
182
182
|
|
@@ -199,9 +199,9 @@ describe FacetsHelper do
|
|
199
199
|
|
200
200
|
fields = [a,b,empty]
|
201
201
|
|
202
|
-
helper.
|
203
|
-
helper.
|
204
|
-
helper.
|
202
|
+
allow(helper).to receive(:render_facet_limit).with(a, {})
|
203
|
+
allow(helper).to receive(:render_facet_limit).with(b, {})
|
204
|
+
allow(helper).to receive(:render_facet_limit).with(empty, {})
|
205
205
|
|
206
206
|
helper.render_facet_partials fields
|
207
207
|
end
|
@@ -209,10 +209,10 @@ describe FacetsHelper do
|
|
209
209
|
it "should default to the configured facets" do
|
210
210
|
a = double(:items => [1,2])
|
211
211
|
b = double(:items => ['b','c'])
|
212
|
-
helper.
|
212
|
+
allow(helper).to receive(:facet_field_names) { [a,b] }
|
213
213
|
|
214
|
-
helper.
|
215
|
-
helper.
|
214
|
+
allow(helper).to receive(:render_facet_limit).with(a, {})
|
215
|
+
allow(helper).to receive(:render_facet_limit).with(b, {})
|
216
216
|
|
217
217
|
helper.render_facet_partials
|
218
218
|
end
|
@@ -229,13 +229,13 @@ describe FacetsHelper do
|
|
229
229
|
config.add_facet_field 'my_facet_field_with_custom_partial', :partial => 'custom_facet_partial'
|
230
230
|
end
|
231
231
|
|
232
|
-
helper.
|
232
|
+
allow(helper).to receive_messages(:blacklight_config => @config)
|
233
233
|
@response = double()
|
234
234
|
end
|
235
235
|
|
236
236
|
it "should set basic local variables" do
|
237
237
|
@mock_facet = double(:name => 'basic_field', :items => [1,2,3])
|
238
|
-
helper.
|
238
|
+
allow(helper).to receive(:render).with(hash_including(:partial => 'facet_limit',
|
239
239
|
:locals => {
|
240
240
|
:solr_field => 'basic_field',
|
241
241
|
:facet_field => helper.blacklight_config.facet_fields['basic_field'],
|
@@ -246,37 +246,37 @@ describe FacetsHelper do
|
|
246
246
|
|
247
247
|
it "should render a facet _not_ declared in the configuration" do
|
248
248
|
@mock_facet = double(:name => 'asdf', :items => [1,2,3])
|
249
|
-
helper.
|
249
|
+
allow(helper).to receive(:render).with(hash_including(:partial => 'facet_limit'))
|
250
250
|
helper.render_facet_limit(@mock_facet)
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should get the partial name from the configuration" do
|
254
254
|
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
255
|
-
helper.
|
255
|
+
allow(helper).to receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
|
256
256
|
helper.render_facet_limit(@mock_facet)
|
257
257
|
end
|
258
258
|
|
259
259
|
it "should use a partial layout for rendering the facet frame" do
|
260
260
|
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
261
|
-
helper.
|
261
|
+
allow(helper).to receive(:render).with(hash_including(:layout => 'facet_layout'))
|
262
262
|
helper.render_facet_limit(@mock_facet)
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should allow the caller to opt-out of facet layouts" do
|
266
266
|
@mock_facet = double(:name => 'my_facet_field_with_custom_partial', :items => [1,2,3])
|
267
|
-
helper.
|
267
|
+
allow(helper).to receive(:render).with(hash_including(:layout => nil))
|
268
268
|
helper.render_facet_limit(@mock_facet, :layout => nil)
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should render the facet_pivot partial for pivot facets" do
|
272
272
|
@mock_facet = double(:name => 'pivot_facet_field', :items => [1,2,3])
|
273
|
-
helper.
|
273
|
+
allow(helper).to receive(:render).with(hash_including(:partial => 'facet_pivot'))
|
274
274
|
helper.render_facet_limit(@mock_facet)
|
275
275
|
end
|
276
276
|
|
277
277
|
it "should let you override the rendered partial for pivot facets" do
|
278
278
|
@mock_facet = double(:name => 'my_pivot_facet_field_with_custom_partial', :items => [1,2,3])
|
279
|
-
helper.
|
279
|
+
allow(helper).to receive(:render).with(hash_including(:partial => 'custom_facet_partial'))
|
280
280
|
helper.render_facet_limit(@mock_facet)
|
281
281
|
end
|
282
282
|
end
|
@@ -312,7 +312,7 @@ describe FacetsHelper do
|
|
312
312
|
|
313
313
|
describe "facet_field_in_params?" do
|
314
314
|
it "should check if the facet field is selected in the user params" do
|
315
|
-
helper.
|
315
|
+
allow(helper).to receive_messages(:params => { :f => { "some-field" => ["x"]}})
|
316
316
|
expect(helper.facet_field_in_params?("some-field")).to be_truthy
|
317
317
|
expect(helper.facet_field_in_params?("other-field")).to_not be true
|
318
318
|
end
|
@@ -325,9 +325,9 @@ describe FacetsHelper do
|
|
325
325
|
describe "render_facet_value" do
|
326
326
|
let (:item) { double(:value => 'A', :hits => 10) }
|
327
327
|
before do
|
328
|
-
helper.
|
329
|
-
helper.
|
330
|
-
helper.
|
328
|
+
allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false))
|
329
|
+
allow(helper).to receive(:facet_display_value).and_return('Z')
|
330
|
+
allow(helper).to receive(:add_facet_params_and_redirect).and_return({controller:'catalog'})
|
331
331
|
|
332
332
|
allow(helper).to receive(:search_action_path) do |*args|
|
333
333
|
catalog_index_path *args
|
@@ -352,30 +352,30 @@ describe FacetsHelper do
|
|
352
352
|
|
353
353
|
describe "#facet_display_value" do
|
354
354
|
it "should just be the facet value for an ordinary facet" do
|
355
|
-
helper.
|
355
|
+
allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil))
|
356
356
|
expect(helper.facet_display_value('simple_field', 'asdf')).to eq 'asdf'
|
357
357
|
end
|
358
358
|
|
359
359
|
it "should allow you to pass in a :helper_method argument to the configuration" do
|
360
|
-
helper.
|
360
|
+
allow(helper).to receive(:facet_configuration_for_field).with('helper_field').and_return(double(:query => nil, :date => nil, :helper_method => :my_facet_value_renderer))
|
361
361
|
|
362
|
-
helper.
|
362
|
+
allow(helper).to receive(:my_facet_value_renderer).with('qwerty').and_return('abc')
|
363
363
|
|
364
364
|
expect(helper.facet_display_value('helper_field', 'qwerty')).to eq 'abc'
|
365
365
|
end
|
366
366
|
|
367
367
|
it "should extract the configuration label for a query facet" do
|
368
|
-
helper.
|
368
|
+
allow(helper).to receive(:facet_configuration_for_field).with('query_facet').and_return(double(:query => { 'query_key' => { :label => 'XYZ'}}, :date => nil, :helper_method => nil))
|
369
369
|
expect(helper.facet_display_value('query_facet', 'query_key')).to eq 'XYZ'
|
370
370
|
end
|
371
371
|
|
372
372
|
it "should localize the label for date-type facets" do
|
373
|
-
helper.
|
373
|
+
allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => true, :query => nil, :helper_method => nil))
|
374
374
|
expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq 'Sun, 01 Jan 2012 00:00:00 +0000'
|
375
375
|
end
|
376
376
|
|
377
377
|
it "should localize the label for date-type facets with the supplied localization options" do
|
378
|
-
helper.
|
378
|
+
allow(helper).to receive(:facet_configuration_for_field).with('date_facet').and_return(double('date' => { :format => :short }, :query => nil, :helper_method => nil))
|
379
379
|
expect(helper.facet_display_value('date_facet', '2012-01-01')).to eq '01 Jan 00:00'
|
380
380
|
end
|
381
381
|
end
|