blacklight 7.0.0.rc1 → 7.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +30 -18
- data/.rubocop_todo.yml +308 -67
- data/.solr_wrapper.yml +8 -1
- data/.travis.yml +15 -13
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/Vagrantfile +2 -0
- data/app/assets/javascripts/blacklight/blacklight.js +17 -17
- data/app/assets/stylesheets/blacklight/_blacklight_base.scss +17 -16
- data/app/assets/stylesheets/blacklight/_facets.scss +2 -13
- data/app/assets/stylesheets/blacklight/_icons.scss +8 -2
- data/app/assets/stylesheets/blacklight/_search_form.scss +7 -0
- data/app/assets/stylesheets/blacklight/blacklight.scss +1 -1
- data/app/builders/blacklight/action_builder.rb +1 -0
- data/app/controllers/concerns/blacklight/bookmarks.rb +19 -13
- data/app/controllers/concerns/blacklight/catalog.rb +19 -7
- data/app/controllers/concerns/blacklight/controller.rb +12 -18
- data/app/controllers/concerns/blacklight/facet.rb +3 -0
- data/app/controllers/concerns/blacklight/search_context.rb +7 -3
- data/app/controllers/concerns/blacklight/search_history.rb +1 -6
- data/app/controllers/concerns/blacklight/token_based_user.rb +3 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +5 -1
- data/app/helpers/blacklight/configuration_helper_behavior.rb +5 -3
- data/app/helpers/blacklight/facets_helper_behavior.rb +15 -12
- data/app/helpers/blacklight/icon_helper_behavior.rb +2 -0
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -0
- data/app/helpers/blacklight/render_partials_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +1 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +29 -14
- data/app/javascript/blacklight/checkbox_submit.js +9 -8
- data/app/javascript/blacklight/core.js +8 -6
- data/app/javascript/blacklight/modal.js +1 -3
- data/app/javascript/blacklight/search_context.js +0 -1
- data/app/models/blacklight/icon.rb +3 -0
- data/app/models/blacklight/suggest_search.rb +3 -14
- data/app/models/bookmark.rb +1 -1
- data/app/models/concerns/blacklight/document.rb +3 -1
- data/app/models/concerns/blacklight/solr/document.rb +1 -0
- data/app/models/concerns/blacklight/suggest/response.rb +5 -3
- data/app/models/concerns/blacklight/user.rb +1 -0
- data/app/models/search.rb +1 -0
- data/app/presenters/blacklight/document_presenter.rb +38 -0
- data/app/presenters/blacklight/field_presenter.rb +2 -0
- data/app/presenters/blacklight/index_presenter.rb +13 -5
- data/app/presenters/blacklight/json_presenter.rb +5 -12
- data/app/presenters/blacklight/link_alternate_presenter.rb +2 -0
- data/app/presenters/blacklight/rendering/abstract_step.rb +2 -0
- data/app/presenters/blacklight/rendering/helper_method.rb +2 -0
- data/app/presenters/blacklight/rendering/join.rb +2 -0
- data/app/presenters/blacklight/rendering/link_to_facet.rb +4 -0
- data/app/presenters/blacklight/rendering/microdata.rb +3 -0
- data/app/presenters/blacklight/rendering/pipeline.rb +2 -0
- data/app/presenters/blacklight/rendering/terminator.rb +2 -0
- data/app/presenters/blacklight/search_bar_presenter.rb +2 -0
- data/app/presenters/blacklight/show_presenter.rb +8 -5
- data/app/presenters/blacklight/thumbnail_presenter.rb +2 -0
- data/app/services/blacklight/document_factory.rb +2 -0
- data/app/services/blacklight/field_retriever.rb +2 -0
- data/app/services/blacklight/search_service.rb +7 -9
- data/app/values/blacklight/types.rb +3 -0
- data/app/views/bookmarks/index.html.erb +12 -13
- data/app/views/catalog/_citation.html.erb +4 -4
- data/app/views/catalog/_constraints.html.erb +2 -0
- data/app/views/catalog/_did_you_mean.html.erb +1 -1
- data/app/views/catalog/_document.atom.builder +17 -16
- data/app/views/catalog/_document.rss.builder +2 -0
- data/app/views/catalog/_facet_index_navigation.html.erb +5 -4
- data/app/views/catalog/_facet_layout.html.erb +3 -5
- data/app/views/catalog/_facets.html.erb +5 -4
- data/app/views/catalog/_field.json.jbuilder +10 -0
- data/app/views/catalog/_group.html.erb +1 -1
- data/app/views/catalog/_home_text.html.erb +5 -5
- data/app/views/catalog/_index.html.erb +5 -7
- data/app/views/catalog/_index_header.html.erb +1 -1
- data/app/views/catalog/_per_page_widget.html.erb +1 -1
- data/app/views/catalog/_results_pagination.html.erb +2 -2
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_search_results.html.erb +2 -2
- data/app/views/catalog/_show.html.erb +3 -5
- data/app/views/catalog/_show_more_like_this.html.erb +1 -1
- data/app/views/catalog/_show_sidebar.html.erb +1 -1
- data/app/views/catalog/_show_tools.html.erb +1 -1
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/app/views/catalog/_zero_results.html.erb +1 -1
- data/app/views/catalog/citation.js.erb +1 -1
- data/app/views/catalog/facet.html.erb +5 -4
- data/app/views/catalog/facet.json.jbuilder +2 -0
- data/app/views/catalog/index.atom.builder +4 -2
- data/app/views/catalog/index.json.jbuilder +29 -10
- data/app/views/catalog/index.rss.builder +2 -0
- data/app/views/catalog/opensearch.xml.builder +3 -1
- data/app/views/catalog/show.json.jbuilder +21 -0
- data/app/views/kaminari/blacklight/_first_page.html.erb +1 -1
- data/app/views/kaminari/blacklight/_last_page.html.erb +1 -1
- data/app/views/kaminari/blacklight/_next_page.html.erb +3 -3
- data/app/views/kaminari/blacklight/_page.html.erb +4 -2
- data/app/views/kaminari/blacklight/_prev_page.html.erb +2 -2
- data/app/views/layouts/blacklight.html.erb +4 -4
- data/app/views/layouts/blacklight/base.html.erb +1 -9
- data/app/views/search_history/index.html.erb +3 -3
- data/app/views/shared/_header_navbar.html.erb +1 -1
- data/app/views/shared/_modal.html.erb +2 -2
- data/blacklight.gemspec +7 -6
- data/config/i18n-tasks.yml +17 -0
- data/config/locales/blacklight.de.yml +72 -57
- data/config/locales/blacklight.en.yml +11 -1
- data/config/locales/blacklight.es.yml +15 -1
- data/config/locales/blacklight.fr.yml +17 -8
- data/config/locales/blacklight.hu.yml +3 -1
- data/config/locales/blacklight.it.yml +16 -1
- data/config/locales/blacklight.nl.yml +3 -1
- data/config/locales/blacklight.pt-BR.yml +19 -2
- data/config/locales/blacklight.sq.yml +3 -1
- data/config/locales/blacklight.zh.yml +3 -1
- data/config/routes.rb +0 -1
- data/lib/blacklight.rb +3 -0
- data/lib/blacklight/abstract_repository.rb +12 -0
- data/lib/blacklight/configuration.rb +21 -3
- data/lib/blacklight/configuration/context.rb +11 -0
- data/lib/blacklight/configuration/fields.rb +31 -26
- data/lib/blacklight/configuration/null_field.rb +2 -0
- data/lib/blacklight/engine.rb +4 -1
- data/lib/blacklight/routes/exportable.rb +1 -3
- data/lib/blacklight/routes/searchable.rb +2 -3
- data/lib/blacklight/runtime_registry.rb +2 -0
- data/lib/blacklight/search_builder.rb +2 -0
- data/lib/blacklight/search_state.rb +2 -0
- data/lib/blacklight/solr/repository.rb +34 -0
- data/lib/blacklight/solr/response/spelling.rb +1 -0
- data/lib/generators/blacklight/assets_generator.rb +10 -9
- data/lib/generators/blacklight/controller_generator.rb +1 -1
- data/lib/generators/blacklight/install_generator.rb +7 -14
- data/lib/generators/blacklight/solr_generator.rb +8 -0
- data/lib/generators/blacklight/templates/alternate_controller.rb +4 -4
- data/lib/generators/blacklight/templates/catalog_controller.rb +7 -1
- data/lib/generators/blacklight/templates/solr/conf/schema.xml +20 -22
- data/lib/generators/blacklight/user_generator.rb +2 -0
- data/lib/railties/blacklight.rake +9 -13
- data/package-lock.json +544 -406
- data/package.json +3 -2
- data/spec/controllers/alternate_controller_spec.rb +4 -3
- data/spec/controllers/application_controller_spec.rb +0 -4
- data/spec/controllers/blacklight/base_spec.rb +5 -2
- data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +4 -4
- data/spec/controllers/blacklight/facet_spec.rb +0 -1
- data/spec/controllers/blacklight/search_fields_spec.rb +25 -22
- data/spec/controllers/bookmarks_controller_spec.rb +45 -10
- data/spec/controllers/catalog_controller_spec.rb +206 -138
- data/spec/controllers/search_history_controller_spec.rb +4 -4
- data/spec/features/alternate_controller_spec.rb +3 -3
- data/spec/features/autocomplete_spec.rb +2 -0
- data/spec/features/did_you_mean_spec.rb +4 -3
- data/spec/features/facets_spec.rb +7 -7
- data/spec/features/record_view_spec.rb +11 -12
- data/spec/features/search_context_spec.rb +4 -5
- data/spec/features/search_crawler_spec.rb +3 -5
- data/spec/features/search_filters_spec.rb +44 -44
- data/spec/features/search_history_spec.rb +5 -3
- data/spec/features/search_pagination_spec.rb +3 -1
- data/spec/features/search_results_spec.rb +11 -8
- data/spec/features/search_spec.rb +3 -3
- data/spec/features/sitelinks_search_box.rb +4 -4
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +30 -30
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +65 -59
- data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight/icon_helper_behavior_spec.rb +2 -0
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +8 -3
- data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +16 -4
- data/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb +21 -22
- data/spec/helpers/blacklight/suggest_helper_behavior_spec.rb +6 -1
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +49 -43
- data/spec/helpers/blacklight_helper_spec.rb +28 -12
- data/spec/helpers/catalog_helper_spec.rb +50 -47
- data/spec/i18n_spec.rb +18 -0
- data/spec/integration/generators/blacklight/solr_generator_spec.rb +18 -10
- data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -0
- data/spec/lib/blacklight/configuration/field_spec.rb +3 -0
- data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +15 -20
- data/spec/lib/blacklight/parameters_spec.rb +3 -1
- data/spec/lib/blacklight/search_state_spec.rb +51 -34
- data/spec/lib/blacklight_spec.rb +13 -14
- data/spec/lib/tasks/blacklight_task_spec.rb +3 -5
- data/spec/models/blacklight/configurable_spec.rb +11 -13
- data/spec/models/blacklight/configuration/context_spec.rb +9 -10
- data/spec/models/blacklight/configuration_spec.rb +103 -91
- data/spec/models/blacklight/document/active_model_shim_spec.rb +5 -6
- data/spec/models/blacklight/document/cache_key_spec.rb +9 -2
- data/spec/models/blacklight/document/dublin_core_spec.rb +16 -19
- data/spec/models/blacklight/document/email_spec.rb +9 -9
- data/spec/models/blacklight/document/sms_spec.rb +9 -9
- data/spec/models/blacklight/document_spec.rb +9 -8
- data/spec/models/blacklight/facet_paginator_spec.rb +40 -30
- data/spec/models/blacklight/icon_spec.rb +12 -2
- data/spec/models/blacklight/search_builder_spec.rb +12 -3
- data/spec/models/blacklight/solr/document_spec.rb +216 -219
- data/spec/models/blacklight/solr/facet_paginator_spec.rb +6 -4
- data/spec/models/blacklight/solr/repository_spec.rb +37 -34
- data/spec/models/blacklight/solr/request_spec.rb +17 -18
- data/spec/models/blacklight/solr/response/facets_spec.rb +58 -58
- data/spec/models/blacklight/solr/response/group_response_spec.rb +16 -22
- data/spec/models/blacklight/solr/response/group_spec.rb +18 -25
- data/spec/models/blacklight/solr/response_spec.rb +48 -50
- data/spec/models/blacklight/solr/search_builder_spec.rb +120 -121
- data/spec/models/blacklight/suggest/response_spec.rb +6 -4
- data/spec/models/blacklight/suggest_search_spec.rb +9 -16
- data/spec/models/blacklight/user_spec.rb +9 -11
- data/spec/models/bookmark_spec.rb +6 -5
- data/spec/models/record_mailer_spec.rb +22 -20
- data/spec/models/search_spec.rb +18 -17
- data/spec/models/solr_document_spec.rb +6 -2
- data/spec/presenters/blacklight/document_presenter_spec.rb +86 -0
- data/spec/presenters/blacklight/index_presenter_spec.rb +186 -0
- data/spec/presenters/blacklight/json_presenter_spec.rb +59 -0
- data/spec/presenters/blacklight/link_alternate_presenter_spec.rb +3 -0
- data/spec/presenters/blacklight/search_bar_presenter_spec.rb +7 -0
- data/spec/presenters/{show_presenter_spec.rb → blacklight/show_presenter_spec.rb} +138 -91
- data/spec/presenters/pipeline_spec.rb +15 -8
- data/spec/presenters/thumbnail_presenter_spec.rb +5 -2
- data/spec/routing/catalog_routing_spec.rb +12 -14
- data/spec/services/blacklight/search_service_spec.rb +112 -70
- data/spec/spec_helper.rb +6 -2
- data/spec/support/features.rb +1 -1
- data/spec/support/features/session_helpers.rb +4 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -13
- data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -3
- data/spec/views/catalog/_constraints_element.html.erb_spec.rb +9 -5
- data/spec/views/catalog/_document.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -0
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -4
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -3
- data/spec/views/catalog/_facets.html.erb_spec.rb +8 -10
- data/spec/views/catalog/_index.html.erb_spec.rb +13 -14
- data/spec/views/catalog/_index_header.html.erb_spec.rb +5 -8
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
- data/spec/views/catalog/_show.html.erb_spec.rb +12 -13
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +4 -7
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +0 -1
- data/spec/views/catalog/_sort_widget.html.erb_spec.rb +3 -1
- data/spec/views/catalog/_thumbnail.html.erb_spec.rb +6 -8
- data/spec/views/catalog/_view_type_group.html.erb_spec.rb +7 -9
- data/spec/views/catalog/email_success.html.erb_spec.rb +0 -1
- data/spec/views/catalog/facet.html.erb_spec.rb +3 -2
- data/spec/views/catalog/facet.json.jbuilder_spec.rb +3 -2
- data/spec/views/catalog/index.atom.builder_spec.rb +9 -4
- data/spec/views/catalog/index.html.erb_spec.rb +2 -1
- data/spec/views/catalog/index.json.jbuilder_spec.rb +84 -36
- data/spec/views/catalog/show.html.erb_spec.rb +6 -6
- data/spec/views/catalog/show.json.jbuilder_spec.rb +40 -0
- data/spec/views/catalog/sms_success.html.erb_spec.rb +0 -1
- data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -4
- data/tasks/blacklight.rake +6 -4
- data/template.demo.rb +2 -0
- metadata +50 -24
- data/app/javascript/blacklight/autofocus.js +0 -20
- data/spec/presenters/index_presenter_spec.rb +0 -150
@@ -7,7 +7,7 @@ RSpec.describe Blacklight::HashAsHiddenFieldsHelperBehavior do
|
|
7
7
|
per_page: 10,
|
8
8
|
page: 5,
|
9
9
|
extra_arbitrary_key: "arbitrary_value",
|
10
|
-
f: { field1: %w
|
10
|
+
f: { field1: %w[a b], field2: ["z"] } }
|
11
11
|
end
|
12
12
|
let(:generated) { helper.render_hash_as_hidden_fields(params) }
|
13
13
|
|
@@ -16,9 +16,10 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '#render_constraints_query' do
|
19
|
+
subject { helper.render_constraints_query(params) }
|
20
|
+
|
19
21
|
let(:my_engine) { double("Engine") }
|
20
22
|
let(:params) { ActionController::Parameters.new(q: 'foobar', f: { type: 'journal' }) }
|
21
|
-
subject { helper.render_constraints_query(params) }
|
22
23
|
|
23
24
|
it "has a link relative to the current url" do
|
24
25
|
expect(subject).to have_selector "a[href='/?f%5Btype%5D=journal']"
|
@@ -34,6 +35,7 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
34
35
|
|
35
36
|
context "with a route_set" do
|
36
37
|
let(:params) { ActionController::Parameters.new(q: 'foobar', f: { type: 'journal' }, route_set: my_engine) }
|
38
|
+
|
37
39
|
it "accepts an optional route set" do
|
38
40
|
expect(my_engine).to receive(:url_for).and_return('/?f%5Btype%5D=journal')
|
39
41
|
expect(subject).to have_selector "a[href='/?f%5Btype%5D=journal']"
|
@@ -42,11 +44,12 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
42
44
|
end
|
43
45
|
|
44
46
|
describe '#render_filter_element' do
|
47
|
+
subject { helper.render_filter_element('type', ['journal'], path) }
|
48
|
+
|
45
49
|
before do
|
46
50
|
allow(helper).to receive(:blacklight_config).and_return(config)
|
47
51
|
expect(helper).to receive(:facet_field_label).with('type').and_return("Item Type")
|
48
52
|
end
|
49
|
-
subject { helper.render_filter_element('type', ['journal'], path) }
|
50
53
|
|
51
54
|
let(:params) { ActionController::Parameters.new q: 'biz' }
|
52
55
|
let(:path) { Blacklight::SearchState.new(params, config, controller) }
|
@@ -66,12 +69,14 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
|
|
66
69
|
end
|
67
70
|
|
68
71
|
describe "#render_constraints_filters" do
|
72
|
+
subject { helper.render_constraints_filters(params) }
|
73
|
+
|
69
74
|
let(:params) { ActionController::Parameters.new f: { 'type' => [''] } }
|
75
|
+
|
70
76
|
before do
|
71
77
|
allow(helper).to receive(:blacklight_config).and_return(config)
|
72
78
|
allow(controller).to receive(:search_state_class).and_return(Blacklight::SearchState)
|
73
79
|
end
|
74
|
-
subject { helper.render_constraints_filters(params) }
|
75
80
|
|
76
81
|
it "renders nothing for empty facet limit param" do
|
77
82
|
expect(subject).to be_blank
|
@@ -1,31 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Blacklight::RenderPartialsHelperBehavior do
|
2
4
|
describe "#type_field_to_partial_name" do
|
3
|
-
let(:document) { double }
|
4
5
|
subject { helper.send(:type_field_to_partial_name, document, value) }
|
5
6
|
|
7
|
+
let(:document) { double }
|
8
|
+
|
6
9
|
context "with default value" do
|
7
10
|
let(:value) { 'default' }
|
11
|
+
|
8
12
|
it { is_expected.to eq 'default' }
|
9
13
|
end
|
10
14
|
|
11
15
|
context "with spaces" do
|
12
16
|
let(:value) { 'one two three' }
|
17
|
+
|
13
18
|
it { is_expected.to eq 'one_two_three' }
|
14
19
|
end
|
15
20
|
|
16
21
|
context "with hyphens" do
|
17
22
|
let(:value) { 'one-two-three' }
|
23
|
+
|
18
24
|
it { is_expected.to eq 'one_two_three' }
|
19
25
|
end
|
20
26
|
|
21
27
|
context "an array" do
|
22
|
-
let(:value) { [
|
28
|
+
let(:value) { %w[one two three] }
|
29
|
+
|
23
30
|
it { is_expected.to eq 'one_two_three' }
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
34
|
describe "#render_document_partials" do
|
28
35
|
let(:doc) { double }
|
36
|
+
|
29
37
|
before do
|
30
38
|
allow(helper).to receive_messages(document_partial_path_templates: [])
|
31
39
|
allow(helper).to receive_messages(document_index_view_type: 'index_header')
|
@@ -39,19 +47,22 @@ RSpec.describe Blacklight::RenderPartialsHelperBehavior do
|
|
39
47
|
|
40
48
|
describe "#document_partial_name" do
|
41
49
|
let(:blacklight_config) { Blacklight::Configuration.new }
|
50
|
+
|
42
51
|
before do
|
43
52
|
allow(helper).to receive_messages(blacklight_config: blacklight_config)
|
44
53
|
end
|
45
54
|
|
46
55
|
context "with a solr document with empty fields" do
|
47
56
|
let(:document) { SolrDocument.new }
|
57
|
+
|
48
58
|
it "is the default value" do
|
49
59
|
expect(helper.document_partial_name(document)).to eq 'default'
|
50
60
|
end
|
51
61
|
end
|
52
62
|
|
53
63
|
context "with a solr document with the display type field set" do
|
54
|
-
let(:document) { SolrDocument.new 'my_field' => 'xyz'}
|
64
|
+
let(:document) { SolrDocument.new 'my_field' => 'xyz' }
|
65
|
+
|
55
66
|
before do
|
56
67
|
blacklight_config.show.display_type_field = 'my_field'
|
57
68
|
end
|
@@ -66,15 +77,16 @@ RSpec.describe Blacklight::RenderPartialsHelperBehavior do
|
|
66
77
|
|
67
78
|
context "with a solr doucment with an action-specific field set" do
|
68
79
|
let(:document) { SolrDocument.new 'my_field' => 'xyz', 'other_field' => 'abc' }
|
80
|
+
|
69
81
|
before do
|
70
82
|
blacklight_config.show.media_display_type_field = 'my_field'
|
71
83
|
blacklight_config.show.metadata_display_type_field = 'other_field'
|
72
84
|
end
|
85
|
+
|
73
86
|
it "uses the value in the action-specific fields" do
|
74
87
|
expect(helper.document_partial_name(document, :media)).to eq 'xyz'
|
75
88
|
expect(helper.document_partial_name(document, :metadata)).to eq 'abc'
|
76
89
|
end
|
77
90
|
end
|
78
91
|
end
|
79
|
-
|
80
92
|
end
|
@@ -1,21 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Blacklight::SearchHistoryConstraintsHelperBehavior do
|
4
|
-
|
5
4
|
before(:all) do
|
6
5
|
@config = Blacklight::Configuration.new do |config|
|
7
|
-
config.add_search_field 'default_search_field', :
|
6
|
+
config.add_search_field 'default_search_field', label: 'Default'
|
8
7
|
|
9
|
-
config.add_facet_field 'some_facet', :
|
10
|
-
config.add_facet_field 'other_facet', :
|
8
|
+
config.add_facet_field 'some_facet', label: 'Some'
|
9
|
+
config.add_facet_field 'other_facet', label: 'Other'
|
11
10
|
config.add_facet_field 'i18n_facet'
|
12
11
|
|
13
|
-
I18n.backend.store_translations(:en, blacklight: {search: {fields: {facet: {i18n_facet: 'English facet label'}}}})
|
14
|
-
I18n.backend.store_translations(:de, blacklight: {search: {fields: {facet: {i18n_facet: 'German facet label'}}}})
|
12
|
+
I18n.backend.store_translations(:en, blacklight: { search: { fields: { facet: { i18n_facet: 'English facet label' } } } })
|
13
|
+
I18n.backend.store_translations(:de, blacklight: { search: { fields: { facet: { i18n_facet: 'German facet label' } } } })
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
before
|
17
|
+
before do
|
19
18
|
allow(helper).to receive(:blacklight_config).and_return(@config)
|
20
19
|
end
|
21
20
|
|
@@ -23,7 +22,7 @@ RSpec.describe Blacklight::SearchHistoryConstraintsHelperBehavior do
|
|
23
22
|
describe "render_search_to_s_element" do
|
24
23
|
it "renders basic element" do
|
25
24
|
response = helper.render_search_to_s_element("key", "value")
|
26
|
-
expect(response).to have_selector("span.constraint")
|
25
|
+
expect(response).to have_selector("span.constraint") do |span|
|
27
26
|
expect(span).to have_selector("span.filter-name", content: "key:")
|
28
27
|
expect(span).to have_selector("span.filter-value", content: "value")
|
29
28
|
end
|
@@ -31,21 +30,21 @@ RSpec.describe Blacklight::SearchHistoryConstraintsHelperBehavior do
|
|
31
30
|
end
|
32
31
|
it "escapes them that need escaping" do
|
33
32
|
response = helper.render_search_to_s_element("key>", "value>")
|
34
|
-
expect(response).to have_selector("span.constraint") do |span|
|
33
|
+
expect(response).to have_selector("span.constraint") do |span|
|
35
34
|
expect(span).to have_selector("span.filter-name") do |s2|
|
36
35
|
# Note: nokogiri's gettext will unescape the inner html
|
37
|
-
# which seems to be what rspecs "contains" method calls on
|
36
|
+
# which seems to be what rspecs "contains" method calls on
|
38
37
|
# text nodes - thus the to_s inserted below.
|
39
38
|
expect(s2).to match(/key>:/)
|
40
39
|
end
|
41
|
-
expect(span).to have_selector("span.filter-value") do |s3|
|
40
|
+
expect(span).to have_selector("span.filter-value") do |s3|
|
42
41
|
expect(s3).to match(/value>/)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
expect(response).to be_html_safe
|
46
45
|
end
|
47
46
|
it "does not escape with options set thus" do
|
48
|
-
response = helper.render_search_to_s_element("key>", "value>", :
|
47
|
+
response = helper.render_search_to_s_element("key>", "value>", escape_key: false, escape_value: false)
|
49
48
|
expect(response).to have_selector("span.constraint") do |span|
|
50
49
|
expect(span).to have_selector("span.filter-name", content: "key>:")
|
51
50
|
expect(span).to have_selector("span.filter-value", content: "value>")
|
@@ -56,29 +55,30 @@ RSpec.describe Blacklight::SearchHistoryConstraintsHelperBehavior do
|
|
56
55
|
|
57
56
|
describe "render_search_to_s" do
|
58
57
|
before do
|
59
|
-
@params = {:
|
58
|
+
@params = { q: "history", f: { "some_facet" => %w[value1 value1], "other_facet" => ["other1"] } }
|
60
59
|
end
|
60
|
+
|
61
61
|
it "calls lesser methods" do
|
62
62
|
allow(helper).to receive(:blacklight_config).and_return(@config)
|
63
|
-
allow(helper).to receive(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(:
|
63
|
+
allow(helper).to receive(:default_search_field).and_return(Blacklight::Configuration::SearchField.new(key: 'default_search_field', display_label: 'Default'))
|
64
64
|
allow(helper).to receive(:label_for_search_field).with(nil).and_return('')
|
65
65
|
# API hooks expect this to be so
|
66
66
|
response = helper.render_search_to_s(@params)
|
67
67
|
|
68
|
-
expect(response).to include(
|
69
|
-
expect(response).to include(
|
68
|
+
expect(response).to include(helper.render_search_to_s_q(@params))
|
69
|
+
expect(response).to include(helper.render_search_to_s_filters(@params))
|
70
70
|
expect(response).to be_html_safe
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
describe "render_search_to_s_filters" do
|
75
75
|
it "renders a constraint for a selected facet in the config" do
|
76
|
-
response = helper.render_search_to_s_filters(:
|
76
|
+
response = helper.render_search_to_s_filters(f: { "some_facet" => %w[value1 value2] })
|
77
77
|
expect(response).to eq("<span class=\"constraint\"><span class=\"filter-name\">Some:</span><span class=\"filter-values\"><span class=\"filter-value\">value1</span><span class=\"filter-separator\"> and </span><span class=\"filter-value\">value2</span></span></span>")
|
78
78
|
end
|
79
79
|
|
80
80
|
it "renders a constraint for a selected facet not in the config" do
|
81
|
-
response = helper.render_search_to_s_filters(:
|
81
|
+
response = helper.render_search_to_s_filters(f: { "undefined_facet" => %w[value1 value2] })
|
82
82
|
expect(response).to eq("<span class=\"constraint\"><span class=\"filter-name\">#{'undefined_facet'.titleize}:</span><span class=\"filter-values\"><span class=\"filter-value\">value1</span><span class=\"filter-separator\"> and </span><span class=\"filter-value\">value2</span></span></span>")
|
83
83
|
end
|
84
84
|
|
@@ -92,14 +92,13 @@ RSpec.describe Blacklight::SearchHistoryConstraintsHelperBehavior do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'renders the correct I18n label for a selected facet with I18n translations' do
|
95
|
-
{en: 'English facet label', de: 'German facet label'}.each do |locale, label|
|
95
|
+
{ en: 'English facet label', de: 'German facet label' }.each do |locale, label|
|
96
96
|
I18n.locale = locale
|
97
|
-
response = helper.render_search_to_s_filters(f: {'i18n_facet' => [
|
97
|
+
response = helper.render_search_to_s_filters(f: { 'i18n_facet' => %w[value1 value2] })
|
98
98
|
expect(response).to include(label)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
105
104
|
end
|
@@ -5,7 +5,7 @@ RSpec.describe Blacklight::SuggestHelperBehavior do
|
|
5
5
|
allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
|
6
6
|
expect(Deprecation).to receive(:warn)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe '#autocomplete_enabled?' do
|
10
10
|
describe 'with autocomplete config' do
|
11
11
|
let(:blacklight_config) do
|
@@ -14,10 +14,12 @@ RSpec.describe Blacklight::SuggestHelperBehavior do
|
|
14
14
|
config.autocomplete_path = 'suggest'
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
17
18
|
it 'is enabled' do
|
18
19
|
expect(helper.autocomplete_enabled?).to be true
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
21
23
|
describe 'without disabled config' do
|
22
24
|
let(:blacklight_config) do
|
23
25
|
Blacklight::Configuration.new.configure do |config|
|
@@ -25,16 +27,19 @@ RSpec.describe Blacklight::SuggestHelperBehavior do
|
|
25
27
|
config.autocomplete_path = 'suggest'
|
26
28
|
end
|
27
29
|
end
|
30
|
+
|
28
31
|
it 'is disabled' do
|
29
32
|
expect(helper.autocomplete_enabled?).to be false
|
30
33
|
end
|
31
34
|
end
|
35
|
+
|
32
36
|
describe 'without path config' do
|
33
37
|
let(:blacklight_config) do
|
34
38
|
Blacklight::Configuration.new.configure do |config|
|
35
39
|
config.autocomplete_enabled = true
|
36
40
|
end
|
37
41
|
end
|
42
|
+
|
38
43
|
it 'is disabled' do
|
39
44
|
expect(helper.autocomplete_enabled?).to be false
|
40
45
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Blacklight::UrlHelperBehavior do
|
4
|
-
|
5
4
|
let(:blacklight_config) do
|
6
5
|
Blacklight::Configuration.new.configure do |config|
|
7
6
|
config.index.title_field = 'title_tsim'
|
@@ -37,7 +36,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
37
36
|
|
38
37
|
it "allows for custom show routes" do
|
39
38
|
helper.blacklight_config.show.route = { controller: 'catalog' }
|
40
|
-
expect(helper.url_for_document(doc)).to eq(
|
39
|
+
expect(helper.url_for_document(doc)).to eq(controller: 'catalog', action: :show, id: doc)
|
41
40
|
end
|
42
41
|
|
43
42
|
context "within bookmarks" do
|
@@ -53,7 +52,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
53
52
|
|
54
53
|
before do
|
55
54
|
helper.blacklight_config.show.route = { controller: :current }
|
56
|
-
allow(helper).to receive(:params).and_return(parameter_class.new
|
55
|
+
allow(helper).to receive(:params).and_return(parameter_class.new(controller: 'alternate'))
|
57
56
|
end
|
58
57
|
|
59
58
|
it "supports the :current controller configuration" do
|
@@ -70,27 +69,26 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
70
69
|
end
|
71
70
|
|
72
71
|
describe "link_back_to_catalog" do
|
73
|
-
let(:query_params)
|
74
|
-
let(:bookmarks_query_params) {{ :
|
72
|
+
let(:query_params) { { q: "query", f: "facets", controller: 'catalog' } }
|
73
|
+
let(:bookmarks_query_params) { { controller: 'bookmarks' } }
|
75
74
|
|
76
75
|
it "builds a link tag to catalog using session[:search] for query params" do
|
77
|
-
allow(helper).to receive(:current_search_session).and_return double(:
|
76
|
+
allow(helper).to receive(:current_search_session).and_return double(query_params: query_params)
|
78
77
|
tag = helper.link_back_to_catalog
|
79
78
|
expect(tag).to match /q=query/
|
80
79
|
expect(tag).to match /f=facets/
|
81
|
-
expect(tag).
|
82
|
-
expect(tag).
|
80
|
+
expect(tag).not_to match /page=/
|
81
|
+
expect(tag).not_to match /per_page=/
|
83
82
|
end
|
84
83
|
|
85
84
|
it "builds a link tag to bookmarks using session[:search] for query params" do
|
86
|
-
allow(helper).to receive(:current_search_session).and_return double(:
|
85
|
+
allow(helper).to receive(:current_search_session).and_return double(query_params: bookmarks_query_params)
|
87
86
|
tag = helper.link_back_to_catalog
|
88
87
|
expect(tag).to match /Back to Bookmarks/
|
89
|
-
expect(tag).to match
|
88
|
+
expect(tag).to match %r{/bookmarks}
|
90
89
|
end
|
91
90
|
|
92
91
|
context "with a search context" do
|
93
|
-
|
94
92
|
it "uses the current search session counter and per page information to construct the appropriate pagination context" do
|
95
93
|
allow(helper).to receive_messages(current_search_session: double(query_params: query_params))
|
96
94
|
allow(helper).to receive_messages(search_session: { 'per_page' => 15, 'counter' => 31 })
|
@@ -104,34 +102,35 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
104
102
|
allow(helper).to receive_messages(search_session: { 'per_page' => 10, 'counter' => 31 })
|
105
103
|
tag = helper.link_back_to_catalog
|
106
104
|
expect(tag).to match /page=4/
|
107
|
-
expect(tag).
|
105
|
+
expect(tag).not_to match /per_page=/
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
111
109
|
context "without current search context" do
|
110
|
+
subject { helper.link_back_to_catalog }
|
111
|
+
|
112
112
|
before do
|
113
113
|
controller.request.assign_parameters(Rails.application.routes, 'catalog', 'show', { id: '123' }, '/catalog/123', [:controller, :action, :id])
|
114
114
|
allow(helper).to receive_messages(current_search_session: nil)
|
115
115
|
end
|
116
116
|
|
117
|
-
subject { helper.link_back_to_catalog }
|
118
|
-
|
119
117
|
it "links to the catalog" do
|
120
118
|
expect(subject).to eq '<a href="/catalog">Back to Search</a>'
|
121
119
|
end
|
122
120
|
end
|
123
121
|
|
124
122
|
context "when an alternate scope is passed in" do
|
125
|
-
let(:my_engine) { double("Engine") }
|
126
123
|
subject(:tag) { helper.link_back_to_catalog(route_set: my_engine) }
|
127
124
|
|
125
|
+
let(:my_engine) { double("Engine") }
|
126
|
+
|
128
127
|
before do
|
129
|
-
allow(helper).to receive(:current_search_session).and_return double(:
|
128
|
+
allow(helper).to receive(:current_search_session).and_return double(query_params: query_params)
|
130
129
|
end
|
131
130
|
|
132
131
|
it "calls url_for on the engine scope" do
|
133
132
|
expect(my_engine).to receive(:url_for)
|
134
|
-
.with(q:"query", f: "facets", controller: "catalog")
|
133
|
+
.with(q: "query", f: "facets", controller: "catalog")
|
135
134
|
.and_return('link-url')
|
136
135
|
expect(tag).to match /Back to Search/
|
137
136
|
expect(tag).to match /link-url/
|
@@ -142,6 +141,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
142
141
|
describe "link_to_previous_document" do
|
143
142
|
context "when the argument is nil" do
|
144
143
|
subject { helper.link_to_previous_document(nil) }
|
144
|
+
|
145
145
|
it { is_expected.to eq '<span class="previous">« Previous</span>' }
|
146
146
|
end
|
147
147
|
end
|
@@ -152,7 +152,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
152
152
|
allow(helper).to receive_messages(params: parameter_class.new)
|
153
153
|
tag = helper.link_to_query(query)
|
154
154
|
expect(tag).to match /q=#{query}/
|
155
|
-
expect(tag).to match
|
155
|
+
expect(tag).to match %r{>#{query}</a>}
|
156
156
|
end
|
157
157
|
|
158
158
|
it "builds a link tag to catalog using query string and other existing params" do
|
@@ -168,7 +168,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
168
168
|
allow(helper).to receive_messages(params: parameter_class.new(page: "2", qt: "author_search"))
|
169
169
|
tag = helper.link_to_query(query)
|
170
170
|
expect(tag).to match /qt=author_search/
|
171
|
-
expect(tag).
|
171
|
+
expect(tag).not_to match /page/
|
172
172
|
end
|
173
173
|
|
174
174
|
it "is html_safe" do
|
@@ -181,15 +181,15 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
181
181
|
|
182
182
|
describe "start_over_path" do
|
183
183
|
it 'is the catalog path with the current view type' do
|
184
|
-
allow(blacklight_config).to receive(:view)
|
185
|
-
allow(helper).to receive_messages(:
|
186
|
-
expect(helper.start_over_path(:
|
184
|
+
allow(blacklight_config).to receive(:view).and_return(list: nil, abc: nil)
|
185
|
+
allow(helper).to receive_messages(blacklight_config: blacklight_config)
|
186
|
+
expect(helper.start_over_path(view: 'abc')).to eq search_catalog_url(view: 'abc')
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'does not include the current view type if it is the default' do
|
190
|
-
allow(blacklight_config).to receive(:view)
|
191
|
-
allow(helper).to receive_messages(:
|
192
|
-
expect(helper.start_over_path(:
|
190
|
+
allow(blacklight_config).to receive(:view).and_return(list: nil, asdf: nil)
|
191
|
+
allow(helper).to receive_messages(blacklight_config: blacklight_config)
|
192
|
+
expect(helper.start_over_path(view: 'list')).to eq search_catalog_url
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -198,29 +198,37 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
198
198
|
let(:id) { '123456' }
|
199
199
|
let(:data) { { 'id' => id, 'title_tsim' => [title_tsim] } }
|
200
200
|
let(:document) { SolrDocument.new(data) }
|
201
|
+
|
201
202
|
before do
|
202
203
|
allow(controller).to receive(:action_name).and_return('index')
|
204
|
+
allow(helper.main_app).to receive(:track_test_path).and_return('tracking url')
|
205
|
+
allow(helper.main_app).to receive(:respond_to?).with('track_test_path').and_return(true)
|
203
206
|
end
|
204
207
|
|
205
208
|
it "consists of the document title wrapped in a <a>" do
|
206
|
-
expect(
|
209
|
+
expect(Deprecation).to receive(:warn)
|
210
|
+
expect(helper.link_to_document(document, :title_tsim)).to have_selector("a", text: '654321', count: 1)
|
207
211
|
end
|
208
212
|
|
209
213
|
it "accepts and returns a string label" do
|
210
|
-
expect(helper.link_to_document(document,
|
214
|
+
expect(helper.link_to_document(document, 'This is the title')).to have_selector("a", text: 'This is the title', count: 1)
|
211
215
|
end
|
212
216
|
|
213
217
|
it "accepts and returns a Proc" do
|
214
|
-
expect(
|
218
|
+
expect(Deprecation).to receive(:warn).twice
|
219
|
+
expect(helper.link_to_document(document, proc { |doc, _opts| doc[:id] + ": " + doc.first(:title_tsim) })).to have_selector("a", text: '123456: 654321', count: 1)
|
215
220
|
end
|
216
221
|
|
217
222
|
context 'when label is missing' do
|
218
223
|
let(:data) { { 'id' => id } }
|
224
|
+
|
219
225
|
it "returns id" do
|
220
|
-
expect(
|
226
|
+
expect(Deprecation).to receive(:warn)
|
227
|
+
expect(helper.link_to_document(document, :title_tsim)).to have_selector("a", text: '123456', count: 1)
|
221
228
|
end
|
222
229
|
|
223
230
|
it "is html safe" do
|
231
|
+
expect(Deprecation).to receive(:warn)
|
224
232
|
expect(helper.link_to_document(document, :title_tsim)).to be_html_safe
|
225
233
|
end
|
226
234
|
|
@@ -229,11 +237,12 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
229
237
|
end
|
230
238
|
|
231
239
|
it "doesn't add an erroneous title attribute if one isn't provided" do
|
232
|
-
expect(helper.link_to_document(document, "Some crazy long label...")).
|
240
|
+
expect(helper.link_to_document(document, "Some crazy long label...")).not_to match(/title=/)
|
233
241
|
end
|
234
242
|
|
235
243
|
context "with an integer id" do
|
236
|
-
let(:id) {
|
244
|
+
let(:id) { 123_456 }
|
245
|
+
|
237
246
|
it "works" do
|
238
247
|
expect(helper.link_to_document(document)).to have_selector("a")
|
239
248
|
end
|
@@ -241,31 +250,27 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
241
250
|
end
|
242
251
|
|
243
252
|
it "converts the counter parameter into a data- attribute" do
|
244
|
-
|
245
|
-
|
253
|
+
expect(Deprecation).to receive(:warn)
|
246
254
|
expect(helper.link_to_document(document, :title_tsim, counter: 5)).to include 'data-context-href="tracking url"'
|
255
|
+
expect(helper.main_app).to have_received(:track_test_path).with(hash_including(id: have_attributes(id: '123456'), counter: 5))
|
247
256
|
end
|
248
257
|
|
249
258
|
it "includes the data- attributes from the options" do
|
250
|
-
link = helper.link_to_document document,
|
259
|
+
link = helper.link_to_document document, data: { x: 1 }
|
251
260
|
expect(link).to have_selector '[data-x]'
|
252
261
|
end
|
253
262
|
|
254
263
|
it 'adds a controller-specific tracking attribute' do
|
255
|
-
expect(helper).to receive(:track_test_path).and_return('/asdf')
|
256
|
-
link = helper.link_to_document document,
|
264
|
+
expect(helper.main_app).to receive(:track_test_path).and_return('/asdf')
|
265
|
+
link = helper.link_to_document document, data: { x: 1 }
|
257
266
|
|
258
267
|
expect(link).to have_selector '[data-context-href="/asdf"]'
|
259
268
|
end
|
260
|
-
|
261
|
-
it 'adds a global tracking attribute' do
|
262
|
-
link = helper.link_to_document document, { data: { x: 1 } }
|
263
|
-
expect(link).to have_selector '[data-context-href="/catalog/123456/track"]'
|
264
|
-
end
|
265
269
|
end
|
266
270
|
|
267
271
|
describe "link_to_previous_search" do
|
268
272
|
let(:params) { {} }
|
273
|
+
|
269
274
|
it "links to the given search parameters" do
|
270
275
|
allow(helper).to receive(:render_search_to_s).with(params).and_return "link text"
|
271
276
|
expect(helper.link_to_previous_search({})).to eq helper.link_to("link text", helper.search_action_path)
|
@@ -282,13 +287,14 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
282
287
|
|
283
288
|
describe "#session_tracking_path" do
|
284
289
|
let(:document) { SolrDocument.new(id: 1) }
|
290
|
+
|
285
291
|
it "determines the correct route for the document class" do
|
286
|
-
allow(helper).to receive(:track_test_path).with(id: have_attributes(id: 1)).and_return('x')
|
292
|
+
allow(helper.main_app).to receive(:track_test_path).with(id: have_attributes(id: 1)).and_return('x')
|
287
293
|
expect(helper.session_tracking_path(document)).to eq 'x'
|
288
294
|
end
|
289
295
|
|
290
296
|
it "passes through tracking parameters" do
|
291
|
-
allow(helper).to receive(:track_test_path).with(id: have_attributes(id: 1), x: 1).and_return('x')
|
297
|
+
allow(helper.main_app).to receive(:track_test_path).with(id: have_attributes(id: 1), x: 1).and_return('x')
|
292
298
|
expect(helper.session_tracking_path(document, x: 1)).to eq 'x'
|
293
299
|
end
|
294
300
|
end
|