From f1a8cf405f73e6e3006f4a60b7d28835222a1e88 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 7 Sep 2016 08:21:59 -0700 Subject: [PATCH] Remove deprecated behaviors --- .rubocop_todo.yml | 61 +-- .../stylesheets/blacklight/_facets.scss | 7 - .../blacklight/blacklight_helper_behavior.rb | 96 ---- .../deprecated_url_helper_behavior.rb | 57 --- .../blacklight/facets_helper_behavior.rb | 1 - app/helpers/blacklight/url_helper_behavior.rb | 2 - .../blacklight/document_presenter.rb | 153 ------ app/presenters/blacklight/index_presenter.rb | 33 -- app/presenters/blacklight/show_presenter.rb | 40 -- app/views/catalog/_previous_next_doc.html.erb | 3 +- lib/blacklight/configuration.rb | 13 - lib/blacklight/exceptions.rb | 8 +- lib/blacklight/search_builder.rb | 16 +- lib/blacklight/solr/response.rb | 2 - spec/helpers/blacklight_helper_spec.rb | 59 +-- .../deprecated_url_helper_behavior_spec.rb | 100 ---- spec/helpers/facets_helper_spec.rb | 1 - spec/models/blacklight/search_builder_spec.rb | 19 +- .../blacklight/solr/search_builder_spec.rb | 19 +- spec/presenters/document_presenter_spec.rb | 438 ------------------ spec/presenters/index_presenter_spec.rb | 26 -- spec/presenters/show_presenter_spec.rb | 26 -- spec/test_app_templates/Gemfile.extra | 1 - 23 files changed, 37 insertions(+), 1144 deletions(-) delete mode 100644 app/helpers/blacklight/deprecated_url_helper_behavior.rb delete mode 100644 app/presenters/blacklight/document_presenter.rb delete mode 100644 spec/helpers/deprecated_url_helper_behavior_spec.rb delete mode 100644 spec/presenters/document_presenter_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a1ea3513cb..de306b000d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,12 +1,12 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-08-25 07:56:15 -0700 using RuboCop version 0.42.0. +# on 2016-09-07 07:22:49 -0700 using RuboCop version 0.42.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 19 +# Offense count: 17 # Cop supports --auto-correct. # Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. # SupportedStyles: keyword, variable, start_of_line @@ -14,7 +14,6 @@ Lint/EndAlignment: Exclude: - 'app/controllers/concerns/blacklight/token_based_user.rb' - 'app/helpers/blacklight/catalog_helper_behavior.rb' - - 'app/helpers/blacklight/deprecated_url_helper_behavior.rb' - 'app/helpers/blacklight/facets_helper_behavior.rb' - 'app/helpers/blacklight/render_partials_helper.rb' - 'app/helpers/blacklight/url_helper_behavior.rb' @@ -25,7 +24,7 @@ Lint/EndAlignment: - 'lib/blacklight/solr/response/facets.rb' - 'lib/blacklight/solr/search_builder_behavior.rb' -# Offense count: 30 +# Offense count: 26 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: @@ -33,7 +32,6 @@ Lint/UnusedBlockArgument: - 'app/controllers/concerns/blacklight/search_context.rb' - 'app/helpers/blacklight/configuration_helper_behavior.rb' - 'app/models/concerns/blacklight/document/dublin_core.rb' - - 'lib/blacklight/configuration.rb' - 'lib/blacklight/configuration/fields.rb' - 'lib/blacklight/engine.rb' - 'lib/blacklight/parameters.rb' @@ -42,17 +40,15 @@ Lint/UnusedBlockArgument: - 'lib/railties/blacklight.rake' - 'tasks/blacklight.rake' -# Offense count: 21 +# Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. Lint/UnusedMethodArgument: Exclude: - - 'app/controllers/concerns/blacklight/default_component_configuration.rb' - 'app/helpers/blacklight/blacklight_helper_behavior.rb' - 'app/helpers/blacklight/catalog_helper_behavior.rb' - 'app/helpers/blacklight/component_helper_behavior.rb' - 'app/helpers/blacklight/configuration_helper_behavior.rb' - - 'app/helpers/blacklight/deprecated_url_helper_behavior.rb' - 'app/helpers/blacklight/facets_helper_behavior.rb' - 'app/helpers/blacklight/render_partials_helper.rb' - 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb' @@ -62,11 +58,10 @@ Lint/UnusedMethodArgument: - 'lib/blacklight/search_builder.rb' - 'lib/blacklight/search_state.rb' -# Offense count: 9 +# Offense count: 7 Lint/UselessAssignment: Exclude: - 'app/controllers/concerns/blacklight/search_context.rb' - - 'app/helpers/blacklight/deprecated_url_helper_behavior.rb' - 'app/helpers/blacklight/facets_helper_behavior.rb' - 'app/models/bookmark.rb' - 'lib/blacklight/routes/exportable.rb' @@ -85,21 +80,21 @@ Metrics/BlockNesting: # Offense count: 2 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 200 + Max: 185 # Offense count: 20 Metrics/CyclomaticComplexity: Max: 12 -# Offense count: 59 +# Offense count: 54 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 52 + Max: 51 # Offense count: 9 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 213 + Max: 208 # Offense count: 1 # Configuration parameters: CountKeywordArgs. @@ -132,7 +127,7 @@ Style/Alias: - 'lib/blacklight/solr/response.rb' - 'lib/blacklight/solr/response/group_response.rb' -# Offense count: 7 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: with_first_parameter, with_fixed_indentation @@ -143,7 +138,7 @@ Style/AlignParameters: - 'lib/blacklight/configuration.rb' - 'lib/generators/blacklight/solr4_generator.rb' -# Offense count: 66 +# Offense count: 64 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: always, conditionals @@ -160,17 +155,15 @@ Style/BracesAroundHashParameters: - 'lib/blacklight/solr/response/facets.rb' - 'lib/generators/blacklight/test_support_generator.rb' -# Offense count: 13 +# Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep, IndentationWidth. # SupportedStyles: case, end Style/CaseIndentation: Exclude: - 'app/helpers/blacklight/catalog_helper_behavior.rb' - - 'app/helpers/blacklight/deprecated_url_helper_behavior.rb' - 'app/presenters/blacklight/index_presenter.rb' - 'lib/blacklight/configuration/fields.rb' - - 'lib/blacklight/search_builder.rb' # Offense count: 51 # Configuration parameters: EnforcedStyle, SupportedStyles. @@ -186,7 +179,7 @@ Style/ConditionalAssignment: Exclude: - 'lib/blacklight/solr/response/spelling.rb' -# Offense count: 104 +# Offense count: 103 Style/Documentation: Enabled: false @@ -216,7 +209,7 @@ Style/ElseAlignment: - 'lib/blacklight/solr/response/facets.rb' - 'lib/blacklight/solr/search_builder_behavior.rb' -# Offense count: 26 +# Offense count: 25 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. Style/ExtraSpacing: @@ -224,7 +217,6 @@ Style/ExtraSpacing: - 'app/helpers/blacklight/catalog_helper_behavior.rb' - 'app/helpers/blacklight/configuration_helper_behavior.rb' - 'app/models/concerns/blacklight/document/dublin_core.rb' - - 'app/models/concerns/blacklight/document/export.rb' - 'app/models/record_mailer.rb' - 'blacklight.gemspec' - 'config/routes.rb' @@ -254,7 +246,7 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 16 +# Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: MaxLineLength. Style/IfUnlessModifier: @@ -265,7 +257,6 @@ Style/IfUnlessModifier: - 'app/helpers/blacklight/catalog_helper_behavior.rb' - 'app/helpers/blacklight/url_helper_behavior.rb' - 'app/models/blacklight/facet_paginator.rb' - - 'lib/blacklight/configuration.rb' - 'lib/blacklight/configuration/fields.rb' - 'lib/blacklight/search_state.rb' - 'lib/generators/blacklight/install_generator.rb' @@ -279,7 +270,7 @@ Style/IndentHash: Exclude: - 'lib/blacklight/configuration.rb' -# Offense count: 23 +# Offense count: 22 # Cop supports --auto-correct. # Configuration parameters: Width. Style/IndentationWidth: @@ -308,7 +299,7 @@ Style/LeadingCommentSpace: - 'lib/blacklight/configuration.rb' - 'lib/blacklight/solr/response/spelling.rb' -# Offense count: 139 +# Offense count: 119 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline @@ -331,7 +322,7 @@ Style/MultilineMethodCallIndentation: - 'app/controllers/concerns/blacklight/search_helper.rb' - 'lib/blacklight/search_builder.rb' -# Offense count: 13 +# Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: aligned, indented @@ -372,7 +363,7 @@ Style/PredicateName: Style/RedundantSelf: Enabled: false -# Offense count: 24 +# Offense count: 17 # Cop supports --auto-correct. Style/SpaceAfterComma: Exclude: @@ -381,7 +372,6 @@ Style/SpaceAfterComma: - 'app/helpers/blacklight/facets_helper_behavior.rb' - 'app/helpers/blacklight/render_constraints_helper_behavior.rb' - 'app/models/concerns/blacklight/document/dublin_core.rb' - - 'lib/blacklight/configuration.rb' - 'lib/blacklight/configuration/fields.rb' - 'lib/blacklight/parameters.rb' - 'lib/blacklight/solr/response/facets.rb' @@ -397,7 +387,7 @@ Style/SpaceAroundBlockParameters: - 'app/controllers/concerns/blacklight/catalog.rb' - 'app/models/concerns/blacklight/document/extensions.rb' -# Offense count: 27 +# Offense count: 23 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: space, no_space @@ -408,15 +398,13 @@ Style/SpaceAroundEqualsInParameterDefault: - 'app/helpers/blacklight/component_helper_behavior.rb' - 'app/helpers/blacklight/configuration_helper_behavior.rb' - 'app/helpers/blacklight/facets_helper_behavior.rb' - - 'app/helpers/blacklight/render_partials_helper.rb' - 'app/helpers/blacklight/url_helper_behavior.rb' - 'app/models/concerns/blacklight/document.rb' - - 'app/presenters/blacklight/document_presenter.rb' - 'app/presenters/blacklight/index_presenter.rb' - 'app/presenters/blacklight/show_presenter.rb' - 'lib/blacklight/search_state.rb' -# Offense count: 13 +# Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Style/SpaceAroundOperators: @@ -426,7 +414,6 @@ Style/SpaceAroundOperators: - 'app/helpers/blacklight/facets_helper_behavior.rb' - 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb' - 'app/helpers/blacklight/url_helper_behavior.rb' - - 'app/models/concerns/blacklight/document/export.rb' - 'lib/blacklight/configuration.rb' - 'lib/blacklight/solr/repository.rb' - 'lib/blacklight/solr/response/spelling.rb' @@ -497,14 +484,13 @@ Style/SpaceInsideHashLiteralBraces: - 'lib/blacklight/configuration.rb' - 'lib/blacklight/solr/repository.rb' -# Offense count: 19 +# Offense count: 18 # Cop supports --auto-correct. Style/SpaceInsideParens: Exclude: - 'app/controllers/concerns/blacklight/search_context.rb' - 'app/helpers/blacklight/catalog_helper_behavior.rb' - 'app/helpers/blacklight/facets_helper_behavior.rb' - - 'app/helpers/blacklight/render_constraints_helper_behavior.rb' - 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb' - 'app/helpers/blacklight/url_helper_behavior.rb' - 'app/models/concerns/blacklight/document/dublin_core.rb' @@ -513,8 +499,7 @@ Style/SpaceInsideParens: - 'lib/blacklight/search_state.rb' - 'lib/blacklight/solr/search_builder_behavior.rb' -# Offense count: 217 +# Offense count: 197 # Cop supports --auto-correct. Style/TrailingWhitespace: Enabled: false - diff --git a/app/assets/stylesheets/blacklight/_facets.scss b/app/assets/stylesheets/blacklight/_facets.scss index 284a2e7736..f0f02b55c0 100644 --- a/app/assets/stylesheets/blacklight/_facets.scss +++ b/app/assets/stylesheets/blacklight/_facets.scss @@ -106,13 +106,6 @@ } -/* deprecated in Blacklight 5.x */ -ul.facet_extended_list, .facet_extended_list ul -{ - @extend .list-unstyled; - -} - .collapse-toggle { cursor: pointer; } diff --git a/app/helpers/blacklight/blacklight_helper_behavior.rb b/app/helpers/blacklight/blacklight_helper_behavior.rb index f9282a07af..f5a0d3244f 100644 --- a/app/helpers/blacklight/blacklight_helper_behavior.rb +++ b/app/helpers/blacklight/blacklight_helper_behavior.rb @@ -7,8 +7,6 @@ module Blacklight::BlacklightHelperBehavior include RenderConstraintsHelper include RenderPartialsHelper include FacetsHelper - extend Deprecation - self.deprecation_horizon = 'Blacklight version 7.0.0' ## # Get the name of this application, from either: @@ -137,45 +135,6 @@ def render_index_field_label *args html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: index_field_label(document, field)) end - ## - # Render the index field label for a document - # - # @overload render_index_field_value(options) - # Use the default, document-agnostic configuration - # @param [Hash] opts - # @option opts [String] :field - # @option opts [String] :value - # @option opts [String] :document - # @overload render_index_field_value(document, options) - # Allow an extention point where information in the document - # may drive the value of the field - # @param [SolrDocument] doc - # @param [Hash] opts - # @option opts [String] :field - # @option opts [String] :value - # @overload render_index_field_value(document, field, options) - # Allow an extention point where information in the document - # may drive the value of the field - # @param [SolrDocument] doc - # @param [String] field - # @param [Hash] opts - # @option opts [String] :value - # @deprecated use IndexPresenter#field_value - def render_index_field_value *args - render_field_value(*args) - end - deprecation_deprecate render_index_field_value: 'replaced by IndexPresenter#field_value' - - # @deprecated use IndexPresenter#field_value - def render_field_value(*args) - options = args.extract_options! - document = args.shift || options[:document] - - field = args.shift || options[:field] - presenter(document).field_value field, options.except(:document, :field) - end - deprecation_deprecate render_field_value: 'replaced by IndexPresenter#field_value' - ## # Render the show field label for a document # @@ -198,35 +157,6 @@ def render_document_show_field_label *args t(:'blacklight.search.show.label', label: document_show_field_label(document, field)) end - ## - # Render the index field label for a document - # - # @overload render_document_show_field_value(options) - # Use the default, document-agnostic configuration - # @param [Hash] opts - # @option opts [String] :field - # @option opts [String] :value - # @option opts [String] :document - # @overload render_document_show_field_value(document, options) - # Allow an extention point where information in the document - # may drive the value of the field - # @param [SolrDocument] doc - # @param [Hash] opts - # @option opts [String] :field - # @option opts [String] :value - # @overload render_document_show_field_value(document, field, options) - # Allow an extention point where information in the document - # may drive the value of the field - # @param [SolrDocument] doc - # @param [String] field - # @param [Hash] opts - # @option opts [String] :value - # @deprecated use ShowPresenter#field_value - def render_document_show_field_value *args - render_field_value(*args) - end - deprecation_deprecate render_document_show_field_value: 'replaced by ShowPresenter#field_value' - ## # Get the value of the document's "title" field, or a placeholder # value (if empty) @@ -269,24 +199,6 @@ def render_document_heading(*args) content_tag(tag, presenter(document).heading, itemprop: "name") end - ## - # Get the value for a document's field, and prepare to render it. - # - highlight_field - # - accessor - # - solr field - # - # Rendering: - # - helper_method - # - link_to_search - # @param [SolrDocument] document - # @param [String] _field name - # @param [Blacklight::Configuration::Field] field_config solr field configuration - # @param [Hash] options additional options to pass to the rendering helpers - def get_field_values document, _field, field_config, options = {} - presenter(document).field_values field_config, options - end - deprecation_deprecate :get_field_values - ## # Get the current "view type" (and ensure it is a valid type) # @@ -335,9 +247,6 @@ def presenter(document) show_presenter(document) when 'index' index_presenter(document) - else - Deprecation.warn(Blacklight::BlacklightHelperBehavior, "Unable to determine presenter type for #{action_name} on #{controller_name}, falling back on deprecated Blacklight::DocumentPresenter") - presenter_class.new(document, self) end end @@ -349,11 +258,6 @@ def index_presenter(document) index_presenter_class(document).new(document, self) end - def presenter_class - blacklight_config.document_presenter_class - end - deprecation_deprecate presenter_class: "replaced by show_presenter_class and index_presenter_class" - ## # Override this method if you want to use a different presenter class def show_presenter_class(_document) diff --git a/app/helpers/blacklight/deprecated_url_helper_behavior.rb b/app/helpers/blacklight/deprecated_url_helper_behavior.rb deleted file mode 100644 index e794767631..0000000000 --- a/app/helpers/blacklight/deprecated_url_helper_behavior.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true -module Blacklight - module DeprecatedUrlHelperBehavior - extend Deprecation - self.deprecation_horizon = 'blacklight 7.x' - - def params_for_search(*args, &block) - source_params, params_to_merge = case args.length - when 0 - search_state.params_for_search - when 1 - search_state.params_for_search(args.first) - when 2 - Deprecation.warn(Blacklight::DeprecatedUrlHelperBehavior, 'Use Blacklight::SearchState.new(source_params).params_for_search instead') - Blacklight::SearchState.new(args.first, blacklight_config).params_for_search(args.last) - else - raise ArgumentError, "wrong number of arguments (#{args.length} for 0..2)" - end - end - deprecation_deprecate :params_for_search - - def sanitize_search_params(source_params) - Blacklight::Parameters.sanitize(source_params) - end - deprecation_deprecate :sanitize_search_params - - def reset_search_params(source_params) - Blacklight::SearchState.new(source_params, blacklight_config).send(:reset_search_params) - end - deprecation_deprecate :reset_search_params - - def add_facet_params(field, item, source_params = nil) - if source_params - Deprecation.warn(Blacklight::DeprecatedUrlHelperBehavior, 'Use Blacklight::SearchState.new(source_params).add_facet_params instead') - - Blacklight::SearchState.new(source_params, blacklight_config).add_facet_params(field, item) - else - search_state.add_facet_params(field, item) - end - end - deprecation_deprecate :add_facet_params - - def remove_facet_params(field, item, source_params = nil) - if source_params - Deprecation.warn(Blacklight::DeprecatedUrlHelperBehavior, 'Use Blacklight::SearchState.new(source_params).remove_facet_params instead') - - Blacklight::SearchState.new(source_params, blacklight_config).remove_facet_params(field, item) - else - search_state.remove_facet_params(field, item) - end - end - deprecation_deprecate :remove_facet_params - - delegate :add_facet_params_and_redirect, to: :search_state - deprecation_deprecate :add_facet_params_and_redirect - end -end diff --git a/app/helpers/blacklight/facets_helper_behavior.rb b/app/helpers/blacklight/facets_helper_behavior.rb index a3389ba1e1..7c99b096c2 100644 --- a/app/helpers/blacklight/facets_helper_behavior.rb +++ b/app/helpers/blacklight/facets_helper_behavior.rb @@ -43,7 +43,6 @@ def render_facet_limit(display_facet, options = {}) options[:layout] ||= "facet_layout" unless options.key?(:layout) options[:locals] ||= {} options[:locals][:field_name] ||= display_facet.name - options[:locals][:solr_field] ||= display_facet.name # deprecated options[:locals][:facet_field] ||= facet_configuration_for_field(display_facet.name) options[:locals][:display_facet] ||= display_facet diff --git a/app/helpers/blacklight/url_helper_behavior.rb b/app/helpers/blacklight/url_helper_behavior.rb index 3ca8da7907..d7a19ef919 100644 --- a/app/helpers/blacklight/url_helper_behavior.rb +++ b/app/helpers/blacklight/url_helper_behavior.rb @@ -2,8 +2,6 @@ ## # URL helper methods module Blacklight::UrlHelperBehavior - include Blacklight::DeprecatedUrlHelperBehavior - ## # Extension point for downstream applications # to provide more interesting routing to diff --git a/app/presenters/blacklight/document_presenter.rb b/app/presenters/blacklight/document_presenter.rb deleted file mode 100644 index 71e9bc21cf..0000000000 --- a/app/presenters/blacklight/document_presenter.rb +++ /dev/null @@ -1,153 +0,0 @@ -# frozen_string_literal: true -module Blacklight - # @deprecated - class DocumentPresenter - extend Deprecation - self.deprecation_horizon = 'Blacklight version 7.0.0' - - # @param [SolrDocument] document - # @param [ActionController::Base] controller scope for linking and generating urls - # @param [Blacklight::Configuration] configuration - def initialize(document, controller, configuration = controller.blacklight_config) - @document = document - @configuration = configuration - @controller = controller - end - - ## - # Get the value of the document's "title" field, or a placeholder - # value (if empty) - # - # @return [String] - # @deprecated use ShowPresenter#heading instead - def document_heading - show_presenter.heading - end - deprecation_deprecate document_heading: "use ShowPresenter#heading instead" - - ## - # Create links from a documents dynamically - # provided export formats. Returns empty string if no links available. - # - # @param [Hash] options - # @option options [Boolean] :unique ensures only one link is output for every - # content type, e.g. as required by atom - # @option options [Array] :exclude array of format shortnames to not include in the output - # @deprecated moved to ShowPresenter#link_rel_alternates - def link_rel_alternates(options = {}) - show_presenter.link_rel_alternates(options) - end - deprecation_deprecate link_rel_alternates: "use ShowPresenter#link_rel_alternates instead" - - ## - # Get the document's "title" to display in the element. - # (by default, use the #document_heading) - # - # @see #document_heading - # @return [String] - # @deprecated use ShowPresenter#html_title instead - def document_show_html_title - show_presenter.html_title - end - deprecation_deprecate document_show_html_title: "use ShowPresenter#html_title instead" - - ## - # Render the document index heading - # - # @overload render_document_index_label(field, opts) - # @param [Symbol, Proc, String] field Render the given field or evaluate the proc or render the given string - # @param [Hash] opts - # @deprecated use IndexPresenter#label instead - def render_document_index_label(*args) - index_presenter.label(*args) - end - deprecation_deprecate render_document_index_label: "use IndexPresenter#label instead" - - ## - # Render the index field label for a document - # - # Allow an extention point where information in the document - # may drive the value of the field - # @overload render_index_field_value(field, opts) - # @param [String] field - # @param [Hash] opts - # @option opts [String] :value - # @deprecated use IndexPresenter#field_value instead - def render_index_field_value *args - index_presenter.field_value(*args) - end - deprecation_deprecate render_index_field_value: "use IndexPresenter#field_value instead" - - ## - # Render the show field value for a document - # - # Allow an extention point where information in the document - # may drive the value of the field - # - # @overload render_index_field_value(field, options) - # @param [String] field - # @param [Hash] options - # @option options [String] :value - # @deprecated use ShowPresenter#field_value - def render_document_show_field_value *args - show_presenter.field_value(*args) - end - deprecation_deprecate render_document_show_field_value: "use ShowPresenter#field_value instead" - - ## - # Get the value for a document's field, and prepare to render it. - # - highlight_field - # - accessor - # - solr field - # - # Rendering: - # - helper_method - # - link_to_search - # @param [String] _field name - # @param [Blacklight::Configuration::Field] field_config solr field configuration - # @param [Hash] options additional options to pass to the rendering helpers - # @deprecated - def get_field_values _field, field_config, options = {} - field_values(field_config, options) - end - deprecation_deprecate get_field_values: 'Use field_values instead' - - ## - # Get the value for a document's field, and prepare to render it. - # - highlight_field - # - accessor - # - solr field - # - # Rendering: - # - helper_method - # - link_to_search - # @param [Blacklight::Configuration::Field] field_config solr field configuration - # @param [Hash] options additional options to pass to the rendering helpers - def field_values(field_config, options={}) - FieldPresenter.new(@controller, @document, field_config, options).render - end - deprecation_deprecate field_values: 'Use ShowPresenter or IndexPresenter field_values instead' - - # @deprecated - def render_field_value(values, field_config = Configuration::NullField.new) - field_values(field_config, value: Array(values)) - end - deprecation_deprecate render_field_value: 'Use FieldPresenter instead' - - # @deprecated - def render_values(values, field_config = Configuration::NullField.new) - field_values(field_config, value: Array(values)) - end - deprecation_deprecate render_values: 'Use FieldPresenter instead' - - private - - def index_presenter - @controller.index_presenter(@document) - end - - def show_presenter - @controller.show_presenter(@document) - end - end -end diff --git a/app/presenters/blacklight/index_presenter.rb b/app/presenters/blacklight/index_presenter.rb index 1f8a5ae486..f6283d0ff6 100644 --- a/app/presenters/blacklight/index_presenter.rb +++ b/app/presenters/blacklight/index_presenter.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true module Blacklight class IndexPresenter - extend Deprecation - self.deprecation_horizon = 'Blacklight version 7.0.0' - attr_reader :document, :configuration, :view_context # @param [SolrDocument] document @@ -37,12 +34,6 @@ def label(field_or_string_or_proc, opts = {}) field_values(config, value: value) end - # @deprecated - def render_document_index_label(*args) - label(*args) - end - deprecation_deprecate render_document_index_label: 'Use #label instead' - ## # Render the index field label for a document # @@ -56,30 +47,6 @@ def field_value field, options = {} field_values(field_config, options) end - # @deprecated - def render_index_field_value(*args) - field_value(*args) - end - deprecation_deprecate render_index_field_value: 'replaced by #field_value' - - # @deprecated - def get_field_values(field_config, options={}) - field_values(field_config, options) - end - deprecation_deprecate get_field_values: "replaced by #field_value" - - # @deprecated - def render_field_values(values, field_config = Configuration::NullField.new) - field_values(field_config, value: Array(values)) - end - deprecation_deprecate render_field_values: "replaced by #field_value" - - # @deprecated - def render_values(values, field_config = Configuration::NullField.new) - field_values(field_config, value: Array(values)) - end - deprecation_deprecate render_values: "replaced by #field_value" - private ## diff --git a/app/presenters/blacklight/show_presenter.rb b/app/presenters/blacklight/show_presenter.rb index 0640a4e719..1f6f5bf0b6 100644 --- a/app/presenters/blacklight/show_presenter.rb +++ b/app/presenters/blacklight/show_presenter.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true module Blacklight class ShowPresenter - extend Deprecation - self.deprecation_horizon = 'Blacklight version 7.0.0' - attr_reader :document, :configuration, :view_context # @param [SolrDocument] document @@ -23,7 +20,6 @@ def initialize(document, view_context, configuration = view_context.blacklight_c # @option options [Boolean] :unique ensures only one link is output for every # content type, e.g. as required by atom # @option options [Array<String>] :exclude array of format shortnames to not include in the output - # @deprecated moved to ShowPresenter#link_rel_alternates def link_rel_alternates(options = {}) LinkAlternatePresenter.new(view_context, document, options).render end @@ -45,12 +41,6 @@ def html_title end end - # @deprecated - def document_show_html_title - html_title - end - deprecation_deprecate document_show_html_title: "use #html_title" - ## # Get the value of the document's "title" field, or a placeholder # value (if empty) @@ -63,12 +53,6 @@ def heading field_values(field_config(f), value: document[f]) end - # @deprecated - def document_heading - heading - end - deprecation_deprecate document_heading: "replaced by #heading" - ## # Render the show field value for a document # @@ -81,30 +65,6 @@ def field_value field, options={} field_values(field_config(field), options) end - # @deprecated - def render_document_show_field_value(*args) - field_value(*args) - end - deprecation_deprecate render_document_show_field_value: 'replaced by #field_value' - - # @deprecated - def get_field_values(field_config, options={}) - field_values(field_config, options) - end - deprecation_deprecate get_field_values: "replaced by #field_value" - - # @deprecated - def render_field_values(values, field_config = Configuration::NullField.new) - field_values(field_config, value: Array(values)) - end - deprecation_deprecate render_field_values: "replaced by #field_value" - - # @deprecated - def render_values(values, field_config = Configuration::NullField.new) - field_values(field_config, value: Array(values)) - end - deprecation_deprecate render_values: "replaced by #field_value" - private ## diff --git a/app/views/catalog/_previous_next_doc.html.erb b/app/views/catalog/_previous_next_doc.html.erb index 8f8ae7b2f3..f92e1a27e0 100644 --- a/app/views/catalog/_previous_next_doc.html.erb +++ b/app/views/catalog/_previous_next_doc.html.erb @@ -1,6 +1,5 @@ <% #Using the Bootstrap Pagination class -%> -<% #DEPRECATED - using id="previousNextDocument" as a selector is deprecated and will be removed in Blacklight 6.0 %> -<div id='previousNextDocument' class='pagination-search-widgets'> +<div class='pagination-search-widgets'> <% if @previous_document || @next_document %> <div class="page_links"> <%= link_to_previous_document @previous_document %> | diff --git a/lib/blacklight/configuration.rb b/lib/blacklight/configuration.rb index 232c215cd2..00de3257ae 100644 --- a/lib/blacklight/configuration.rb +++ b/lib/blacklight/configuration.rb @@ -66,8 +66,6 @@ def default_values response_model: nil, # the model to use for each response document document_model: nil, - # document presenter class used by helpers and views - document_presenter_class: nil, # deprecated # Class for paginating long lists of facet fields facet_paginator_class: nil, # repository connection configuration @@ -190,17 +188,6 @@ def response_model super || Blacklight::Solr::Response end - # @deprecated - def document_presenter_class - super || Blacklight::DocumentPresenter - end - - # @deprecated - def document_presenter_class=(klass) - super - end - deprecation_deprecate :document_presenter_class= => "replaced by show.presenter_class and index.presenter_class" - def response_model=(*args) super end diff --git a/lib/blacklight/exceptions.rb b/lib/blacklight/exceptions.rb index 5f23d68637..09857ee163 100644 --- a/lib/blacklight/exceptions.rb +++ b/lib/blacklight/exceptions.rb @@ -4,13 +4,7 @@ module Exceptions class AccessDenied < StandardError end - # When a request for a single solr document by id - # is not successful, we can raise this exception. - # Deprecated; this will be removed in Blacklight 6.0: - class InvalidSolrID < RuntimeError - end - # In Blacklight 6.0, this exception can subclass RuntimeError directly - class RecordNotFound < InvalidSolrID + class RecordNotFound < RuntimeError end class InvalidRequest < StandardError diff --git a/lib/blacklight/search_builder.rb b/lib/blacklight/search_builder.rb index 9dc44562db..57d917dd4e 100644 --- a/lib/blacklight/search_builder.rb +++ b/lib/blacklight/search_builder.rb @@ -5,7 +5,6 @@ module Blacklight # query parameters appropriate for search index. It does so by evaluating a # chain of processing methods to populate a result hash (see {#to_hash}). class SearchBuilder - extend Deprecation class_attribute :default_processor_chain self.default_processor_chain = [] @@ -18,21 +17,16 @@ class SearchBuilder # @param [List<Symbol>,TrueClass] processor_chain options a list of filter methods to run or true, to use the default methods # @param [Object] scope scope the scope where the filter methods reside in. def initialize(*options) - @scope = case options.size + case options.size when 1 - options.first + @processor_chain = default_processor_chain.dup + @scope = options.first when 2 - if options.first == true - Deprecation.warn Blacklight::SearchBuilder, "SearchBuilder#initialize now takes only one parameter, the scope. Passing `true' will be removed in Blacklight 7" - else - @processor_chain = options.first - end - options.last + @processor_chain, @scope = options else raise ArgumentError, "wrong number of arguments. (#{options.size} for 1..2)" end - - @processor_chain ||= default_processor_chain.dup + @blacklight_params = {} @merged_params = {} @reverse_merged_params = {} diff --git a/lib/blacklight/solr/response.rb b/lib/blacklight/solr/response.rb index b9a9adf4a6..86c03f9e2c 100644 --- a/lib/blacklight/solr/response.rb +++ b/lib/blacklight/solr/response.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true class Blacklight::Solr::Response < ActiveSupport::HashWithIndifferentAccess - extend Deprecation - # Using required_dependency to work around Rails autoloading # problems when developing blacklight. Without this, any change # to this class breaks other classes in this namespace diff --git a/spec/helpers/blacklight_helper_spec.rb b/spec/helpers/blacklight_helper_spec.rb index b485404055..3b1c37b39c 100644 --- a/spec/helpers/blacklight_helper_spec.rb +++ b/spec/helpers/blacklight_helper_spec.rb @@ -34,7 +34,7 @@ describe "render_link_rel_alternates" do let(:document) { instance_double(SolrDocument) } let(:result) { double } - let(:presenter) { Blacklight::DocumentPresenter.new(document, self) } + let(:presenter) { Blacklight::IndexPresenter.new(document, self) } let(:blacklight_config) do Blacklight::Configuration.new.configure do |config| config.index.title_field = 'title_display' @@ -151,50 +151,6 @@ end end - context "render methods" do - let(:field) { "some_field" } - let(:doc) { instance_double(SolrDocument) } - let(:presenter) { instance_double(Blacklight::ShowPresenter) } - before do - allow(Deprecation).to receive(:warn) # TODO: purge Deprecations - allow(helper).to receive(:presenter).with(doc).and_return(presenter) - end - - describe "#render_index_field_value" do - it "passes the document and field through to the presenter" do - expect(presenter).to receive(:field_value).with(field, {}) - helper.render_index_field_value(doc, field) - end - - it "allows the document and field to be passed as hash arguments" do - expect(presenter).to receive(:field_value).with(field, {}) - helper.render_index_field_value(document: doc, field: field) - end - - it "allows additional options to be passed to the presenter" do - expect(presenter).to receive(:field_value).with(field, x: 1) - helper.render_index_field_value(document: doc, field: field, x: 1) - end - end - - describe "#render_document_show_field_value" do - it "passes the document and field through to the presenter" do - expect(presenter).to receive(:field_value).with(field, {}) - helper.render_document_show_field_value(doc, field) - end - - it "allows the document and field to be passed as hash arguments" do - expect(presenter).to receive(:field_value).with(field, {}) - helper.render_document_show_field_value(document: doc, field: field) - end - - it "allows additional options to be passed to the presenter" do - expect(presenter).to receive(:field_value).with(field, x: 1) - helper.render_document_show_field_value(document: doc, field: field, x: 1) - end - end - end - describe "#document_has_value?" do let(:doc) { double(SolrDocument) } it "ifs the document has the field value" do @@ -413,19 +369,6 @@ allow(helper).to receive(:blacklight_config).and_return(blacklight_config) end - describe "#presenter_class" do - it "uses the value defined in the blacklight configuration" do - expect(Deprecation).to receive(:warn).exactly(2).times - blacklight_config.document_presenter_class = presenter_class - expect(helper.presenter_class).to eq presenter_class - end - - it "defaults to Blacklight::DocumentPresenter" do - expect(Deprecation).to receive(:warn) - expect(helper.presenter_class).to eq Blacklight::DocumentPresenter - end - end - describe "#index_presenter_class" do it "uses the value defined in the blacklight configuration" do blacklight_config.index.document_presenter_class = presenter_class diff --git a/spec/helpers/deprecated_url_helper_behavior_spec.rb b/spec/helpers/deprecated_url_helper_behavior_spec.rb deleted file mode 100644 index 6ad6296e00..0000000000 --- a/spec/helpers/deprecated_url_helper_behavior_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -# frozen_string_literal: true - -describe Blacklight::DeprecatedUrlHelperBehavior do - around do |test| - Deprecation.silence(described_class) do - test.call - end - end - - let(:parameter_class) { ActionController::Parameters } - let(:search_state) { Blacklight::SearchState.new(params, blacklight_config) } - let(:params) { parameter_class.new } - let(:blacklight_config) { Blacklight::Configuration.new } - - before do - allow(helper).to receive(:search_state).and_return(search_state) - allow(helper).to receive(:params).and_return(params) - allow(helper).to receive(:blacklight_config).and_return(blacklight_config) - end - - describe '#params_for_search' do - it 'passes through to the search state' do - expect(helper.params_for_search).to eq search_state.params_for_search - end - - it 'passes arguments through to the search state' do - expect(helper.params_for_search(merge: 1)).to eq search_state.params_for_search(merge: 1) - end - - it 'generates a search state for the source parameters' do - expect(helper.params_for_search(parameter_class.new(source: 1), { merge: 1 })).to include merge: 1, source: 1 - end - end - - describe '#sanitize_search_params' do - it 'passes through to the parameter sanitizer' do - expect(helper.sanitize_search_params(a: 1)).to eq Blacklight::Parameters.sanitize(a: 1) - end - end - - describe '#reset_search_params' do - let(:source_parameters) { parameter_class.new page: 1, counter: 10 } - it 'resets the current page and counter' do - expect(helper.reset_search_params(source_parameters)).to be_blank - end - end - - describe '#add_facet_params' do - before do - blacklight_config.add_facet_field 'x' - end - - let(:field) { blacklight_config.facet_fields['x'] } - let(:item) { true } - - it 'passes through to the search state' do - expect(helper.add_facet_params(field, item)).to eq search_state.add_facet_params(field, item) - end - - context "with source_parameters" do - let(:source_parameters) { parameter_class.new source: 1 } - it 'generates a search state for the source parameters' do - expect(helper.add_facet_params(field, item, source_parameters)).to include source: 1 - end - end - end - - describe '#add_facet_params_and_redirect' do - before do - blacklight_config.add_facet_field 'x' - end - - let(:field) { blacklight_config.facet_fields['x'] } - let(:item) { true } - - it 'passes through to the search state' do - expect(helper.add_facet_params_and_redirect(field, item)).to eq search_state.add_facet_params_and_redirect(field, item) - end - end - - describe '#remove_facet_params' do - before do - blacklight_config.add_facet_field 'x' - end - - let(:field) { blacklight_config.facet_fields['x'] } - let(:item) { true } - - it 'passes through to the search state' do - expect(helper.remove_facet_params(field, item)).to eq search_state.remove_facet_params(field, item) - end - - context "with source_parameters" do - let(:source_parameters) { parameter_class.new source: 1 } - it 'generates a search state for the source parameters' do - expect(helper.remove_facet_params(field, item, source_parameters)).to include source: 1 - end - end - end -end diff --git a/spec/helpers/facets_helper_spec.rb b/spec/helpers/facets_helper_spec.rb index a124857ef1..45befea932 100644 --- a/spec/helpers/facets_helper_spec.rb +++ b/spec/helpers/facets_helper_spec.rb @@ -149,7 +149,6 @@ mock_facet = double(:name => 'basic_field', :items => [1, 2, 3]) expect(helper).to receive(:render).with(hash_including(:partial => 'facet_limit', :locals => { - :solr_field => 'basic_field', :field_name => 'basic_field', :facet_field => helper.blacklight_config.facet_fields['basic_field'], :display_facet => mock_facet } diff --git a/spec/models/blacklight/search_builder_spec.rb b/spec/models/blacklight/search_builder_spec.rb index 0a448fb4a9..84ffbba92e 100644 --- a/spec/models/blacklight/search_builder_spec.rb +++ b/spec/models/blacklight/search_builder_spec.rb @@ -7,22 +7,9 @@ subject { described_class.new processor_chain, scope } context "with default processor chain" do - context "with two arguments" do - subject do - Deprecation.silence Blacklight::SearchBuilder do - described_class.new true, scope - end - end - it "uses the class-level default_processor_chain" do - expect(subject.processor_chain).to eq [] - end - end - - context "with one arguments" do - subject { described_class.new scope } - it "uses the class-level default_processor_chain" do - expect(subject.processor_chain).to eq [] - end + subject { described_class.new scope } + it "uses the class-level default_processor_chain" do + expect(subject.processor_chain).to eq [] end end diff --git a/spec/models/blacklight/solr/search_builder_spec.rb b/spec/models/blacklight/solr/search_builder_spec.rb index 01e2961a14..7781faafc6 100644 --- a/spec/models/blacklight/solr/search_builder_spec.rb +++ b/spec/models/blacklight/solr/search_builder_spec.rb @@ -22,22 +22,9 @@ subject { search_builder.with(user_params) } context "with default processor chain" do - context "with two arguments" do - subject do - Deprecation.silence Blacklight::SearchBuilder do - search_builder_class.new true, context - end - end - it "uses the class-level default_processor_chain" do - expect(subject.processor_chain).to eq search_builder_class.default_processor_chain - end - end - - context "with one arguments" do - subject { search_builder } - it "uses the class-level default_processor_chain" do - expect(subject.processor_chain).to eq search_builder_class.default_processor_chain - end + subject { search_builder } + it "uses the class-level default_processor_chain" do + expect(subject.processor_chain).to eq search_builder_class.default_processor_chain end end diff --git a/spec/presenters/document_presenter_spec.rb b/spec/presenters/document_presenter_spec.rb deleted file mode 100644 index 5bbd7caae1..0000000000 --- a/spec/presenters/document_presenter_spec.rb +++ /dev/null @@ -1,438 +0,0 @@ -# frozen_string_literal: true - -describe Blacklight::DocumentPresenter do - include Capybara::RSpecMatchers - let(:show_presenter) { Blacklight::ShowPresenter.new(document, request_context, config) } - let(:index_presenter) { Blacklight::IndexPresenter.new(document, request_context, config) } - let(:request_context) { double } - let(:config) { Blacklight::Configuration.new } - - subject { presenter } - let(:presenter) { described_class.new(document, request_context, config) } - let(:parameter_class) { ActionController::Parameters } - let(:params) { parameter_class.new } - let(:search_state) { Blacklight::SearchState.new(params, config) } - - let(:document) do - SolrDocument.new(id: 1, - 'link_to_search_true' => 'x', - 'link_to_search_named' => 'x', - 'qwer' => 'document qwer value', - 'mnbv' => 'document mnbv value') - end - - before do - allow(request_context).to receive(:search_state).and_return(search_state) - allow(Deprecation).to receive(:warn) - end - - describe "link_rel_alternates" do - before do - class MockDocument - include Blacklight::Solr::Document - end - - module MockExtension - def self.extended(document) - document.will_export_as(:weird, "application/weird") - document.will_export_as(:weirder, "application/weirder") - document.will_export_as(:weird_dup, "application/weird") - end - def export_as_weird ; "weird" ; end - def export_as_weirder ; "weirder" ; end - def export_as_weird_dup ; "weird_dup" ; end - end - - MockDocument.use_extension(MockExtension) - - def mock_document_app_helper_url *args - solr_document_url(*args) - end - - allow(request_context).to receive(:polymorphic_url) do |_, opts| - "url.#{opts[:format]}" - end - allow(request_context).to receive(:show_presenter).and_return(show_presenter) - end - - let(:document) { MockDocument.new(id: "MOCK_ID1") } - - context "with no arguments" do - subject { presenter.link_rel_alternates } - - it "generates <link rel=alternate> tags" do - tmp_value = Capybara.ignore_hidden_elements - Capybara.ignore_hidden_elements = false - document.export_formats.each_pair do |format, spec| - expect(subject).to have_selector("link[href$='.#{ format }']") do |matches| - expect(matches).to have(1).match - tag = matches[0] - expect(tag.attributes["rel"].value).to eq "alternate" - expect(tag.attributes["title"].value).to eq format.to_s - expect(tag.attributes["href"].value).to eq mock_document_app_helper_url(document, format: format) - end - end - Capybara.ignore_hidden_elements = tmp_value - end - - it { is_expected.to be_html_safe } - end - - context "with unique: true" do - subject { presenter.link_rel_alternates(unique: true) } - - it "respects unique: true" do - tmp_value = Capybara.ignore_hidden_elements - Capybara.ignore_hidden_elements = false - expect(subject).to have_selector("link[type='application/weird']", count: 1) - Capybara.ignore_hidden_elements = tmp_value - end - end - - context "with exclude" do - subject { presenter.link_rel_alternates(unique: true) } - it "excludes formats from :exclude" do - tmp_value = Capybara.ignore_hidden_elements - Capybara.ignore_hidden_elements = false - expect(subject).to_not have_selector("link[href$='.weird_dup']") - Capybara.ignore_hidden_elements = tmp_value - end - end - end - - describe "render_index_field_value" do - let(:config) do - Blacklight::Configuration.new.configure do |config| - config.add_index_field 'qwer' - config.add_index_field 'asdf', :helper_method => :render_asdf_index_field - config.add_index_field 'link_to_search_true', :link_to_search => true - config.add_index_field 'link_to_search_named', :link_to_search => :some_field - config.add_index_field 'highlight', :highlight => true - config.add_index_field 'solr_doc_accessor', :accessor => true - config.add_index_field 'explicit_accessor', :accessor => :solr_doc_accessor - config.add_index_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg - config.add_index_field 'alias', field: 'qwer' - config.add_index_field 'with_default', default: 'value' - end - end - before do - allow(request_context).to receive(:index_presenter).and_return(index_presenter) - end - it "checks for an explicit value" do - value = subject.render_index_field_value 'asdf', :value => 'asdf' - expect(value).to eq 'asdf' - end - - it "checks for a helper method to call" do - allow(request_context).to receive(:render_asdf_index_field).and_return('custom asdf value') - value = subject.render_index_field_value 'asdf' - expect(value).to eq 'custom asdf value' - end - - it "checks for a link_to_search" do - allow(request_context).to receive(:search_action_path).with('f' => { 'link_to_search_true' => ['x'] }).and_return('/foo') - allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar') - value = subject.render_index_field_value 'link_to_search_true' - expect(value).to eq 'bar' - end - - it "checks for a link_to_search with a field name" do - allow(request_context).to receive(:search_action_path).with('f' => { 'some_field' => ['x'] }).and_return('/foo') - allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar') - value = subject.render_index_field_value 'link_to_search_named' - expect(value).to eq 'bar' - end - - context "when no highlight field is available" do - before do - allow(document).to receive(:has_highlight_field?).and_return(false) - end - let(:value) { subject.render_index_field_value 'highlight' } - it "is blank" do - expect(value).to be_blank - end - end - - it "checks for a highlighted field" do - allow(document).to receive(:has_highlight_field?).and_return(true) - allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe]) - value = subject.render_index_field_value 'highlight' - expect(value).to eq '<em>highlight</em>' - end - - it "checks the document field value" do - value = subject.render_index_field_value 'qwer' - expect(value).to eq 'document qwer value' - end - - it "works with index fields that aren't explicitly defined" do - value = subject.render_index_field_value 'mnbv' - expect(value).to eq 'document mnbv value' - end - - it "calls an accessor on the solr document" do - allow(document).to receive_messages(solr_doc_accessor: "123") - value = subject.render_index_field_value 'solr_doc_accessor' - expect(value).to eq "123" - end - - it "calls an explicit accessor on the solr document" do - allow(document).to receive_messages(solr_doc_accessor: "123") - value = subject.render_index_field_value 'explicit_accessor' - expect(value).to eq "123" - end - - it "calls an accessor on the solr document with the field as an argument" do - allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123") - value = subject.render_index_field_value 'explicit_accessor_with_arg' - expect(value).to eq "123" - end - - it "supports solr field configuration" do - value = subject.render_index_field_value 'alias' - expect(value).to eq "document qwer value" - end - - it "supports default values in the field configuration" do - value = subject.render_index_field_value 'with_default' - expect(value).to eq "value" - end - end - - describe "render_document_show_field_value" do - let(:config) do - Blacklight::Configuration.new.configure do |config| - config.add_show_field 'qwer' - config.add_show_field 'asdf', :helper_method => :render_asdf_document_show_field - config.add_show_field 'link_to_search_true', :link_to_search => true - config.add_show_field 'link_to_search_named', :link_to_search => :some_field - config.add_show_field 'highlight', :highlight => true - config.add_show_field 'solr_doc_accessor', :accessor => true - config.add_show_field 'explicit_accessor', :accessor => :solr_doc_accessor - config.add_show_field 'explicit_array_accessor', :accessor => [:solr_doc_accessor, :some_method] - config.add_show_field 'explicit_accessor_with_arg', :accessor => :solr_doc_accessor_with_arg - end - end - - before do - allow(request_context).to receive(:show_presenter).and_return(show_presenter) - end - - it 'html-escapes values' do - value = subject.render_document_show_field_value 'asdf', value: '<b>val1</b>' - expect(value).to eq '<b>val1</b>' - end - - it 'joins multivalued valued fields' do - value = subject.render_document_show_field_value 'asdf', value: ['<a', 'b'] - expect(value).to eq '<a and b' - end - - it 'joins multivalued valued fields' do - value = subject.render_document_show_field_value 'asdf', value: ['a', 'b', 'c'] - expect(value).to eq 'a, b, and c' - end - - it "checks for an explicit value" do - expect(request_context).to_not receive(:render_asdf_document_show_field) - value = subject.render_document_show_field_value 'asdf', :value => 'val1' - expect(value).to eq 'val1' - end - - it "checks for a helper method to call" do - allow(request_context).to receive(:render_asdf_document_show_field).and_return('custom asdf value') - value = subject.render_document_show_field_value 'asdf' - expect(value).to eq 'custom asdf value' - end - - it "checks for a link_to_search" do - allow(request_context).to receive(:search_action_path).and_return('/foo') - allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar') - value = subject.render_document_show_field_value 'link_to_search_true' - expect(value).to eq 'bar' - end - - it "checks for a link_to_search with a field name" do - allow(request_context).to receive(:search_action_path).and_return('/foo') - allow(request_context).to receive(:link_to).with("x", '/foo').and_return('bar') - value = subject.render_document_show_field_value 'link_to_search_named' - expect(value).to eq 'bar' - end - - context "when no highlight field is available" do - before do - allow(document).to receive(:has_highlight_field?).and_return(false) - end - let(:value) { subject.render_document_show_field_value 'highlight' } - it "is blank" do - expect(value).to be_blank - end - end - - it "checks for a highlighted field" do - allow(document).to receive(:has_highlight_field?).and_return(true) - allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe]) - value = subject.render_document_show_field_value 'highlight' - expect(value).to eq '<em>highlight</em>' - end - - it 'respects the HTML-safeness of multivalued highlight fields' do - allow(document).to receive(:has_highlight_field?).and_return(true) - allow(document).to receive(:highlight_field).with('highlight').and_return(['<em>highlight</em>'.html_safe, '<em>other highlight</em>'.html_safe]) - value = subject.render_document_show_field_value 'highlight' - expect(value).to eq '<em>highlight</em> and <em>other highlight</em>' - end - - it "checks the document field value" do - value = subject.render_document_show_field_value 'qwer' - expect(value).to eq 'document qwer value' - end - - it "works with show fields that aren't explicitly defined" do - value = subject.render_document_show_field_value 'mnbv' - expect(value).to eq 'document mnbv value' - end - - it "calls an accessor on the solr document" do - allow(document).to receive_messages(solr_doc_accessor: "123") - value = subject.render_document_show_field_value 'solr_doc_accessor' - expect(value).to eq "123" - end - - it "calls an explicit accessor on the solr document" do - allow(document).to receive_messages(solr_doc_accessor: "123") - value = subject.render_document_show_field_value 'explicit_accessor' - expect(value).to eq "123" - end - - it "calls an explicit array-style accessor on the solr document" do - allow(document).to receive_message_chain(:solr_doc_accessor, some_method: "123") - value = subject.render_document_show_field_value 'explicit_array_accessor' - expect(value).to eq "123" - end - - it "calls an accessor on the solr document with the field as an argument" do - allow(document).to receive(:solr_doc_accessor_with_arg).with('explicit_accessor_with_arg').and_return("123") - value = subject.render_document_show_field_value 'explicit_accessor_with_arg' - expect(value).to eq "123" - end - end - describe "render_field_value" do - before do - expect(Deprecation).to receive(:warn) - end - it "joins and html-safe values" do - expect(subject.render_field_value(['a', 'b'])).to eq "a and b" - end - - context "with separator_options" do - let(:field_config) { double(to_h: { field: 'foo', separator: nil, itemprop: nil, separator_options: { two_words_connector: '; '}}) } - it "uses the field_config.separator_options" do - expect(subject.render_field_value(['c', 'd'], field_config)).to eq "c; d" - end - end - - context "with itemprop attributes" do - let(:field_config) { double(to_h: { field: 'bar', separator: nil, itemprop: 'some-prop', separator_options: nil }) } - it "includes schema.org itemprop attributes" do - expect(subject.render_field_value('a', field_config)).to have_selector("span[@itemprop='some-prop']", :text => "a") - end - end - end - - describe "#document_heading" do - before do - allow(request_context).to receive(:show_presenter).and_return(show_presenter) - end - it "falls back to an id" do - allow(document).to receive(:[]).with('id').and_return "xyz" - expect(subject.document_heading).to eq document.id - end - - it "returns the value of the field" do - config.show.title_field = :x - allow(document).to receive(:has?).with(:x).and_return(true) - allow(document).to receive(:[]).with(:x).and_return("value") - expect(subject.document_heading).to eq "value" - end - - it "returns the first present value" do - config.show.title_field = [:x, :y] - allow(document).to receive(:has?).with(:x).and_return(false) - allow(document).to receive(:has?).with(:y).and_return(true) - allow(document).to receive(:[]).with(:y).and_return("value") - expect(subject.document_heading).to eq "value" - end - end - - describe "#document_show_html_title" do - before do - allow(request_context).to receive(:show_presenter).and_return(show_presenter) - end - it "falls back to an id" do - allow(document).to receive(:[]).with('id').and_return "xyz" - expect(subject.document_show_html_title).to eq document.id - end - - it "returns the value of the field" do - config.show.html_title_field = :x - allow(document).to receive(:has?).with(:x).and_return(true) - allow(document).to receive(:fetch).with(:x, nil).and_return("value") - expect(subject.document_show_html_title).to eq "value" - end - - it "returns the first present value" do - config.show.html_title_field = [:x, :y] - allow(document).to receive(:has?).with(:x).and_return(false) - allow(document).to receive(:has?).with(:y).and_return(true) - allow(document).to receive(:fetch).with(:y, nil).and_return("value") - expect(subject.document_show_html_title).to eq "value" - end - end - - describe '#get_field_values' do - let(:field_config) { double } - let(:options) { double } - it "calls field_values" do - expect(Deprecation).to receive(:warn) - expect(presenter).to receive(:field_values).with(field_config, options) - presenter.get_field_values('name', field_config, options) - end - end - - describe '#field_values' do - context 'for a field with the helper_method option' do - let(:field_name) { 'field_with_helper' } - let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' } - - before do - document['field_with_helper'] = 'value' - end - - it "checks call the helper method with arguments" do - allow(request_context).to receive(:render_field_with_helper) do |*args| - args.first - end - - render_options = { a: 1 } - - options = subject.field_values field_config, a: 1 - - expect(options).to include :document, :field, :value, :config, :a - expect(options[:document]).to eq document - expect(options[:field]).to eq 'field_with_helper' - expect(options[:value]).to eq ['value'] - expect(options[:config]).to eq field_config - expect(options[:a]).to eq 1 - end - end - end - - describe '#render_values' do - it 'renders field values as a string' do - expect(subject.render_values('x')).to eq 'x' - expect(subject.render_values(['x', 'y'])).to eq 'x and y' - expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z' - end - end -end diff --git a/spec/presenters/index_presenter_spec.rb b/spec/presenters/index_presenter_spec.rb index fd095ae185..c7548b417c 100644 --- a/spec/presenters/index_presenter_spec.rb +++ b/spec/presenters/index_presenter_spec.rb @@ -142,31 +142,5 @@ end end end - - describe 'deprecated methods' do - before do - allow(Deprecation).to receive(:warn) - end - - let(:field_config) { config.add_index_field 'qwerty' } - - describe '#get_field_values' do - it 'renders values for the given field' do - expect(subject.get_field_values(field_config, value: ['x', 'y'])).to eq 'x and y' - end - end - - describe '#render_field_values' do - it 'renders values for the given field' do - expect(subject.render_field_values('x')).to eq 'x' - end - end - - describe '#render_values' do - it 'renders values for the given field' do - expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z' - end - end - end end diff --git a/spec/presenters/show_presenter_spec.rb b/spec/presenters/show_presenter_spec.rb index 070e57f286..9546c8adc2 100644 --- a/spec/presenters/show_presenter_spec.rb +++ b/spec/presenters/show_presenter_spec.rb @@ -282,31 +282,5 @@ def mock_document_app_helper_url *args end end end - - describe 'deprecated methods' do - before do - allow(Deprecation).to receive(:warn) - end - - let(:field_config) { config.add_index_field 'qwerty' } - - describe '#get_field_values' do - it 'renders values for the given field' do - expect(subject.get_field_values(field_config, value: ['x', 'y'])).to eq 'x and y' - end - end - - describe '#render_field_values' do - it 'renders values for the given field' do - expect(subject.render_field_values('x')).to eq 'x' - end - end - - describe '#render_values' do - it 'renders values for the given field' do - expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z' - end - end - end end diff --git a/spec/test_app_templates/Gemfile.extra b/spec/test_app_templates/Gemfile.extra index 5768286b63..135cae4f1b 100644 --- a/spec/test_app_templates/Gemfile.extra +++ b/spec/test_app_templates/Gemfile.extra @@ -1,4 +1,3 @@ if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge' gem 'rails-controller-testing' - gem 'deprecation' end