blacklight 5.19.2 → 6.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/.hound.yml +2 -0
- data/.jshintrc +67 -0
- data/.rubocop_hound.yml +4 -0
- data/.travis.yml +11 -8
- data/Gemfile +11 -21
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +1 -0
- data/app/assets/javascripts/blacklight/core.js +5 -19
- data/app/assets/javascripts/blacklight/facet_load.js +23 -0
- data/app/assets/stylesheets/blacklight/_balanced_list.scss +18 -0
- data/app/assets/stylesheets/blacklight/_blacklight_base.scss +5 -1
- data/app/assets/stylesheets/blacklight/_bookmark.scss +14 -6
- data/app/assets/stylesheets/blacklight/_constraints.scss +52 -0
- data/app/assets/stylesheets/blacklight/_controls.scss +61 -0
- data/app/assets/stylesheets/blacklight/_facets.scss +31 -4
- data/app/assets/stylesheets/blacklight/_header.scss +17 -3
- data/app/assets/stylesheets/blacklight/_pagination.scss +21 -0
- data/app/assets/stylesheets/blacklight/_search_results.scss +28 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +0 -3
- data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
- data/app/controllers/concerns/blacklight/catalog.rb +3 -45
- data/app/controllers/concerns/blacklight/controller.rb +29 -18
- data/app/controllers/concerns/blacklight/default_component_configuration.rb +4 -3
- data/app/controllers/concerns/blacklight/facet.rb +1 -0
- data/app/controllers/concerns/blacklight/request_builders.rb +4 -107
- data/app/controllers/concerns/blacklight/search_fields.rb +1 -1
- data/app/controllers/concerns/blacklight/search_helper.rb +8 -160
- data/app/controllers/saved_searches_controller.rb +1 -1
- data/app/controllers/search_history_controller.rb +18 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +17 -85
- data/app/helpers/blacklight/catalog_helper_behavior.rb +4 -48
- data/app/helpers/blacklight/component_helper_behavior.rb +9 -2
- data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -43
- data/app/helpers/blacklight/facets_helper_behavior.rb +10 -6
- data/app/helpers/blacklight/layout_helper_behavior.rb +0 -8
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +9 -10
- data/app/helpers/blacklight/render_partials_helper.rb +1 -3
- data/app/helpers/blacklight/url_helper_behavior.rb +15 -187
- data/{lib → app/models}/blacklight/abstract_repository.rb +0 -15
- data/{lib → app/models}/blacklight/configuration.rb +22 -59
- data/app/models/blacklight/configuration/context.rb +47 -0
- data/{lib → app/models}/blacklight/configuration/facet_field.rb +1 -0
- data/{lib → app/models}/blacklight/configuration/field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/fields.rb +2 -6
- data/{lib → app/models}/blacklight/configuration/search_field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/solr_field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/sort_field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/tool_config.rb +0 -0
- data/app/models/blacklight/configuration/view_config.rb +9 -0
- data/app/models/blacklight/facet_paginator.rb +14 -28
- data/{lib → app/models}/blacklight/search_builder.rb +16 -24
- data/app/models/blacklight/solr/facet_paginator.rb +6 -2
- data/{lib → app/models}/blacklight/solr/repository.rb +0 -21
- data/{lib → app/models}/blacklight/solr/request.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response.rb +9 -8
- data/{lib → app/models}/blacklight/solr/response/facets.rb +37 -29
- data/{lib → app/models}/blacklight/solr/response/group.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/group_response.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/more_like_this.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/pagination_methods.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/response.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/spelling.rb +2 -1
- data/{lib → app/models}/blacklight/solr/search_builder.rb +0 -0
- data/app/models/concerns/blacklight/document.rb +11 -27
- data/app/models/concerns/blacklight/document/active_model_shim.rb +8 -0
- data/app/models/concerns/blacklight/solr/document.rb +8 -3
- data/{lib → app/models/concerns}/blacklight/solr/search_builder_behavior.rb +21 -33
- data/app/models/concerns/blacklight/user.rb +0 -9
- data/app/models/record_mailer.rb +0 -1
- data/app/presenters/blacklight/document_presenter.rb +23 -13
- data/app/views/blacklight/nav/_saved_searches.html.erb +1 -1
- data/app/views/blacklight/nav/_search_history.html.erb +1 -1
- data/app/views/bookmarks/_tools.html.erb +1 -2
- data/app/views/bookmarks/index.html.erb +2 -2
- data/app/views/catalog/_document_default.atom.builder +4 -2
- data/app/views/catalog/_facet_index_navigation.html.erb +9 -0
- data/app/views/catalog/_facet_layout.html.erb +2 -3
- data/app/views/catalog/_facet_pagination.html.erb +19 -21
- data/app/views/catalog/_facets.html.erb +2 -3
- data/app/views/catalog/_home_text.html.erb +2 -3
- data/app/views/catalog/_index_header_default.html.erb +2 -2
- data/app/views/catalog/_per_page_widget.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +21 -18
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/app/views/catalog/_zero_results.html.erb +2 -2
- data/app/views/catalog/facet.html.erb +3 -0
- data/app/views/catalog/index.atom.builder +1 -1
- data/app/views/layouts/blacklight.html.erb +2 -2
- data/app/views/saved_searches/index.html.erb +6 -7
- data/app/views/search_history/index.html.erb +5 -5
- data/app/views/shared/_header_navbar.html.erb +2 -2
- data/blacklight.gemspec +5 -5
- data/config/locales/blacklight.de.yml +1 -4
- data/config/locales/blacklight.en.yml +2 -7
- data/config/locales/blacklight.es.yml +1 -4
- data/config/locales/blacklight.fr.yml +1 -4
- data/config/locales/blacklight.it.yml +1 -4
- data/config/locales/blacklight.pt-BR.yml +1 -4
- data/config/routes.rb +9 -0
- data/db/migrate/20140202020201_create_searches.rb +1 -1
- data/db/migrate/20140202020202_create_bookmarks.rb +1 -1
- data/lib/blacklight.rb +5 -82
- data/lib/blacklight/engine.rb +0 -5
- data/lib/blacklight/parameters.rb +13 -0
- data/lib/blacklight/path.rb +143 -0
- data/lib/blacklight/routes.rb +3 -134
- data/lib/blacklight/routes/exportable.rb +25 -0
- data/lib/blacklight/routes/searchable.rb +20 -0
- data/lib/blacklight/solr.rb +1 -9
- data/lib/blacklight/utils.rb +2 -44
- data/lib/generators/blacklight/controller_generator.rb +7 -4
- data/lib/generators/blacklight/install_generator.rb +16 -9
- data/lib/generators/blacklight/models_generator.rb +18 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +85 -91
- data/lib/generators/blacklight/test_support_generator.rb +22 -15
- data/solr/conf/_rest_managed.json +3 -0
- data/solr/conf/admin-extra.html +31 -0
- data/solr/conf/elevate.xml +36 -0
- data/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/conf/protwords.txt +21 -0
- data/solr/conf/schema.xml +621 -0
- data/solr/conf/scripts.conf +24 -0
- data/solr/conf/solrconfig.xml +391 -0
- data/solr/conf/spellings.txt +2 -0
- data/solr/conf/stopwords.txt +58 -0
- data/solr/conf/stopwords_en.txt +58 -0
- data/solr/conf/synonyms.txt +31 -0
- data/solr/conf/xslt/example.xsl +132 -0
- data/solr/conf/xslt/example_atom.xsl +67 -0
- data/solr/conf/xslt/example_rss.xsl +66 -0
- data/solr/conf/xslt/luke.xsl +337 -0
- data/solr/sample_solr_documents.yml +1 -0
- data/spec/controllers/blacklight/base_spec.rb +17 -0
- data/spec/controllers/blacklight/search_helper_spec.rb +25 -297
- data/spec/controllers/catalog_controller_spec.rb +7 -6
- data/spec/controllers/saved_searches_controller_spec.rb +1 -0
- data/spec/controllers/search_history_controller_spec.rb +1 -0
- data/spec/features/alternate_controller_spec.rb +10 -10
- data/spec/features/bookmarks_spec.rb +8 -22
- data/spec/features/facets_spec.rb +27 -7
- data/spec/features/record_view_spec.rb +4 -13
- data/spec/features/search_formats_spec.rb +1 -26
- data/spec/features/sitelinks_search_box.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +8 -38
- data/spec/helpers/catalog_helper_spec.rb +0 -8
- data/spec/helpers/configuration_helper_spec.rb +0 -25
- data/spec/helpers/facets_helper_spec.rb +12 -11
- data/spec/helpers/hash_as_hidden_fields_spec.rb +7 -7
- data/spec/helpers/layout_helper_spec.rb +0 -7
- data/spec/helpers/render_constraints_helper_spec.rb +4 -2
- data/spec/helpers/url_helper_spec.rb +13 -254
- data/spec/lib/blacklight/parameters_spec.rb +22 -0
- data/spec/lib/blacklight/path_spec.rb +254 -0
- data/spec/lib/blacklight_spec.rb +6 -2
- data/spec/models/blacklight/configuration/context_spec.rb +33 -0
- data/spec/models/blacklight/document/active_model_shim_spec.rb +33 -0
- data/spec/models/blacklight/document_spec.rb +29 -1
- data/spec/models/blacklight/facet_paginator_spec.rb +14 -13
- data/spec/models/blacklight/search_builder_spec.rb +17 -23
- data/spec/models/blacklight/solr/facet_paginator_spec.rb +11 -1
- data/spec/models/blacklight/solr/response/facets_spec.rb +19 -25
- data/spec/models/blacklight/solr/response/group_response_spec.rb +5 -5
- data/spec/models/blacklight/solr/response_spec.rb +0 -11
- data/spec/models/blacklight/solr/search_builder_spec.rb +49 -57
- data/spec/presenters/document_presenter_spec.rb +15 -42
- data/spec/routing/catalog_routing_spec.rb +7 -11
- data/spec/spec_helper.rb +4 -42
- data/spec/support/controller_level_helpers.rb +17 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -2
- data/spec/views/_user_util_links.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +40 -0
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facets.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
- data/tasks/blacklight.rake +25 -30
- metadata +93 -71
- data/app/assets/stylesheets/blacklight/_catalog.scss +0 -229
- data/app/controllers/concerns/blacklight/search_history.rb +0 -31
- data/app/views/catalog/_refworks_form.html.erb +0 -6
- data/lib/blacklight/configuration/view_config.rb +0 -71
- data/lib/blacklight/rails/routes.rb +0 -29
- data/lib/blacklight/solr_helper.rb +0 -9
- data/lib/generators/blacklight/templates/config/initializers/blacklight_initializer.rb +0 -9
- data/spec/helpers/component_helper_spec.rb +0 -19
- data/spec/lib/blacklight/routes_spec.rb +0 -25
- data/spec/lib/blacklight/solr_helper_spec.rb +0 -12
- data/spec/routing/routes_spec.rb +0 -20
- data/spec/views/catalog/_document_action.html.erb_spec.rb +0 -21
@@ -226,14 +226,6 @@ describe CatalogHelper do
|
|
226
226
|
|
227
227
|
expect(helper.render_thumbnail_tag document).to be_nil
|
228
228
|
end
|
229
|
-
|
230
|
-
it "should return nil if no thumbnail is in the document" do
|
231
|
-
allow(helper).to receive_messages(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
|
232
|
-
|
233
|
-
allow(document).to receive(:has?).with(:xyz).and_return(false)
|
234
|
-
|
235
|
-
expect(helper.render_thumbnail_tag document).to be_nil
|
236
|
-
end
|
237
229
|
end
|
238
230
|
|
239
231
|
describe "thumbnail_url" do
|
@@ -222,32 +222,7 @@ describe BlacklightConfigurationHelper do
|
|
222
222
|
expect(helper.should_render_field?(field_config)).to be false
|
223
223
|
end
|
224
224
|
end
|
225
|
-
|
226
|
-
describe "#evaluate_configuration_conditional" do
|
227
|
-
it "should pass through regular values" do
|
228
|
-
val = double
|
229
|
-
expect(helper.evaluate_configuration_conditional(val)).to eq val
|
230
|
-
end
|
231
225
|
|
232
|
-
it "should execute a helper method" do
|
233
|
-
allow(helper).to receive_messages(:my_helper => true)
|
234
|
-
expect(helper.evaluate_configuration_conditional(:my_helper)).to be true
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should call a helper to determine if it should render a field" do
|
238
|
-
a = double
|
239
|
-
allow(helper).to receive(:my_helper_with_an_arg).with(a).and_return(true)
|
240
|
-
expect(helper.evaluate_configuration_conditional(:my_helper_with_an_arg, a)).to be true
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should evaluate a Proc to determine if it should render a field" do
|
244
|
-
one_arg_lambda = lambda { |context, a| true }
|
245
|
-
two_arg_lambda = lambda { |context, a, b| true }
|
246
|
-
expect(helper.evaluate_configuration_conditional(one_arg_lambda, 1)).to be true
|
247
|
-
expect(helper.evaluate_configuration_conditional(two_arg_lambda, 1, 2)).to be true
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
226
|
describe "#search_field_options_for_select" do
|
252
227
|
|
253
228
|
before do
|
@@ -8,7 +8,7 @@ describe FacetsHelper do
|
|
8
8
|
before(:each) do
|
9
9
|
allow(helper).to receive(:blacklight_config).and_return blacklight_config
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe "has_facet_values?" do
|
13
13
|
it "should be true if there are any facets to display" do
|
14
14
|
|
@@ -47,8 +47,8 @@ describe FacetsHelper do
|
|
47
47
|
@config = Blacklight::Configuration.new do |config|
|
48
48
|
config.add_facet_field 'basic_field'
|
49
49
|
config.add_facet_field 'no_show', :show => false
|
50
|
-
config.add_facet_field 'helper_show', :show => :
|
51
|
-
config.add_facet_field 'helper_with_an_arg_show', :show => :
|
50
|
+
config.add_facet_field 'helper_show', :show => :my_custom_check
|
51
|
+
config.add_facet_field 'helper_with_an_arg_show', :show => :my_custom_check_with_an_arg
|
52
52
|
config.add_facet_field 'lambda_show', :show => lambda { |context, config, field| true }
|
53
53
|
config.add_facet_field 'lambda_no_show', :show => lambda { |context, config, field| false }
|
54
54
|
end
|
@@ -71,14 +71,14 @@ describe FacetsHelper do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should call a helper to determine if it should render a field" do
|
74
|
-
allow(
|
74
|
+
allow(controller).to receive_messages(:my_custom_check => true)
|
75
75
|
a = double(:items => [1,2], :name=>'helper_show')
|
76
76
|
expect(helper.should_render_facet?(a)).to be true
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should call a helper to determine if it should render a field" do
|
80
80
|
a = double(:items => [1,2], :name=>'helper_with_an_arg_show')
|
81
|
-
allow(
|
81
|
+
allow(controller).to receive(:my_custom_check_with_an_arg).with(@config.facet_fields['helper_with_an_arg_show'], a).and_return(true)
|
82
82
|
expect(helper.should_render_facet?(a)).to be true
|
83
83
|
end
|
84
84
|
|
@@ -230,7 +230,7 @@ describe FacetsHelper do
|
|
230
230
|
subject { helper.render_facet_limit_list(paginator, 'type_solr_field') }
|
231
231
|
before do
|
232
232
|
allow(helper).to receive(:search_action_path) do |*args|
|
233
|
-
|
233
|
+
search_catalog_path *args
|
234
234
|
end
|
235
235
|
end
|
236
236
|
it "should draw a list of elements" do
|
@@ -300,19 +300,20 @@ describe FacetsHelper do
|
|
300
300
|
end
|
301
301
|
|
302
302
|
describe "render_facet_value" do
|
303
|
-
let
|
303
|
+
let(:item) { double(:value => 'A', :hits => 10) }
|
304
|
+
let(:blacklight_path) { double(add_facet_params_and_redirect: { controller: 'catalog' }) }
|
304
305
|
before do
|
305
306
|
allow(helper).to receive(:facet_configuration_for_field).with('simple_field').and_return(double(:query => nil, :date => nil, :helper_method => nil, :single => false, :url_method => nil))
|
306
307
|
allow(helper).to receive(:facet_display_value).and_return('Z')
|
307
|
-
allow(helper).to receive(:
|
308
|
-
|
308
|
+
allow(helper).to receive(:blacklight_path).and_return(blacklight_path)
|
309
309
|
allow(helper).to receive(:search_action_path) do |*args|
|
310
|
-
|
310
|
+
search_catalog_path *args
|
311
311
|
end
|
312
312
|
end
|
313
313
|
describe "simple case" do
|
314
314
|
let(:expected_html) { "<span class=\"facet-label\"><a class=\"facet_select\" href=\"/catalog\">Z</a></span><span class=\"facet-count\">10</span>" }
|
315
|
-
|
315
|
+
|
316
|
+
it "uses facet_display_value" do
|
316
317
|
result = helper.render_facet_value('simple_field', item)
|
317
318
|
expect(result).to be_equivalent_to(expected_html).respecting_element_order
|
318
319
|
end
|
@@ -10,13 +10,13 @@ describe HashAsHiddenFieldsHelper do
|
|
10
10
|
|
11
11
|
generated = render_hash_as_hidden_fields(@hash)
|
12
12
|
|
13
|
-
expect(generated).to have_selector("input[type='hidden'][name='q'][value='query']"
|
14
|
-
expect(generated).to have_selector("input[type='hidden'][name='per_page'][value='10']"
|
15
|
-
expect(generated).to have_selector("input[type='hidden'][name='page'][value='5']"
|
16
|
-
expect(generated).to have_selector("input[type='hidden'][name='extra_arbitrary_key'][value='arbitrary_value']"
|
17
|
-
expect(generated).to have_selector("input[type='hidden'][name='f[field2][]'][value='z']"
|
18
|
-
expect(generated).to have_selector("input[type='hidden'][name='f[field1][]'][value='a']"
|
19
|
-
expect(generated).to have_selector("input[type='hidden'][name='f[field1][]'][value='b']"
|
13
|
+
expect(generated).to have_selector("input[type='hidden'][name='q'][value='query']")
|
14
|
+
expect(generated).to have_selector("input[type='hidden'][name='per_page'][value='10']")
|
15
|
+
expect(generated).to have_selector("input[type='hidden'][name='page'][value='5']")
|
16
|
+
expect(generated).to have_selector("input[type='hidden'][name='extra_arbitrary_key'][value='arbitrary_value']")
|
17
|
+
expect(generated).to have_selector("input[type='hidden'][name='f[field2][]'][value='z']")
|
18
|
+
expect(generated).to have_selector("input[type='hidden'][name='f[field1][]'][value='a']")
|
19
|
+
expect(generated).to have_selector("input[type='hidden'][name='f[field1][]'][value='b']")
|
20
20
|
|
21
21
|
end
|
22
22
|
|
@@ -28,11 +28,4 @@ describe LayoutHelper do
|
|
28
28
|
expect(helper.sidebar_classes).to eq 'col-md-3 col-sm-4'
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
describe '#container_classes' do
|
33
|
-
it 'returns a string of classe(s)' do
|
34
|
-
expect(helper.container_classes).to be_an String
|
35
|
-
expect(helper.container_classes).to eq 'container'
|
36
|
-
end
|
37
|
-
end
|
38
31
|
end
|
@@ -12,7 +12,7 @@ describe RenderConstraintsHelper do
|
|
12
12
|
# the helper methods below infer paths from the current route
|
13
13
|
controller.request.path_parameters[:controller] = 'catalog'
|
14
14
|
allow(helper).to receive(:search_action_path) do |*args|
|
15
|
-
|
15
|
+
search_catalog_path *args
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -32,7 +32,9 @@ describe RenderConstraintsHelper do
|
|
32
32
|
allow(helper).to receive(:blacklight_config).and_return(config)
|
33
33
|
expect(helper).to receive(:facet_field_label).with('type').and_return("Item Type")
|
34
34
|
end
|
35
|
-
subject { helper.render_filter_element('type', ['journal'],
|
35
|
+
subject { helper.render_filter_element('type', ['journal'], path) }
|
36
|
+
|
37
|
+
let(:path) { Blacklight::Path.new({:q=>'biz'}, config) }
|
36
38
|
|
37
39
|
it "should have a link relative to the current url" do
|
38
40
|
expect(subject).to have_link "Remove constraint Item Type: journal", href: "/catalog?q=biz"
|
@@ -11,7 +11,7 @@ describe BlacklightUrlHelper do
|
|
11
11
|
|
12
12
|
before do
|
13
13
|
allow(helper).to receive(:search_action_path) do |*args|
|
14
|
-
|
14
|
+
search_catalog_url *args
|
15
15
|
end
|
16
16
|
|
17
17
|
allow(helper).to receive_messages(blacklight_config: blacklight_config)
|
@@ -26,6 +26,7 @@ describe BlacklightUrlHelper do
|
|
26
26
|
before do
|
27
27
|
allow(helper).to receive_messages(controller: controller_class)
|
28
28
|
allow(helper).to receive_messages(controller_name: controller_class.controller_name)
|
29
|
+
allow(helper).to receive_messages(params: {})
|
29
30
|
end
|
30
31
|
|
31
32
|
it "should be a polymorphic routing-ready object" do
|
@@ -49,6 +50,7 @@ describe BlacklightUrlHelper do
|
|
49
50
|
let(:controller_class) { ::AlternateController.new }
|
50
51
|
before do
|
51
52
|
helper.blacklight_config.show.route = { controller: :current }
|
53
|
+
allow(helper).to receive(:params).and_return(controller: 'alternate')
|
52
54
|
end
|
53
55
|
it "should support the :current controller configuration" do
|
54
56
|
expect(helper.url_for_document(doc)).to eq({controller: 'alternate', action: :show, id: doc})
|
@@ -129,13 +131,6 @@ describe BlacklightUrlHelper do
|
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
132
|
-
describe "link_to_previous_document" do
|
133
|
-
context "when the argument is nil" do
|
134
|
-
subject { helper.link_to_previous_document(nil) }
|
135
|
-
it { is_expected.to eq '<span class="previous">« Previous</span>' }
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
134
|
describe "link_to_query" do
|
140
135
|
it "should build a link tag to catalog using query string (no other params)" do
|
141
136
|
query = "brilliant"
|
@@ -166,94 +161,17 @@ describe BlacklightUrlHelper do
|
|
166
161
|
end
|
167
162
|
end
|
168
163
|
|
169
|
-
describe "sanitize_search_params" do
|
170
|
-
it "should strip nil values" do
|
171
|
-
result = helper.sanitize_search_params(:a => nil, :b => 1)
|
172
|
-
expect(result).to_not have_key(:a)
|
173
|
-
expect(result[:b]).to eq 1
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should remove blacklisted keys" do
|
177
|
-
result = helper.sanitize_search_params(:action => true, :controller => true, :id => true, :commit => true, :utf8 => true)
|
178
|
-
expect(result).to be_empty
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "params_for_search" do
|
183
|
-
before do
|
184
|
-
allow(helper).to receive_messages(params: { 'default' => 'params'})
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should default to using the controller's params" do
|
188
|
-
result = helper.params_for_search
|
189
|
-
expect(result).to eq({ 'default' => 'params' })
|
190
|
-
expect(params.object_id).to_not eq result.object_id
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should let you pass in params to merge into the controller's params" do
|
194
|
-
source_params = { :q => 'query'}
|
195
|
-
result = helper.params_for_search( source_params )
|
196
|
-
expect(result).to include(:q => 'query', 'default' => 'params')
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should not return blacklisted elements" do
|
200
|
-
source_params = { :action => 'action', :controller => 'controller', :id => "id", :commit => 'commit'}
|
201
|
-
result = helper.params_for_search(source_params)
|
202
|
-
expect(result.keys).to_not include(:action, :controller, :commit, :id)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should adjust the current page if the per_page changes" do
|
206
|
-
source_params = { :per_page => 20, :page => 5}
|
207
|
-
result = helper.params_for_search(source_params, :per_page => 100)
|
208
|
-
expect(result[:page]).to eq 1
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should not adjust the current page if the per_page is the same as it always was" do
|
212
|
-
source_params = { :per_page => 20, :page => 5}
|
213
|
-
result = helper.params_for_search(source_params, :per_page => 20)
|
214
|
-
expect(result[:page]).to eq 5
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should adjust the current page if the sort changes" do
|
218
|
-
source_params = { :sort => 'field_a', :page => 5}
|
219
|
-
result = helper.params_for_search(source_params, :sort => 'field_b')
|
220
|
-
expect(result[:page]).to eq 1
|
221
|
-
end
|
222
|
-
|
223
|
-
it "should not adjust the current page if the sort is the same as it always was" do
|
224
|
-
source_params = { :sort => 'field_a', :page => 5}
|
225
|
-
result = helper.params_for_search(source_params, :sort => 'field_a')
|
226
|
-
expect(result[:page]).to eq 5
|
227
|
-
end
|
228
|
-
|
229
|
-
describe "params_for_search with a block" do
|
230
|
-
it "should evalute the block and allow it to add or remove keys" do
|
231
|
-
result = helper.params_for_search({:a => 1, :b => 2}, :c => 3) do |params|
|
232
|
-
params.except! :a, :b
|
233
|
-
params[:d] = 'd'
|
234
|
-
end
|
235
|
-
|
236
|
-
expect(result.keys).to_not include(:a, :b)
|
237
|
-
expect(result[:c]).to eq 3
|
238
|
-
expect(result[:d]).to eq 'd'
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
|
246
164
|
describe "start_over_path" do
|
247
165
|
it 'should be the catalog path with the current view type' do
|
248
166
|
allow(blacklight_config).to receive(:view) { { list: nil, abc: nil} }
|
249
167
|
allow(helper).to receive_messages(:blacklight_config => blacklight_config)
|
250
|
-
expect(helper.start_over_path(:view => 'abc')).to eq
|
168
|
+
expect(helper.start_over_path(:view => 'abc')).to eq search_catalog_url(:view => 'abc')
|
251
169
|
end
|
252
170
|
|
253
171
|
it 'should not include the current view type if it is the default' do
|
254
172
|
allow(blacklight_config).to receive(:view) { { list: nil, asdf: nil} }
|
255
173
|
allow(helper).to receive_messages(:blacklight_config => blacklight_config)
|
256
|
-
expect(helper.start_over_path(:view => 'list')).to eq
|
174
|
+
expect(helper.start_over_path(:view => 'list')).to eq search_catalog_url
|
257
175
|
end
|
258
176
|
end
|
259
177
|
|
@@ -298,7 +216,10 @@ describe BlacklightUrlHelper do
|
|
298
216
|
it "should convert the counter parameter into a data- attribute" do
|
299
217
|
data = {'id'=>'123456','title_display'=>['654321']}
|
300
218
|
@document = SolrDocument.new(data)
|
301
|
-
|
219
|
+
|
220
|
+
allow(helper).to receive(:track_test_path).with(hash_including(id: '123456', counter: 5)).and_return('tracking url')
|
221
|
+
|
222
|
+
expect(helper.link_to_document(@document, :title_display, counter: 5)).to include 'data-context-href="tracking url"'
|
302
223
|
end
|
303
224
|
|
304
225
|
it "should merge the data- attributes from the options with the counter params" do
|
@@ -335,170 +256,6 @@ describe BlacklightUrlHelper do
|
|
335
256
|
end
|
336
257
|
end
|
337
258
|
|
338
|
-
describe "add_facet_params" do
|
339
|
-
before do
|
340
|
-
@params_no_existing_facet = {:q => "query", :search_field => "search_field", :per_page => "50"}
|
341
|
-
@params_existing_facets = {:q => "query", :search_field => "search_field", :per_page => "50", :f => {"facet_field_1" => ["value1"], "facet_field_2" => ["value2", "value2a"]}}
|
342
|
-
end
|
343
|
-
|
344
|
-
it "should add facet value for no pre-existing facets" do
|
345
|
-
allow(helper).to receive(:params).and_return(@params_no_existing_facet)
|
346
|
-
|
347
|
-
result_params = helper.add_facet_params("facet_field", "facet_value")
|
348
|
-
expect(result_params[:f]).to be_a_kind_of(Hash)
|
349
|
-
expect(result_params[:f]["facet_field"]).to be_a_kind_of(Array)
|
350
|
-
expect(result_params[:f]["facet_field"]).to eq ["facet_value"]
|
351
|
-
end
|
352
|
-
|
353
|
-
it "should use the facet's key in the url" do
|
354
|
-
allow(helper).to receive(:facet_configuration_for_field).with('some_field').and_return(double(single: true, field: "a_solr_field", key: "some_key"))
|
355
|
-
|
356
|
-
result_params = helper.add_facet_params('some_field', 'my_value', {})
|
357
|
-
|
358
|
-
expect(result_params[:f]['some_key']).to have(1).item
|
359
|
-
expect(result_params[:f]['some_key'].first).to eq 'my_value'
|
360
|
-
end
|
361
|
-
|
362
|
-
|
363
|
-
it "should add a facet param to existing facet constraints" do
|
364
|
-
allow(helper).to receive(:params).and_return(@params_existing_facets)
|
365
|
-
|
366
|
-
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
|
367
|
-
|
368
|
-
expect(result_params[:f]).to be_a_kind_of(Hash)
|
369
|
-
|
370
|
-
@params_existing_facets[:f].each_pair do |facet_field, value_list|
|
371
|
-
expect(result_params[:f][facet_field]).to be_a_kind_of(Array)
|
372
|
-
|
373
|
-
if facet_field == 'facet_field_2'
|
374
|
-
expect(result_params[:f][facet_field]).to eq (@params_existing_facets[:f][facet_field] | ["new_facet_value"])
|
375
|
-
else
|
376
|
-
expect(result_params[:f][facet_field]).to eq @params_existing_facets[:f][facet_field]
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
it "should leave non-facet params alone" do
|
381
|
-
[@params_existing_facets, @params_no_existing_facet].each do |params|
|
382
|
-
allow(helper).to receive(:params).and_return(params)
|
383
|
-
|
384
|
-
result_params = helper.add_facet_params("facet_field_2", "new_facet_value")
|
385
|
-
|
386
|
-
params.each_pair do |key, value|
|
387
|
-
next if key == :f
|
388
|
-
expect(result_params[key]).to eq params[key]
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should replace facets for facets configured as single" do
|
394
|
-
allow(helper).to receive(:facet_configuration_for_field).with('single_value_facet_field').and_return(double(single: true, key: "single_value_facet_field"))
|
395
|
-
params = { :f => { 'single_value_facet_field' => 'other_value'}}
|
396
|
-
allow(helper).to receive(:params).and_return params
|
397
|
-
|
398
|
-
result_params = helper.add_facet_params('single_value_facet_field', 'my_value')
|
399
|
-
|
400
|
-
|
401
|
-
expect(result_params[:f]['single_value_facet_field']).to have(1).item
|
402
|
-
expect(result_params[:f]['single_value_facet_field'].first).to eq 'my_value'
|
403
|
-
end
|
404
|
-
|
405
|
-
it "should accept a FacetItem instead of a plain facet value" do
|
406
|
-
|
407
|
-
result_params = helper.add_facet_params('facet_field_1', double(:value => 123))
|
408
|
-
|
409
|
-
expect(result_params[:f]['facet_field_1']).to include(123)
|
410
|
-
end
|
411
|
-
|
412
|
-
it "should defer to the field set on a FacetItem" do
|
413
|
-
|
414
|
-
result_params = helper.add_facet_params('facet_field_1', double(:field => 'facet_field_2', :value => 123))
|
415
|
-
|
416
|
-
expect(result_params[:f]['facet_field_1']).to be_blank
|
417
|
-
expect(result_params[:f]['facet_field_2']).to include(123)
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should add any extra fq parameters from the FacetItem" do
|
421
|
-
|
422
|
-
result_params = helper.add_facet_params('facet_field_1', double(:value => 123, :fq => {'facet_field_2' => 'abc'}))
|
423
|
-
|
424
|
-
expect(result_params[:f]['facet_field_1']).to include(123)
|
425
|
-
expect(result_params[:f]['facet_field_2']).to include('abc')
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
describe "add_facet_params_and_redirect" do
|
430
|
-
before do
|
431
|
-
catalog_facet_params = {:q => "query",
|
432
|
-
:search_field => "search_field",
|
433
|
-
:per_page => "50",
|
434
|
-
:page => "5",
|
435
|
-
:f => {"facet_field_1" => ["value1"], "facet_field_2" => ["value2", "value2a"]},
|
436
|
-
Blacklight::Solr::FacetPaginator.request_keys[:page] => "100",
|
437
|
-
Blacklight::Solr::FacetPaginator.request_keys[:sort] => "index",
|
438
|
-
:id => 'facet_field_name'
|
439
|
-
}
|
440
|
-
allow(helper).to receive(:params).and_return(catalog_facet_params)
|
441
|
-
end
|
442
|
-
it "should not include request parameters used by the facet paginator" do
|
443
|
-
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
444
|
-
|
445
|
-
bad_keys = Blacklight::Solr::FacetPaginator.request_keys.values + [:id]
|
446
|
-
bad_keys.each do |paginator_key|
|
447
|
-
expect(params.keys).to_not include(paginator_key)
|
448
|
-
end
|
449
|
-
end
|
450
|
-
it 'should remove :page request key' do
|
451
|
-
params = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
452
|
-
expect(params.keys).to_not include(:page)
|
453
|
-
end
|
454
|
-
it "should otherwise do the same thing as add_facet_params" do
|
455
|
-
added_facet_params = helper.add_facet_params("facet_field_2", "facet_value")
|
456
|
-
added_facet_params_from_facet_action = helper.add_facet_params_and_redirect("facet_field_2", "facet_value")
|
457
|
-
|
458
|
-
expect(added_facet_params_from_facet_action).to eq added_facet_params.except(Blacklight::Solr::FacetPaginator.request_keys[:page], Blacklight::Solr::FacetPaginator.request_keys[:sort])
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
describe "#remove_facet_params" do
|
463
|
-
let(:query_params) { { f: facet_params }}
|
464
|
-
let(:facet_params) { { } }
|
465
|
-
it "should remove the facet / value tuple from the query parameters" do
|
466
|
-
facet_params['some_field'] = ['some_value', 'another_value']
|
467
|
-
|
468
|
-
params = helper.remove_facet_params('some_field', 'some_value', query_params)
|
469
|
-
|
470
|
-
expect(params[:f]['some_field']).not_to include 'some_value'
|
471
|
-
expect(params[:f]['some_field']).to include 'another_value'
|
472
|
-
end
|
473
|
-
|
474
|
-
it "should use the facet's key configuration" do
|
475
|
-
allow(helper).to receive(:facet_configuration_for_field).with('some_field').and_return(double(single: true, field: "a_solr_field", key: "some_key"))
|
476
|
-
facet_params['some_key'] = ['some_value', 'another_value']
|
477
|
-
|
478
|
-
params = helper.remove_facet_params('some_field', 'some_value', query_params)
|
479
|
-
|
480
|
-
expect(params[:f]['some_key']).not_to eq 'some_value'
|
481
|
-
expect(params[:f]['some_key']).to include 'another_value'
|
482
|
-
end
|
483
|
-
|
484
|
-
it "should remove the facet entirely when the last facet value is removed" do
|
485
|
-
facet_params['another_field'] = ['some_value']
|
486
|
-
facet_params['some_field'] = ['some_value']
|
487
|
-
|
488
|
-
params = helper.remove_facet_params('some_field', 'some_value', query_params)
|
489
|
-
|
490
|
-
expect(params[:f]).not_to include 'some_field'
|
491
|
-
end
|
492
|
-
|
493
|
-
it "should remove the 'f' parameter entirely when no facets remain" do
|
494
|
-
facet_params['some_field'] = ['some_value']
|
495
|
-
|
496
|
-
params = helper.remove_facet_params('some_field', 'some_value', query_params)
|
497
|
-
|
498
|
-
expect(params).not_to include :f
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
259
|
describe "#bookmarks_export_url" do
|
503
260
|
it "should be the bookmark url with an encrypted user token" do
|
504
261
|
allow(helper).to receive_messages(encrypt_user_id: 'xyz', current_or_guest_user: double(id: 123))
|
@@ -510,11 +267,13 @@ describe BlacklightUrlHelper do
|
|
510
267
|
describe "#session_tracking_path" do
|
511
268
|
let(:document) { SolrDocument.new(id: 1) }
|
512
269
|
it "should determine the correct route for the document class" do
|
513
|
-
|
270
|
+
allow(helper).to receive(:track_test_path).with(id: 1).and_return('x')
|
271
|
+
expect(helper.session_tracking_path(document)).to eq 'x'
|
514
272
|
end
|
515
273
|
|
516
274
|
it "should pass through tracking parameters" do
|
517
|
-
|
275
|
+
allow(helper).to receive(:track_test_path).with(id: 1, x: 1).and_return('x')
|
276
|
+
expect(helper.session_tracking_path(document, x: 1)).to eq 'x'
|
518
277
|
end
|
519
278
|
end
|
520
279
|
end
|