From 92051d5ba812d70a6f242f027ace7cbf49702b27 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 19 Nov 2021 14:41:02 -0600 Subject: [PATCH] Upgrade to latest rubocop --- .rubocop.yml | 157 ++++++++++- .rubocop_todo.yml | 188 +++++++++---- .../document/thumbnail_component.rb | 2 +- .../blacklight/facet_item_pivot_component.rb | 2 +- .../blacklight/response/sort_component.rb | 2 +- .../response/view_type_component.rb | 2 +- .../system/flash_message_component.rb | 2 +- .../concerns/blacklight/bookmarks.rb | 4 +- .../blacklight/blacklight_helper_behavior.rb | 2 +- app/helpers/blacklight/url_helper_behavior.rb | 2 +- app/models/blacklight/facet_paginator.rb | 2 +- app/models/blacklight/icon.rb | 4 +- app/models/record_mailer.rb | 18 +- .../blacklight/facet_field_presenter.rb | 16 +- .../facet_grouped_item_presenter.rb | 6 +- app/services/blacklight/search_service.rb | 2 +- app/views/catalog/_document.atom.builder | 5 +- blacklight.gemspec | 6 +- lib/blacklight.rb | 6 +- lib/blacklight/configuration.rb | 259 +++++++++--------- lib/blacklight/configuration/fields.rb | 2 +- .../open_struct_with_hash_access.rb | 4 +- lib/blacklight/parameters.rb | 2 +- lib/blacklight/search_state.rb | 3 +- lib/blacklight/search_state/filter_field.rb | 5 +- lib/blacklight/solr/response.rb | 6 +- lib/blacklight/solr/response/facets.rb | 8 +- .../solr/response/pagination_methods.rb | 6 +- lib/blacklight/solr/response/params.rb | 8 +- .../solr/search_builder_behavior.rb | 13 +- lib/generators/blacklight/assets_generator.rb | 2 +- .../blacklight/controller_generator.rb | 4 +- lib/generators/blacklight/user_generator.rb | 12 +- lib/railties/blacklight.rake | 2 +- spec/features/search_results_spec.rb | 10 +- ...istory_constraints_helper_behavior_spec.rb | 2 +- spec/helpers/blacklight_helper_spec.rb | 2 +- .../blacklight/configuration/field_spec.rb | 2 +- .../configuration/view_config_spec.rb | 2 +- .../search_state/filter_field_spec.rb | 2 +- spec/models/blacklight/icon_spec.rb | 2 +- .../blacklight/solr/response/facets_spec.rb | 50 ++-- spec/models/blacklight/solr/response_spec.rb | 2 +- .../blacklight/solr/search_builder_spec.rb | 20 +- .../link_alternate_presenter_spec.rb | 4 +- spec/routing/catalog_routing_spec.rb | 2 +- .../blacklight/search_service_spec.rb | 8 +- spec/views/catalog/index.atom.builder_spec.rb | 2 +- .../views/catalog/index.json.jbuilder_spec.rb | 4 +- tasks/blacklight.rake | 6 +- 50 files changed, 562 insertions(+), 322 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3c1af4ec2f..2673e7ab86 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,6 @@ require: - rubocop-rspec - rubocop-rails - inherit_from: - .rubocop_todo.yml @@ -130,3 +129,159 @@ Style/SlicingWithRange: Rails/ContentTag: Enabled: false + +Gemspec/DateAssignment: # new in 1.10 + Enabled: true +Gemspec/RequireMFA: # new in 1.23 + Enabled: true +Layout/LineEndStringConcatenationIndentation: # new in 1.18 + Enabled: true +Layout/SpaceBeforeBrackets: # new in 1.7 + Enabled: true +Lint/AmbiguousAssignment: # new in 1.7 + Enabled: true +Lint/AmbiguousOperatorPrecedence: # new in 1.21 + Enabled: true +Lint/AmbiguousRange: # new in 1.19 + Enabled: true +Lint/DeprecatedConstants: # new in 1.8 + Enabled: true +Lint/DuplicateBranch: # new in 1.3 + Enabled: true +Lint/DuplicateRegexpCharacterClassElement: # new in 1.1 + Enabled: true +Lint/EmptyBlock: # new in 1.1 + Enabled: true +Lint/EmptyClass: # new in 1.3 + Enabled: true +Lint/EmptyInPattern: # new in 1.16 + Enabled: true +Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21 + Enabled: true +Lint/LambdaWithoutLiteralBlock: # new in 1.8 + Enabled: true +Lint/NoReturnInBeginEndBlocks: # new in 1.2 + Enabled: true +Lint/NumberedParameterAssignment: # new in 1.9 + Enabled: true +Lint/OrAssignmentToConstant: # new in 1.9 + Enabled: true +Lint/RedundantDirGlobSort: # new in 1.8 + Enabled: true +Lint/RequireRelativeSelfPath: # new in 1.22 + Enabled: true +Lint/SymbolConversion: # new in 1.9 + Enabled: true +Lint/ToEnumArguments: # new in 1.1 + Enabled: true +Lint/TripleQuotes: # new in 1.9 + Enabled: true +Lint/UnexpectedBlockArity: # new in 1.5 + Enabled: true +Lint/UnmodifiedReduceAccumulator: # new in 1.1 + Enabled: true +Lint/UselessRuby2Keywords: # new in 1.23 + Enabled: true +Security/IoMethods: # new in 1.22 + Enabled: true +Style/ArgumentsForwarding: # new in 1.1 + Enabled: true +Style/CollectionCompact: # new in 1.2 + Enabled: true +Style/DocumentDynamicEvalDefinition: # new in 1.1 + Enabled: true +Style/EndlessMethod: # new in 1.8 + Enabled: true +Style/HashConversion: # new in 1.10 + Enabled: true +Style/HashExcept: # new in 1.7 + Enabled: true +Style/IfWithBooleanLiteralBranches: # new in 1.9 + Enabled: true +Style/InPatternThen: # new in 1.16 + Enabled: true +Style/MultilineInPatternThen: # new in 1.16 + Enabled: true +Style/NegatedIfElseCondition: # new in 1.2 + Enabled: true +Style/NilLambda: # new in 1.3 + Enabled: true +Style/NumberedParameters: # new in 1.22 + Enabled: true +Style/NumberedParametersLimit: # new in 1.22 + Enabled: true +Style/OpenStructUse: # new in 1.23 + Enabled: true +Style/QuotedSymbols: # new in 1.16 + Enabled: true +Style/RedundantArgument: # new in 1.4 + Enabled: true +Style/RedundantSelfAssignmentBranch: # new in 1.19 + Enabled: true +Style/SelectByRegexp: # new in 1.22 + Enabled: true +Style/StringChars: # new in 1.12 + Enabled: true +Style/SwapValues: # new in 1.1 + Enabled: true +RSpec/DescribeClass: + Exclude: + - 'spec/lib/tasks/blacklight_task_spec.rb' + - 'spec/features/**/*' + - 'spec/views/**/*' +RSpec/ExcessiveDocstringSpacing: # new in 2.5 + Enabled: true +RSpec/IdenticalEqualityAssertion: # new in 2.4 + Enabled: true +RSpec/SubjectDeclaration: # new in 2.5 + Enabled: true +RSpec/Rails/AvoidSetupHook: # new in 2.4 + Enabled: true +Rails/ActiveRecordCallbacksOrder: # new in 2.7 + Enabled: true +Rails/AddColumnIndex: # new in 2.11 + Enabled: true +Rails/AfterCommitOverride: # new in 2.8 + Enabled: true +Rails/AttributeDefaultBlockValue: # new in 2.9 + Enabled: true +Rails/EagerEvaluationLogMessage: # new in 2.11 + Enabled: true +Rails/ExpandedDateRange: # new in 2.11 + Enabled: true +Rails/FindById: # new in 2.7 + Enabled: true +Rails/I18nLocaleAssignment: # new in 2.11 + Enabled: true +Rails/Inquiry: # new in 2.7 + Enabled: true +Rails/MailerName: # new in 2.7 + Enabled: true +Rails/MatchRoute: # new in 2.7 + Enabled: true +Rails/NegateInclude: # new in 2.7 + Enabled: true +Rails/Pluck: # new in 2.7 + Enabled: true +Rails/PluckInWhere: # new in 2.7 + Enabled: true +Rails/RedundantTravelBack: # new in 2.12 + Enabled: true +Rails/RenderInline: # new in 2.7 + Enabled: true +Rails/RenderPlainText: # new in 2.7 + Enabled: true +Rails/ShortI18n: # new in 2.7 + Enabled: true +Rails/SquishedSQLHeredocs: # new in 2.8 + Enabled: true +Rails/TimeZoneAssignment: # new in 2.10 + Enabled: true +Rails/UnusedIgnoredColumns: # new in 2.11 + Enabled: true +Rails/WhereEquals: # new in 2.9 + Enabled: true +Rails/WhereExists: # new in 2.7 + Enabled: true +Rails/WhereNot: # new in 2.8 + Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index df999f4038..b7ca87206a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,25 +1,13 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-11-18 05:06:50 UTC using RuboCop version 0.93.1. +# on 2021-11-19 21:03:10 UTC using RuboCop version 1.23.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: 4 -# Cop supports --auto-correct. -Capybara/CurrentPathExpectation: - Exclude: - - 'spec/features/alternate_controller_spec.rb' - -# Offense count: 13 -Capybara/VisibilityMatcher: - Exclude: - - 'spec/features/facets_spec.rb' - - 'spec/features/search_filters_spec.rb' - - 'spec/helpers/blacklight_helper_spec.rb' - # Offense count: 1 +# Configuration parameters: IgnoredMethods. Lint/AmbiguousBlockAssociation: Exclude: - 'lib/blacklight/solr/search_builder_behavior.rb' @@ -49,6 +37,41 @@ Lint/AmbiguousRegexpLiteral: - 'spec/views/catalog/index.html.erb_spec.rb' - 'spec/views/catalog/show.html.erb_spec.rb' +# Offense count: 1 +Lint/BinaryOperatorWithIdenticalOperands: + Exclude: + - 'spec/models/blacklight/document/active_model_shim_spec.rb' + +# Offense count: 14 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'spec/controllers/bookmarks_controller_spec.rb' + - 'spec/controllers/catalog_controller_spec.rb' + - 'spec/models/blacklight/configurable_spec.rb' + - 'spec/models/blacklight/document/active_model_shim_spec.rb' + - 'spec/models/blacklight/document_spec.rb' + - 'spec/models/blacklight/solr/document_spec.rb' + - 'spec/presenters/blacklight/show_presenter_spec.rb' + +# Offense count: 2 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'app/controllers/concerns/blacklight/bookmarks.rb' + - 'lib/blacklight/solr/search_builder_behavior.rb' + +# Offense count: 1 +# Configuration parameters: AllowComments. +Lint/EmptyFile: + Exclude: + - 'spec/components/blacklight/document_metadata_component_spec.rb' + +# Offense count: 36 +Lint/MissingSuper: + Enabled: false + # Offense count: 28 # Cop supports --auto-correct. Lint/ParenthesesAsGroupedExpression: @@ -65,15 +88,15 @@ Lint/ShadowingOuterLocalVariable: - 'spec/models/blacklight/configuration_spec.rb' # Offense count: 71 -# Configuration parameters: IgnoredMethods. +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: Max: 43 # Offense count: 1 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. -# ExcludedMethods: refine +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# IgnoredMethods: refine Metrics/BlockLength: - Max: 28 + Max: 26 # Offense count: 1 # Configuration parameters: CountBlocks. @@ -86,7 +109,7 @@ Metrics/CyclomaticComplexity: Max: 14 # Offense count: 66 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 29 @@ -96,11 +119,11 @@ Metrics/ModuleLength: Max: 140 # Offense count: 6 -# Configuration parameters: CountKeywordArgs. +# Configuration parameters: CountKeywordArgs, MaxOptionalParameters. Metrics/ParameterLists: Max: 6 -# Offense count: 35 +# Offense count: 34 # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: Max: 14 @@ -126,12 +149,18 @@ Naming/MethodParameterName: - 'lib/blacklight/solr/document.rb' - 'lib/blacklight/solr/search_builder_behavior.rb' +# Offense count: 6 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 +Naming/VariableNumber: + Exclude: + - 'spec/lib/blacklight/search_state_spec.rb' + - 'spec/models/blacklight/search_builder_spec.rb' + # Offense count: 8 RSpec/BeforeAfterAll: Exclude: - - 'spec/spec_helper.rb' - - 'spec/rails_helper.rb' - - 'spec/support/**/*.rb' - 'spec/controllers/search_history_controller_spec.rb' - 'spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb' - 'spec/models/blacklight/configurable_spec.rb' @@ -140,38 +169,47 @@ RSpec/BeforeAfterAll: - 'spec/models/blacklight/document/sms_spec.rb' - 'spec/models/blacklight/solr/document_spec.rb' -# Offense count: 93 +# Offense count: 4 +# Cop supports --auto-correct. +RSpec/Capybara/CurrentPathExpectation: + Exclude: + - 'spec/features/alternate_controller_spec.rb' + +# Offense count: 13 +RSpec/Capybara/VisibilityMatcher: + Exclude: + - 'spec/features/facets_spec.rb' + - 'spec/features/search_filters_spec.rb' + - 'spec/helpers/blacklight_helper_spec.rb' + +# Offense count: 92 # Configuration parameters: Prefixes. # Prefixes: when, with, without RSpec/ContextWording: Enabled: false -# Offense count: 37 -# Configuration parameters: IgnoredMetadata. -RSpec/DescribeClass: - Enabled: false - # Offense count: 1 -# Configuration parameters: CustomIncludeMethods. RSpec/EmptyExampleGroup: Exclude: - 'spec/models/blacklight/solr/search_builder_spec.rb' # Offense count: 133 -# Configuration parameters: Max. +# Configuration parameters: CountAsOne. RSpec/ExampleLength: - Enabled: false + Max: 33 # Offense count: 8 RSpec/ExpectInHook: Exclude: - 'spec/controllers/catalog_controller_spec.rb' -# Offense count: 4 -# Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Offense count: 5 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* RSpec/FilePath: Exclude: - 'spec/controllers/blacklight/catalog/component_configuration_spec.rb' + - 'spec/features/sitelinks_search_box.rb' - 'spec/models/blacklight/solr/search_builder_spec.rb' - 'spec/presenters/pipeline_spec.rb' - 'spec/presenters/thumbnail_presenter_spec.rb' @@ -244,7 +282,7 @@ RSpec/MultipleExpectations: RSpec/MultipleMemoizedHelpers: Max: 14 -# Offense count: 380 +# Offense count: 386 # Configuration parameters: IgnoreSharedExamples. RSpec/NamedSubject: Enabled: false @@ -277,6 +315,23 @@ RSpec/ScatteredLet: - 'spec/models/blacklight/solr/search_builder_spec.rb' - 'spec/views/catalog/index.atom.builder_spec.rb' +# Offense count: 22 +RSpec/StubbedMock: + Exclude: + - 'spec/controllers/catalog_controller_spec.rb' + - 'spec/helpers/blacklight/configuration_helper_behavior_spec.rb' + - 'spec/helpers/blacklight/url_helper_behavior_spec.rb' + - 'spec/helpers/blacklight_helper_spec.rb' + - 'spec/helpers/catalog_helper_spec.rb' + - 'spec/models/blacklight/suggest_search_spec.rb' + - 'spec/presenters/blacklight/field_presenter_spec.rb' + - 'spec/presenters/thumbnail_presenter_spec.rb' + +# Offense count: 1 +RSpec/SubjectDeclaration: + Exclude: + - 'spec/models/blacklight/document/cache_key_spec.rb' + # Offense count: 14 RSpec/SubjectStub: Exclude: @@ -292,13 +347,20 @@ RSpec/VerifiedDoubles: Enabled: false # Offense count: 4 -# Configuration parameters: EnforcedStyle. +# Configuration parameters: EnforcedStyle, AllowToTime. # SupportedStyles: strict, flexible Rails/Date: Exclude: - 'spec/models/search_spec.rb' -# Offense count: 22 +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: slashes, arguments +Rails/FilePath: + Exclude: + - 'lib/railties/blacklight.rake' + +# Offense count: 21 # Configuration parameters: Include. # Include: app/helpers/**/*.rb Rails/HelperInstanceVariable: @@ -308,6 +370,14 @@ Rails/HelperInstanceVariable: - 'app/helpers/blacklight/component_helper_behavior.rb' - 'app/helpers/blacklight/render_partials_helper_behavior.rb' +# Offense count: 4 +# Configuration parameters: Include. +# Include: spec/**/*.rb, test/**/*.rb +Rails/I18nLocaleAssignment: + Exclude: + - 'spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb' + - 'spec/helpers/blacklight_helper_spec.rb' + # Offense count: 11 Rails/OutputSafety: Exclude: @@ -355,6 +425,7 @@ Style/ClassAndModuleChildren: Enabled: false # Offense count: 6 +# Cop supports --auto-correct. Style/CommentedKeyword: Exclude: - 'spec/controllers/catalog_controller_spec.rb' @@ -368,7 +439,14 @@ Style/ConditionalAssignment: Exclude: - 'lib/blacklight/solr/response/spelling.rb' -# Offense count: 119 +# Offense count: 3 +Style/DocumentDynamicEvalDefinition: + Exclude: + - 'app/builders/blacklight/action_builder.rb' + - 'lib/blacklight/configuration/fields.rb' + +# Offense count: 108 +# Configuration parameters: AllowedConstants. Style/Documentation: Enabled: false @@ -388,11 +466,10 @@ Style/ExpandPathArguments: - 'lib/generators/blacklight/user_generator.rb' # Offense count: 16 -# Configuration parameters: EnforcedStyle. +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: - Exclude: - - 'app/helpers/blacklight/render_partials_helper_behavior.rb' + EnforcedStyle: template # Offense count: 6 # Configuration parameters: MinBodyLength. @@ -404,7 +481,7 @@ Style/GuardClause: - 'app/helpers/blacklight/catalog_helper_behavior.rb' - 'lib/blacklight/solr/search_builder_behavior.rb' -# Offense count: 34 +# Offense count: 33 # Cop supports --auto-correct. Style/IfUnlessModifier: Enabled: false @@ -418,6 +495,8 @@ Style/MultilineIfModifier: - 'lib/blacklight/solr/search_builder_behavior.rb' # Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowMethodComparison. Style/MultipleComparison: Exclude: - 'lib/blacklight/configuration/context.rb' @@ -436,7 +515,6 @@ Style/MutableConstant: # SupportedStyles: predicate, comparison Style/NumericPredicate: Exclude: - - 'spec/**/*' - 'app/helpers/blacklight/catalog_helper_behavior.rb' - 'app/services/blacklight/search_service.rb' - 'lib/blacklight/search_builder.rb' @@ -445,7 +523,18 @@ Style/NumericPredicate: - 'lib/blacklight/solr/search_builder_behavior.rb' - 'lib/railties/blacklight.rake' -# Offense count: 3 +# Offense count: 15 +Style/OpenStructUse: + Exclude: + - 'lib/blacklight/configuration.rb' + - 'lib/blacklight/open_struct_with_hash_access.rb' + - 'lib/blacklight/solr/response/facets.rb' + - 'spec/components/blacklight/facet_item_pivot_component_spec.rb' + - 'spec/lib/blacklight/search_state/filter_field_spec.rb' + - 'spec/models/blacklight/configuration_spec.rb' + - 'spec/models/blacklight/solr/response_spec.rb' + +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. Style/ParenthesesAroundCondition: @@ -485,7 +574,7 @@ Style/SafeNavigation: - 'lib/blacklight/configuration/search_field.rb' - 'lib/blacklight/solr/search_builder_behavior.rb' -# Offense count: 3 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: AllowAsExpressionSeparator. Style/Semicolon: @@ -493,6 +582,13 @@ Style/Semicolon: - 'spec/models/blacklight/solr/repository_spec.rb' - 'spec/views/catalog/_paginate_compact.html.erb_spec.rb' +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'app/controllers/concerns/blacklight/controller.rb' + # Offense count: 28 # Cop supports --auto-correct. # Configuration parameters: MinSize. diff --git a/app/components/blacklight/document/thumbnail_component.rb b/app/components/blacklight/document/thumbnail_component.rb index 89ae047840..2398bd9fd3 100644 --- a/app/components/blacklight/document/thumbnail_component.rb +++ b/app/components/blacklight/document/thumbnail_component.rb @@ -9,7 +9,7 @@ class ThumbnailComponent < ::ViewComponent::Base # @param [Blacklight::DocumentPresenter] presenter # @param [Integer] counter # @param [Hash] image_options options for the thumbnail presenter's image tag - def initialize(presenter: nil, document: nil, counter:, image_options: {}) + def initialize(counter:, presenter: nil, document: nil, image_options: {}) @presenter = presenter @document = presenter&.document || document @counter = counter diff --git a/app/components/blacklight/facet_item_pivot_component.rb b/app/components/blacklight/facet_item_pivot_component.rb index f8cd288e7a..f537ef36ca 100644 --- a/app/components/blacklight/facet_item_pivot_component.rb +++ b/app/components/blacklight/facet_item_pivot_component.rb @@ -6,7 +6,7 @@ class FacetItemPivotComponent < ::ViewComponent::Base # Somewhat arbitrary number; the only important thing is that # it is bigger than the number of leaf nodes in any collapsing # pivot facet on the page. - ID_COUNTER_MAX = 2**20 - 1 + ID_COUNTER_MAX = (2**20) - 1 # Mint a (sufficiently) unique identifier, so we can associate # the expand/collapse control with labels diff --git a/app/components/blacklight/response/sort_component.rb b/app/components/blacklight/response/sort_component.rb index 9fb867a08a..ff1d0e20c4 100644 --- a/app/components/blacklight/response/sort_component.rb +++ b/app/components/blacklight/response/sort_component.rb @@ -3,7 +3,7 @@ module Blacklight module Response class SortComponent < ViewComponent::Base - def initialize(param: 'sort', choices: {}, search_state:, id: 'sort-dropdown', classes: [], selected: nil) + def initialize(search_state:, param: 'sort', choices: {}, id: 'sort-dropdown', classes: [], selected: nil) @param = param @choices = choices @search_state = search_state diff --git a/app/components/blacklight/response/view_type_component.rb b/app/components/blacklight/response/view_type_component.rb index 008614e39a..55fa8a7d80 100644 --- a/app/components/blacklight/response/view_type_component.rb +++ b/app/components/blacklight/response/view_type_component.rb @@ -7,7 +7,7 @@ class ViewTypeComponent < ViewComponent::Base renders_many :views, 'Blacklight::Response::ViewTypeButtonComponent' # @param [Blacklight::Response] response - def initialize(response:, views: {}, search_state:, selected: nil) + def initialize(response:, search_state:, views: {}, selected: nil) @response = response @views = views @search_state = search_state diff --git a/app/components/blacklight/system/flash_message_component.rb b/app/components/blacklight/system/flash_message_component.rb index c3a3809d9c..4be9d5b4a7 100644 --- a/app/components/blacklight/system/flash_message_component.rb +++ b/app/components/blacklight/system/flash_message_component.rb @@ -7,7 +7,7 @@ class FlashMessageComponent < ViewComponent::Base with_collection_parameter :message - def initialize(message: nil, type:) + def initialize(type:, message: nil) @message = message @classes = alert_class(type) end diff --git a/app/controllers/concerns/blacklight/bookmarks.rb b/app/controllers/concerns/blacklight/bookmarks.rb index e3ac1a7fce..ec3aa9dda6 100644 --- a/app/controllers/concerns/blacklight/bookmarks.rb +++ b/app/controllers/concerns/blacklight/bookmarks.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# note that while this is mostly restful routing, the #update and #destroy actions +# NOTE: that while this is mostly restful routing, the #update and #destroy actions # take the Solr document ID as the :id, NOT the id of the actual Bookmark action. module Blacklight::Bookmarks extend ActiveSupport::Concern @@ -119,7 +119,7 @@ def destroy redirect_back fallback_location: bookmarks_path, notice: I18n.t('blacklight.bookmarks.remove.success') end elsif request.xhr? - head 500 # ajaxy request needs no redirect and should not have flash set + head :internal_server_error # ajaxy request needs no redirect and should not have flash set else redirect_back fallback_location: bookmarks_path, flash: { error: I18n.t('blacklight.bookmarks.remove.failure') } end diff --git a/app/helpers/blacklight/blacklight_helper_behavior.rb b/app/helpers/blacklight/blacklight_helper_behavior.rb index bb8402bc3b..a089983a91 100644 --- a/app/helpers/blacklight/blacklight_helper_behavior.rb +++ b/app/helpers/blacklight/blacklight_helper_behavior.rb @@ -61,7 +61,7 @@ def render_body_class # @see render_body_class # @return [Array] def extra_body_classes - @extra_body_classes ||= ['blacklight-' + controller.controller_name, 'blacklight-' + [controller.controller_name, controller.action_name].join('-')] + @extra_body_classes ||= ["blacklight-#{controller.controller_name}", "blacklight-#{[controller.controller_name, controller.action_name].join('-')}"] end ## diff --git a/app/helpers/blacklight/url_helper_behavior.rb b/app/helpers/blacklight/url_helper_behavior.rb index f1a35ff0f7..26bdfba08e 100644 --- a/app/helpers/blacklight/url_helper_behavior.rb +++ b/app/helpers/blacklight/url_helper_behavior.rb @@ -59,7 +59,7 @@ def session_tracking_path document, params = {} end raise "Unable to find #{controller_tracking_method} route helper. " \ - "Did you add `concerns :searchable` routing mixin to your `config/routes.rb`?" + "Did you add `concerns :searchable` routing mixin to your `config/routes.rb`?" end def controller_tracking_method diff --git a/app/models/blacklight/facet_paginator.rb b/app/models/blacklight/facet_paginator.rb index 70851e4f29..28706a0c89 100644 --- a/app/models/blacklight/facet_paginator.rb +++ b/app/models/blacklight/facet_paginator.rb @@ -56,7 +56,7 @@ def current_page if limit.nil? || limit.zero? # check for divide by zero 1 else - @offset / limit + 1 + (@offset / limit) + 1 end end diff --git a/app/models/blacklight/icon.rb b/app/models/blacklight/icon.rb index ad62002203..a508435a8f 100644 --- a/app/models/blacklight/icon.rb +++ b/app/models/blacklight/icon.rb @@ -32,7 +32,7 @@ def svg end def icon_label - I18n.translate("blacklight.icon.#{icon_name_context}", default: icon_name.to_s.titleize) + I18n.t("blacklight.icon.#{icon_name_context}", default: icon_name.to_s.titleize) end ## @@ -40,7 +40,7 @@ def icon_label def options { class: classes, - "aria-hidden": (true if aria_hidden) + 'aria-hidden': (true if aria_hidden) } end diff --git a/app/models/record_mailer.rb b/app/models/record_mailer.rb index 3d26e10f53..f2ef2477bc 100644 --- a/app/models/record_mailer.rb +++ b/app/models/record_mailer.rb @@ -4,15 +4,15 @@ class RecordMailer < ActionMailer::Base def email_record(documents, details, url_gen_params) title = begin - title_field = details[:config].email.title_field - if title_field - [documents.first[title_field]].flatten.first - else - documents.first.to_semantic_values[:title] - end - rescue - I18n.t('blacklight.email.text.default_title') - end + title_field = details[:config].email.title_field + if title_field + [documents.first[title_field]].flatten.first + else + documents.first.to_semantic_values[:title] + end + rescue + I18n.t('blacklight.email.text.default_title') + end subject = I18n.t('blacklight.email.text.subject', count: documents.length, diff --git a/app/presenters/blacklight/facet_field_presenter.rb b/app/presenters/blacklight/facet_field_presenter.rb index 26fc45cd4a..0ec69d54ed 100644 --- a/app/presenters/blacklight/facet_field_presenter.rb +++ b/app/presenters/blacklight/facet_field_presenter.rb @@ -48,15 +48,13 @@ def each_value(&block) def paginator return unless display_facet - @paginator ||= begin - blacklight_config.facet_paginator_class.new( - display_facet.items, - sort: display_facet.sort, - offset: display_facet.offset, - prefix: display_facet.prefix, - limit: facet_limit - ) - end + @paginator ||= blacklight_config.facet_paginator_class.new( + display_facet.items, + sort: display_facet.sort, + offset: display_facet.offset, + prefix: display_facet.prefix, + limit: facet_limit + ) end DEFAULT_FACET_LIMIT = 10 diff --git a/app/presenters/blacklight/facet_grouped_item_presenter.rb b/app/presenters/blacklight/facet_grouped_item_presenter.rb index c91e642d43..502033f7c6 100644 --- a/app/presenters/blacklight/facet_grouped_item_presenter.rb +++ b/app/presenters/blacklight/facet_grouped_item_presenter.rb @@ -7,12 +7,8 @@ class FacetGroupedItemPresenter < Blacklight::FacetItemPresenter delegate :key, to: :facet_config def initialize(group, facet_item, facet_config, view_context, facet_field, search_state = view_context.search_state) + super(facet_item, facet_config, view_context, facet_field, search_state) @group = group - @facet_item = facet_item - @facet_config = facet_config - @view_context = view_context - @facet_field = facet_field - @search_state = search_state end ## diff --git a/app/services/blacklight/search_service.rb b/app/services/blacklight/search_service.rb index 098b0e4dda..69e04af60b 100644 --- a/app/services/blacklight/search_service.rb +++ b/app/services/blacklight/search_service.rb @@ -120,7 +120,7 @@ def previous_and_next_document_params(index, window = 1) if index > 0 solr_params[:start] = index - window # get one before - solr_params[:rows] = 2 * window + 1 # and one after + solr_params[:rows] = (2 * window) + 1 # and one after else solr_params[:start] = 0 # there is no previous doc solr_params[:rows] = 2 * window # but there should be one after diff --git a/app/views/catalog/_document.atom.builder b/app/views/catalog/_document.atom.builder index 728250f1ae..7721ce365c 100644 --- a/app/views/catalog/_document.atom.builder +++ b/app/views/catalog/_document.atom.builder @@ -38,10 +38,11 @@ xml.entry do # encode properly. See: # http://tools.ietf.org/html/rfc4287#section-4.1.3.3 type = type.downcase - if (type.downcase =~ %r{\+|/xml$}) + case type.downcase + when %r{\+|/xml$} # xml, just put it right in content_element << data - elsif (type.downcase =~ %r{text/}) + when %r{text/} # text, escape content_element.text! data else diff --git a/blacklight.gemspec b/blacklight.gemspec index 7a32538660..bb4223e113 100644 --- a/blacklight.gemspec +++ b/blacklight.gemspec @@ -45,9 +45,9 @@ Gem::Specification.new do |s| s.add_development_dependency 'engine_cart', '~> 2.1' s.add_development_dependency "equivalent-xml" s.add_development_dependency "simplecov" - s.add_development_dependency "rubocop", '~> 0.85' - s.add_development_dependency "rubocop-rails", '~> 2.6' - s.add_development_dependency "rubocop-rspec", '~> 1.43' + s.add_development_dependency "rubocop", '~> 1.0' + s.add_development_dependency "rubocop-rails" + s.add_development_dependency "rubocop-rspec" s.add_development_dependency "i18n-tasks" s.add_development_dependency "solr_wrapper" end diff --git a/lib/blacklight.rb b/lib/blacklight.rb index 892c45ea9e..01208bda14 100644 --- a/lib/blacklight.rb +++ b/lib/blacklight.rb @@ -89,7 +89,7 @@ def self.blacklight_yml end begin - blacklight_erb = ERB.new(IO.read(blacklight_config_file)).result(binding) + blacklight_erb = ERB.new(File.read(blacklight_config_file)).result(binding) rescue StandardError, SyntaxError => e raise("#{blacklight_config_file} was found, but could not be parsed with ERB. \n#{e.inspect}") end @@ -112,9 +112,7 @@ def self.blacklight_yml end def self.logger - @logger ||= begin - ::Rails.logger if defined? Rails && Rails.respond_to?(:logger) - end + @logger ||= (::Rails.logger if defined? Rails && Rails.respond_to?(:logger)) end def self.logger= logger diff --git a/lib/blacklight/configuration.rb b/lib/blacklight/configuration.rb index 29dd0eb6f7..9bef6b277a 100644 --- a/lib/blacklight/configuration.rb +++ b/lib/blacklight/configuration.rb @@ -24,129 +24,128 @@ class Configuration < OpenStructWithHashAccess class << self # rubocop:disable Metrics/MethodLength def default_values - @default_values ||= begin - { - # === Search request configuration - # HTTP method to use when making requests to solr; valid - # values are :get and :post. - http_method: :get, - # The path to send requests to solr. - solr_path: 'select', - # Default values of parameters to send with every search request - default_solr_params: {}, - ## - # === Single document request configuration - # The solr request handler to use when requesting only a single document - document_solr_request_handler: nil, - # The path to send single document requests to solr - document_solr_path: 'get', - document_unique_id_param: :ids, - # Default values of parameters to send when requesting a single document - default_document_solr_params: {}, - fetch_many_document_params: {}, - document_pagination_params: {}, - ## - # == Response models - ## Class for sending and receiving requests from a search index - repository_class: Blacklight::Solr::Repository, - ## Class for converting Blacklight parameters to request parameters for the repository_class - search_builder_class: ::SearchBuilder, - # model that maps index responses to the blacklight response model - response_model: Blacklight::Solr::Response, - # the model to use for each response document - document_model: ::SolrDocument, - # the factory that builds document - document_factory: Blacklight::DocumentFactory, - # Class for paginating long lists of facet fields - facet_paginator_class: Blacklight::Solr::FacetPaginator, - # repository connection configuration - connection_config: Blacklight.connection_config, - ## - # == Blacklight view configuration - navbar: OpenStructWithHashAccess.new(partials: {}), - # General configuration for all views - index: ViewConfig::Index.new( - # document presenter class used by helpers and views - document_presenter_class: nil, - # component class used to render a document - document_component: Blacklight::DocumentComponent, - # solr field to use to render a document title - title_field: nil, - # solr field to use to render format-specific partials - display_type_field: nil, - # partials to render for each document(see #render_document_partials) - partials: [], - document_actions: NestedOpenStructWithHashAccess.new(ToolConfig), - collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig), - # what field, if any, to use to render grouped results - group: false, - # additional response formats for search results - respond_to: OpenStructWithHashAccess.new - ), - # Additional configuration when displaying a single document - show: ViewConfig::Show.new( - # document presenter class used by helpers and views - document_presenter_class: nil, - document_component: Blacklight::DocumentComponent, - display_type_field: nil, - # Default route parameters for 'show' requests. - # Set this to a hash with additional arguments to merge into the route, - # or set `controller: :current` to route to the current controller. - route: nil, - # partials to render for each document(see #render_document_partials) - partials: [], - document_actions: NestedOpenStructWithHashAccess.new(ToolConfig) - ), - action_mapping: NestedOpenStructWithHashAccess.new( - ViewConfig, - default: { top_level_config: :index }, - show: { top_level_config: :show }, - citation: { parent_config: :show } - ), - # SMS and Email configurations. - sms: ViewConfig.new, - email: ViewConfig.new, - # Configurations for specific types of index views - view: NestedOpenStructWithHashAccess.new(ViewConfig, - list: {}, - atom: { - if: false, # by default, atom should not show up as an alternative view - partials: [:document], - summary_partials: [:index] - }, - rss: { - if: false, # by default, rss should not show up as an alternative view - partials: [:document] - }), - # - # These fields are created and managed below by `define_field_access` - # facet_fields - # index_fields - # show_fields - # sort_fields - # search_fields - ## - # === Blacklight behavior configuration - # Maxiumum number of spelling suggestions to offer - spell_max: 5, - # Maximum number of results to show per page - max_per_page: 100, - # Options for the user for number of results to show per page - per_page: [10, 20, 50, 100], - default_per_page: nil, - # how many searches to save in session history - search_history_window: 100, - default_facet_limit: 10, - default_more_limit: 20, - # proc for determining whether the session is a crawler/bot - # ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ } - crawler_detector: nil, - autocomplete_suggester: 'mySuggester', - raw_endpoint: OpenStructWithHashAccess.new(enabled: false), - track_search_session: true, - advanced_search: OpenStruct.new(enabled: false) - } - end + @default_values ||= { + # === Search request configuration + # HTTP method to use when making requests to solr; valid + # values are :get and :post. + http_method: :get, + # The path to send requests to solr. + solr_path: 'select', + # Default values of parameters to send with every search request + default_solr_params: {}, + ## + # === Single document request configuration + # The solr request handler to use when requesting only a single document + document_solr_request_handler: nil, + # The path to send single document requests to solr + document_solr_path: 'get', + document_unique_id_param: :ids, + # Default values of parameters to send when requesting a single document + default_document_solr_params: {}, + fetch_many_document_params: {}, + document_pagination_params: {}, + ## + # == Response models + ## Class for sending and receiving requests from a search index + repository_class: Blacklight::Solr::Repository, + ## Class for converting Blacklight parameters to request parameters for the repository_class + search_builder_class: ::SearchBuilder, + # model that maps index responses to the blacklight response model + response_model: Blacklight::Solr::Response, + # the model to use for each response document + document_model: ::SolrDocument, + # the factory that builds document + document_factory: Blacklight::DocumentFactory, + # Class for paginating long lists of facet fields + facet_paginator_class: Blacklight::Solr::FacetPaginator, + # repository connection configuration + connection_config: Blacklight.connection_config, + ## + # == Blacklight view configuration + navbar: OpenStructWithHashAccess.new(partials: {}), + # General configuration for all views + index: ViewConfig::Index.new( + # document presenter class used by helpers and views + document_presenter_class: nil, + # component class used to render a document + document_component: Blacklight::DocumentComponent, + # solr field to use to render a document title + title_field: nil, + # solr field to use to render format-specific partials + display_type_field: nil, + # partials to render for each document(see #render_document_partials) + partials: [], + document_actions: NestedOpenStructWithHashAccess.new(ToolConfig), + collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig), + # what field, if any, to use to render grouped results + group: false, + # additional response formats for search results + respond_to: OpenStructWithHashAccess.new + ), + # Additional configuration when displaying a single document + show: ViewConfig::Show.new( + # document presenter class used by helpers and views + document_presenter_class: nil, + document_component: Blacklight::DocumentComponent, + display_type_field: nil, + # Default route parameters for 'show' requests. + # Set this to a hash with additional arguments to merge into the route, + # or set `controller: :current` to route to the current controller. + route: nil, + # partials to render for each document(see #render_document_partials) + partials: [], + document_actions: NestedOpenStructWithHashAccess.new(ToolConfig) + ), + action_mapping: NestedOpenStructWithHashAccess.new( + ViewConfig, + default: { top_level_config: :index }, + show: { top_level_config: :show }, + citation: { parent_config: :show } + ), + # SMS and Email configurations. + sms: ViewConfig.new, + email: ViewConfig.new, + # Configurations for specific types of index views + view: NestedOpenStructWithHashAccess.new(ViewConfig, + list: {}, + atom: { + if: false, # by default, atom should not show up as an alternative view + partials: [:document], + summary_partials: [:index] + }, + rss: { + if: false, # by default, rss should not show up as an alternative view + partials: [:document] + }), + # + # These fields are created and managed below by `define_field_access` + # facet_fields + # index_fields + # show_fields + # sort_fields + # search_fields + ## + # === Blacklight behavior configuration + # Maxiumum number of spelling suggestions to offer + spell_max: 5, + # Maximum number of results to show per page + max_per_page: 100, + # Options for the user for number of results to show per page + per_page: [10, 20, 50, 100], + default_per_page: nil, + # how many searches to save in session history + search_history_window: 100, + default_facet_limit: 10, + default_more_limit: 20, + # proc for determining whether the session is a crawler/bot + # ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ } + crawler_detector: nil, + autocomplete_suggester: 'mySuggester', + raw_endpoint: OpenStructWithHashAccess.new(enabled: false), + track_search_session: true, + advanced_search: OpenStruct.new(enabled: false) + } + # rubocop:enable Metrics/MethodLength end end @@ -307,14 +306,12 @@ def view_config(view_type = nil, action_name: :index) view_type = nil end - @view_config[[view_type, action_name]] ||= begin - if view_type.nil? - action_config(action_name) - else - base_config = action_config(action_name) - base_config.merge(view.fetch(view_type, {})) - end - end + @view_config[[view_type, action_name]] ||= if view_type.nil? + action_config(action_name) + else + base_config = action_config(action_name) + base_config.merge(view.fetch(view_type, {})) + end end # YARD will include inline disabling as docs, cannot do multiline inside @!macro. AND this must be separate from doc block. diff --git a/lib/blacklight/configuration/fields.rb b/lib/blacklight/configuration/fields.rb index cb0c81b6aa..50a5db4f84 100644 --- a/lib/blacklight/configuration/fields.rb +++ b/lib/blacklight/configuration/fields.rb @@ -98,7 +98,7 @@ def add_blacklight_field config_key, *args, &block end if (field_config.field || field_config.key).to_s =~ /\*/ - field_config.match = Regexp.new("^" + (field_config.field || field_config.key).to_s.gsub('*', '.+') + "$") + field_config.match = Regexp.new("^#{(field_config.field || field_config.key).to_s.gsub('*', '.+')}$") end # look up any dynamic fields diff --git a/lib/blacklight/open_struct_with_hash_access.rb b/lib/blacklight/open_struct_with_hash_access.rb index 8ae69be8a9..896f9e839f 100644 --- a/lib/blacklight/open_struct_with_hash_access.rb +++ b/lib/blacklight/open_struct_with_hash_access.rb @@ -21,11 +21,11 @@ def select *args, &block end def sort_by *args, &block - self.class.new Hash[to_h.sort_by(*args, &block)] + self.class.new to_h.sort_by(*args, &block).to_h end def sort_by! *args, &block - replace Hash[to_h.sort_by(*args, &block)] + replace to_h.sort_by(*args, &block).to_h self end diff --git a/lib/blacklight/parameters.rb b/lib/blacklight/parameters.rb index 6c8557201a..69a6e94367 100644 --- a/lib/blacklight/parameters.rb +++ b/lib/blacklight/parameters.rb @@ -7,7 +7,7 @@ module Parameters # from the provided parameters. # @param [Hash] params parameters def self.sanitize params - params.reject { |_k, v| v.nil? } + params.compact .except(:action, :controller, :id, :commit, :utf8) end end diff --git a/lib/blacklight/search_state.rb b/lib/blacklight/search_state.rb index a1651cee52..4ba4c35d1d 100644 --- a/lib/blacklight/search_state.rb +++ b/lib/blacklight/search_state.rb @@ -6,8 +6,7 @@ module Blacklight # This class encapsulates the search state as represented by the query # parameters namely: :f, :q, :page, :per_page and, :sort class SearchState - attr_reader :blacklight_config # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config. - attr_reader :params + attr_reader :blacklight_config, :params # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config. # This method is never accessed in this class, but may be used by subclasses that need # to access the url_helpers diff --git a/lib/blacklight/search_state/filter_field.rb b/lib/blacklight/search_state/filter_field.rb index a019335247..ca2618e460 100644 --- a/lib/blacklight/search_state/filter_field.rb +++ b/lib/blacklight/search_state/filter_field.rb @@ -128,9 +128,10 @@ def include?(item) value = as_url_parameter(item) params = search_state.params - if value.is_a?(Array) + case value + when Array (params.dig(:f_inclusive, key) || []).to_set == value.to_set - elsif value == Blacklight::SearchState::FilterField::MISSING + when Blacklight::SearchState::FilterField::MISSING (params.dig(:f, "-#{key}") || []).include?(Blacklight::Engine.config.facet_missing_param) else (params.dig(:f, key) || []).include?(value) diff --git a/lib/blacklight/solr/response.rb b/lib/blacklight/solr/response.rb index 59838fe51e..bb733873a1 100644 --- a/lib/blacklight/solr/response.rb +++ b/lib/blacklight/solr/response.rb @@ -79,11 +79,11 @@ def force_to_utf8(value) when Array value.each { |v| force_to_utf8(v) } when String - if value.encoding != Encoding::UTF_8 + if value.encoding == Encoding::UTF_8 + value + else Blacklight.logger&.warn "Found a non utf-8 value in Blacklight::Solr::Response. \"#{value}\" Encoding is #{value.encoding}" value.dup.force_encoding('UTF-8') - else - value end end value diff --git a/lib/blacklight/solr/response/facets.rb b/lib/blacklight/solr/response/facets.rb index 84a1e202ba..0f98c4fbfc 100644 --- a/lib/blacklight/solr/response/facets.rb +++ b/lib/blacklight/solr/response/facets.rb @@ -114,7 +114,7 @@ def facet_fields # this is some old solr (1.4? earlier?) serialization of facet fields if val.is_a? Array - Hash[val] + val.to_h else val end @@ -152,10 +152,10 @@ def list_as_hash solr_list solr_list.transform_values do |values| if values.first.is_a? Array # arrarr - Hash[values] + values.to_h else # flat - Hash[values.each_slice(2).to_a] + values.each_slice(2).to_a.to_h end end end @@ -171,7 +171,7 @@ def facet_field_aggregations # legacy solr facet.missing serialization if value.nil? - i.label = I18n.t(:"blacklight.search.fields.facet.missing.#{facet_field_name}", default: [:"blacklight.search.facets.missing"]) + i.label = I18n.t(:"blacklight.search.fields.facet.missing.#{facet_field_name}", default: [:'blacklight.search.facets.missing']) i.fq = "-#{facet_field_name}:[* TO *]" # this explicit fq is deprecated; the missing attribute below is a better thing to check for this case i.value = Blacklight::SearchState::FilterField::MISSING i.missing = true diff --git a/lib/blacklight/solr/response/pagination_methods.rb b/lib/blacklight/solr/response/pagination_methods.rb index 98d548c444..495bc353fd 100644 --- a/lib/blacklight/solr/response/pagination_methods.rb +++ b/lib/blacklight/solr/response/pagination_methods.rb @@ -4,15 +4,15 @@ module Blacklight::Solr::Response::PaginationMethods include Kaminari::PageScopeMethods include Kaminari::ConfigurationMethods::ClassMethods - def limit_value #:nodoc: + def limit_value # :nodoc: rows end - def offset_value #:nodoc: + def offset_value # :nodoc: start end - def total_count #:nodoc: + def total_count # :nodoc: total end diff --git a/lib/blacklight/solr/response/params.rb b/lib/blacklight/solr/response/params.rb index dbb0bcf8c0..b40cd21a18 100644 --- a/lib/blacklight/solr/response/params.rb +++ b/lib/blacklight/solr/response/params.rb @@ -30,9 +30,9 @@ def sort def facet_field_aggregation_options(facet_field_name) defaults = { sort: single_valued_param(:'facet.sort'), - limit: single_valued_param(:"facet.limit")&.to_i || 100, - offset: single_valued_param(:"facet.offset")&.to_i || 0, - prefix: single_valued_param(:"facet.prefix") + limit: single_valued_param(:'facet.limit')&.to_i || 100, + offset: single_valued_param(:'facet.offset')&.to_i || 0, + prefix: single_valued_param(:'facet.prefix') } json_facet = json_params.dig('facet', facet_field_name)&.slice(:limit, :offset, :prefix, :sort)&.symbolize_keys || {} @@ -42,7 +42,7 @@ def facet_field_aggregation_options(facet_field_name) limit: single_valued_param(:"f.#{facet_field_name}.facet.limit")&.to_i, offset: single_valued_param(:"f.#{facet_field_name}.facet.offset")&.to_i, prefix: single_valued_param(:"f.#{facet_field_name}.facet.prefix") - }.reject { |_k, v| v.nil? } + }.compact options = defaults.merge(json_facet).merge(param_facet) options[:sort] ||= options[:limit].positive? ? 'count' : 'index' diff --git a/lib/blacklight/solr/search_builder_behavior.rb b/lib/blacklight/solr/search_builder_behavior.rb index 54c3d6e480..6279040de8 100644 --- a/lib/blacklight/solr/search_builder_behavior.rb +++ b/lib/blacklight/solr/search_builder_behavior.rb @@ -261,7 +261,7 @@ def add_facet_paging_to_solr(solr_params) # Now override with our specific things for fetching facet values facet_ex = facet_config.respond_to?(:ex) ? facet_config.ex : nil - solr_params[:"facet.field"] = with_ex_local_param(facet_ex, facet_config.field) + solr_params[:'facet.field'] = with_ex_local_param(facet_ex, facet_config.field) # Need to set as f.facet_field.facet.* to make sure we # override any field-specific default in the solr request handler. @@ -352,7 +352,7 @@ def facet_value_to_fq_string(facet_field, value, use_local_params: true) elsif value == Blacklight::SearchState::FilterField::MISSING "-#{solr_field}:[* TO *]" else - "{!term f=#{solr_field}#{(' ' + local_params.join(' ')) unless local_params.empty?}}#{convert_to_term_value(value)}" + "{!term f=#{solr_field}#{" #{local_params.join(' ')}" unless local_params.empty?}}#{convert_to_term_value(value)}" end end # rubocop:enable Metrics/PerceivedComplexity @@ -375,13 +375,14 @@ def facet_inclusive_value_to_fq_string(facet_field, values) "{!query v=$#{k}}" end.join(' OR ') - ["{!lucene#{(' ' + local_params.join(' ')) unless local_params.empty?}}#{filter_query}", solr_filters] + ["{!lucene#{" #{local_params.join(' ')}" unless local_params.empty?}}#{filter_query}", solr_filters] end def convert_to_term_value(value) - if value.is_a?(DateTime) || value.is_a?(Time) + case value + when DateTime, Time value.utc.strftime("%Y-%m-%dT%H:%M:%SZ") - elsif value.is_a?(Date) + when Date value.to_time(:local).strftime("%Y-%m-%dT%H:%M:%SZ") else value.to_s @@ -415,7 +416,7 @@ def add_search_field_query_builder_params(solr_parameters) def add_search_field_with_local_parameters(solr_parameters) local_params = search_field.solr_local_parameters.map do |key, val| - key.to_s + "=" + solr_param_quote(val, quote: "'") + "#{key}=#{solr_param_quote(val, quote: "'")}" end.join(" ") solr_parameters.append_query "{!#{local_params}}#{search_state.query_param}" diff --git a/lib/generators/blacklight/assets_generator.rb b/lib/generators/blacklight/assets_generator.rb index fce6bb0003..d62e3fe841 100644 --- a/lib/generators/blacklight/assets_generator.rb +++ b/lib/generators/blacklight/assets_generator.rb @@ -79,7 +79,7 @@ def has_blacklight_assets? end def application_js - IO.read(File.expand_path("app/assets/javascripts/application.js", destination_root)) + File.read(File.expand_path("app/assets/javascripts/application.js", destination_root)) end end end diff --git a/lib/generators/blacklight/controller_generator.rb b/lib/generators/blacklight/controller_generator.rb index 644d0efb1a..b048bc702b 100644 --- a/lib/generators/blacklight/controller_generator.rb +++ b/lib/generators/blacklight/controller_generator.rb @@ -17,8 +17,8 @@ class ControllerGenerator < Rails::Generators::Base def inject_blacklight_controller_behavior inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do " # Adds a few additional behaviors into the application controller\n" \ - " include Blacklight::Controller\n" \ - " layout :determine_layout if respond_to? :layout\n\n" + " include Blacklight::Controller\n" \ + " layout :determine_layout if respond_to? :layout\n\n" end end diff --git a/lib/generators/blacklight/user_generator.rb b/lib/generators/blacklight/user_generator.rb index 9a4ffb76a8..75e861e23e 100644 --- a/lib/generators/blacklight/user_generator.rb +++ b/lib/generators/blacklight/user_generator.rb @@ -37,11 +37,11 @@ def generate_devise_assets # add the #to_s to the model. insert_into_file("app/models/#{model_name}.rb", before: /end(\n| )*$/) do "\n # Method added by Blacklight; Blacklight uses #to_s on your\n" \ - " # user class to get a user-displayable login/identifier for\n" \ - " # the account.\n" \ - " def to_s\n" \ - " email\n" \ - " end\n" + " # user class to get a user-displayable login/identifier for\n" \ + " # the account.\n" \ + " def to_s\n" \ + " email\n" \ + " end\n" end gsub_file("config/initializers/devise.rb", "config.sign_out_via = :delete", "config.sign_out_via = :get") end @@ -52,7 +52,7 @@ def inject_blacklight_user_behavior if File.exist?(File.expand_path(file_path, destination_root)) inject_into_class file_path, model_name.classify do "\n # Connects this user object to Blacklights Bookmarks." \ - "\n include Blacklight::User\n" + "\n include Blacklight::User\n" end else say_status "warning", <<-EOS.strip_heredoc, :yellow diff --git a/lib/railties/blacklight.rake b/lib/railties/blacklight.rake index 0cc5927138..aa60a6833a 100644 --- a/lib/railties/blacklight.rake +++ b/lib/railties/blacklight.rake @@ -19,7 +19,7 @@ namespace :blacklight do task seed: [:environment] do require 'yaml' - app_file = Rails.root && Rails.root + 'spec/fixtures/sample_solr_documents.yml' + app_file = Rails.root && "#{Rails.root}spec/fixtures/sample_solr_documents.yml" file = ENV['FILE'] || (app_file && File.exist?(app_file) && app_file) || File.join(Blacklight.root, 'spec', 'fixtures', 'sample_solr_documents.yml') diff --git a/spec/features/search_results_spec.rb b/spec/features/search_results_spec.rb index dd2686e52e..cba8e6d31d 100644 --- a/spec/features/search_results_spec.rb +++ b/spec/features/search_results_spec.rb @@ -68,7 +68,7 @@ def search_for q def position_in_result_page(page, id) i = -1 page.all(".index_title a").each_with_index do |link, idx| - i = (idx + 1) if link['href'] =~ Regexp.new(Regexp.escape(id) + "$") + i = (idx + 1) if link['href'] =~ Regexp.new("#{Regexp.escape(id)}$") end i.to_i end @@ -84,10 +84,10 @@ def number_of_results_from_page(page) tmp_value = Capybara.ignore_hidden_elements Capybara.ignore_hidden_elements = false val = begin - page.find("meta[name=totalResults]")['content'].to_i - rescue StandardError - 0 - end + page.find("meta[name=totalResults]")['content'].to_i + rescue StandardError + 0 + end Capybara.ignore_hidden_elements = tmp_value val end diff --git a/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb b/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb index 093f57b7ca..62e05849dc 100644 --- a/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb +++ b/spec/helpers/blacklight/search_history_constraints_helper_behavior_spec.rb @@ -33,7 +33,7 @@ response = helper.render_search_to_s_element("key>", "value>") expect(response).to have_selector("span.constraint") do |span| expect(span).to have_selector("span.filter-name") do |s2| - # Note: nokogiri's gettext will unescape the inner html + # NOTE: nokogiri's gettext will unescape the inner html # which seems to be what rspecs "contains" method calls on # text nodes - thus the to_s inserted below. expect(s2).to match(/key>:/) diff --git a/spec/helpers/blacklight_helper_spec.rb b/spec/helpers/blacklight_helper_spec.rb index a61769079d..6145ea014c 100644 --- a/spec/helpers/blacklight_helper_spec.rb +++ b/spec/helpers/blacklight_helper_spec.rb @@ -17,7 +17,7 @@ expect(application_name).to eq "Blacklight" end - context "when the language is not english " do + context "when the language is not english" do around do |example| I18n.locale = :de example.run diff --git a/spec/lib/blacklight/configuration/field_spec.rb b/spec/lib/blacklight/configuration/field_spec.rb index 36d1e4acd4..b55723236a 100644 --- a/spec/lib/blacklight/configuration/field_spec.rb +++ b/spec/lib/blacklight/configuration/field_spec.rb @@ -8,7 +8,7 @@ describe '#display_label' do it "looks up the label to display for the given document and field" do - allow(I18n).to receive(:t).with(:"blacklight.search.fields.my_context.some_key", default: [:"blacklight.search.fields.some_key", label, subject.default_label]).and_return('x') + allow(I18n).to receive(:t).with(:'blacklight.search.fields.my_context.some_key', default: [:'blacklight.search.fields.some_key', label, subject.default_label]).and_return('x') expect(subject.display_label('my_context')).to eq 'x' end end diff --git a/spec/lib/blacklight/configuration/view_config_spec.rb b/spec/lib/blacklight/configuration/view_config_spec.rb index 5c269a5203..1fb05da907 100644 --- a/spec/lib/blacklight/configuration/view_config_spec.rb +++ b/spec/lib/blacklight/configuration/view_config_spec.rb @@ -8,7 +8,7 @@ describe '#display_label' do it "looks up the label to display for the given document and field" do - allow(I18n).to receive(:t).with(:"blacklight.search.view_title.my_view", default: [:"blacklight.search.view.my_view", label, nil, "My view"]).and_return('x') + allow(I18n).to receive(:t).with(:'blacklight.search.view_title.my_view', default: [:'blacklight.search.view.my_view', label, nil, "My view"]).and_return('x') expect(subject.display_label).to eq 'x' end end diff --git a/spec/lib/blacklight/search_state/filter_field_spec.rb b/spec/lib/blacklight/search_state/filter_field_spec.rb index 62ac3ebdb7..33ffe46841 100644 --- a/spec/lib/blacklight/search_state/filter_field_spec.rb +++ b/spec/lib/blacklight/search_state/filter_field_spec.rb @@ -162,7 +162,7 @@ context "With facet.missing field" do let(:params) do - { f: { "-some_field": ["[* TO *]"] } } + { f: { '-some_field': ["[* TO *]"] } } end it "removes facet.missing facet params" do diff --git a/spec/models/blacklight/icon_spec.rb b/spec/models/blacklight/icon_spec.rb index 309c687613..e22b18225e 100644 --- a/spec/models/blacklight/icon_spec.rb +++ b/spec/models/blacklight/icon_spec.rb @@ -32,7 +32,7 @@ end end - context ' with a label context' do + context 'with a label context' do subject { described_class.new(:search, classes: 'awesome', aria_hidden: true, additional_options: { label_context: 'foo' }) } it 'adds title' do diff --git a/spec/models/blacklight/solr/response/facets_spec.rb b/spec/models/blacklight/solr/response/facets_spec.rb index e2c11bb095..33e6e3c977 100644 --- a/spec/models/blacklight/solr/response/facets_spec.rb +++ b/spec/models/blacklight/solr/response/facets_spec.rb @@ -291,21 +291,21 @@ def facet_counts let(:response) do { facets: { - "count": 32, - "categories": { - "buckets": [ + count: 32, + categories: { + buckets: [ { - "val": "electronics", - "count": 12, - "max_price": 60 + val: "electronics", + count: 12, + max_price: 60 }, { - "val": "currency", - "count": 4 + val: "currency", + count: 4 }, { - "val": "memory", - "count": 3 + val: "memory", + count: 3 } ] } @@ -331,25 +331,25 @@ def facet_counts let(:response) do { facets: { - "categories": { - "buckets": [ + categories: { + buckets: [ { - "val": "electronics", - "count": 12, - "top_manufacturer": { - "buckets": [{ - "val": "corsair", - "count": 3 + val: "electronics", + count: 12, + top_manufacturer: { + buckets: [{ + val: "corsair", + count: 3 }] } }, { - "val": "currency", - "count": 4, - "top_manufacturer": { - "buckets": [{ - "val": "boa", - "count": 1 + val: "currency", + count: 4, + top_manufacturer: { + buckets: [{ + val: "boa", + count: 1 }] } } @@ -369,7 +369,7 @@ def facet_counts let(:response) do { facets: { - "categories": { + categories: { "missing" => { "count" => 13 }, "buckets" => [{ "val" => "India", "count" => 2 }, { "val" => "Iran", "count" => 2 }] } diff --git a/spec/models/blacklight/solr/response_spec.rb b/spec/models/blacklight/solr/response_spec.rb index bacadce25b..d8414920de 100644 --- a/spec/models/blacklight/solr/response_spec.rb +++ b/spec/models/blacklight/solr/response_spec.rb @@ -43,7 +43,7 @@ expected = "electronics - 14, memory - 3, card - 2, connector - 2, drive - 2, graphics - 2, hard - 2, monitor - 2, search - 2, software - 2" received = first_facet.items.collect do |item| - item.value + ' - ' + item.hits.to_s + "#{item.value} - #{item.hits}" end.join(', ') expect(received).to eq expected diff --git a/spec/models/blacklight/solr/search_builder_spec.rb b/spec/models/blacklight/solr/search_builder_spec.rb index f7ac9a0a1b..10a81ae785 100644 --- a/spec/models/blacklight/solr/search_builder_spec.rb +++ b/spec/models/blacklight/solr/search_builder_spec.rb @@ -73,7 +73,7 @@ expect(subject[:pf]).to eq "" end - describe "should respect proper precedence of settings, " do + describe "should respect proper precedence of settings," do it "does not put :search_field in produced params" do expect(subject[:search_field]).to be_nil end @@ -108,7 +108,7 @@ end it "generates a facet limit" do - expect(subject[:"f.subject_ssim.facet.limit"]).to eq 21 + expect(subject[:'f.subject_ssim.facet.limit']).to eq 21 end context 'with a negative facet limit' do @@ -117,7 +117,7 @@ end it 'is negative' do - expect(subject[:"f.subject_ssim.facet.limit"]).to eq -1 + expect(subject[:'f.subject_ssim.facet.limit']).to eq -1 end end @@ -127,13 +127,13 @@ end it 'is negative' do - expect(subject[:"f.subject_ssim.facet.limit"]).to eq 0 + expect(subject[:'f.subject_ssim.facet.limit']).to eq 0 end end it "handles no facet_limits in config" do blacklight_config.facet_fields = {} - expect(subject).not_to have_key(:"f.subject_ssim.facet.limit") + expect(subject).not_to have_key(:'f.subject_ssim.facet.limit') end describe "with max per page enforced" do @@ -178,7 +178,7 @@ it 'has default facet fields' do # remove local params from the facet.field - expect(subject[:"facet.field"].map { |x| x.gsub(/\{![^}]+\}/, '') }).to match_array %w[format subject_ssim pub_date_ssim language_ssim lc_1letter_ssim subject_geo_ssim subject_era_ssim] + expect(subject[:'facet.field'].map { |x| x.gsub(/\{![^}]+\}/, '') }).to match_array %w[format subject_ssim pub_date_ssim language_ssim lc_1letter_ssim subject_geo_ssim subject_era_ssim] end it "does not have a default qt" do @@ -338,14 +338,14 @@ end it "includes spellcheck.dictionary from field def solr_parameters" do - expect(subject[:"spellcheck.dictionary"]).to eq "subject" + expect(subject[:'spellcheck.dictionary']).to eq "subject" end it "adds on :solr_local_parameters using Solr LocalParams style" do # q == "{!pf=$subject_pf $qf=subject_qf} wome", make sure # the LocalParams are really there subject[:q] =~ /^\{!([^}]+)\}/ - key_value_pairs = Regexp.last_match(1).split(" ") + key_value_pairs = Regexp.last_match(1).split expect(key_value_pairs).to include("pf=$subject_pf") expect(key_value_pairs).to include("qf=$subject_qf") end @@ -465,7 +465,7 @@ describe 'the search field query_builder config' do let(:blacklight_config) do Blacklight::Configuration.new do |config| - config.add_search_field('built_query', query_builder: ->(builder, *_args) { [builder.blacklight_params[:q].reverse, qq1: 'xyz'] }) + config.add_search_field('built_query', query_builder: ->(builder, *_args) { [builder.blacklight_params[:q].reverse, { qq1: 'xyz' }] }) end end @@ -708,7 +708,7 @@ end it 'sets facets requested to facet_field argument' do - expect(solr_parameters["facet.field".to_sym]).to eq facet_field + expect(solr_parameters[:'facet.field']).to eq facet_field end it 'defaults offset to 0' do diff --git a/spec/presenters/blacklight/link_alternate_presenter_spec.rb b/spec/presenters/blacklight/link_alternate_presenter_spec.rb index 105fc0e3c1..fca39e3a82 100644 --- a/spec/presenters/blacklight/link_alternate_presenter_spec.rb +++ b/spec/presenters/blacklight/link_alternate_presenter_spec.rb @@ -26,8 +26,8 @@ let(:expected_html) do '' \ - '' \ - '' + '' \ + '' end it { is_expected.to be_equivalent_to expected_html } diff --git a/spec/routing/catalog_routing_spec.rb b/spec/routing/catalog_routing_spec.rb index b30f718038..d2ee1f19d2 100644 --- a/spec/routing/catalog_routing_spec.rb +++ b/spec/routing/catalog_routing_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper") RSpec.describe "Routing" do describe "Paths Generated by Custom Routes:" do diff --git a/spec/services/blacklight/search_service_spec.rb b/spec/services/blacklight/search_service_spec.rb index 7498107909..2faebe0215 100644 --- a/spec/services/blacklight/search_service_spec.rb +++ b/spec/services/blacklight/search_service_spec.rb @@ -177,7 +177,7 @@ it 'has all value counts > 0' do @facets.each do |_key, facet| facet.items.each do |facet_vals| - expect(facet_vals.hits).to be > 0 + expect(facet_vals.hits).to be_positive end end end @@ -345,7 +345,7 @@ end context "for title search" do - let(:user_params) { { q: 'yehudiyam', "spellcheck.dictionary": "title" } } + let(:user_params) { { q: 'yehudiyam', 'spellcheck.dictionary': "title" } } it 'has spelling suggestions' do (solr_response,) = service.search_results @@ -354,7 +354,7 @@ end context "for author search" do - let(:user_params) { { q: 'shirma', "spellcheck.dictionary": "author" } } + let(:user_params) { { q: 'shirma', 'spellcheck.dictionary': "author" } } it 'has spelling suggestions' do (solr_response,) = service.search_results @@ -363,7 +363,7 @@ end context "for subject search" do - let(:user_params) { { q: 'wome', "spellcheck.dictionary": "subject" } } + let(:user_params) { { q: 'wome', 'spellcheck.dictionary': "subject" } } it 'has spelling suggestions' do (solr_response,) = service.search_results diff --git a/spec/views/catalog/index.atom.builder_spec.rb b/spec/views/catalog/index.atom.builder_spec.rb index 3fc4c390a3..eb0d4a7068 100644 --- a/spec/views/catalog/index.atom.builder_spec.rb +++ b/spec/views/catalog/index.atom.builder_spec.rb @@ -7,7 +7,7 @@ 10.times.map do |i| doc = SolrDocument.new(id: i) allow(doc).to receive(:export_as_some_format).and_return("") - allow(doc).to receive(:to_semantic_values).and_return(author: ['xyz']) if i == 0 + allow(doc).to receive(:to_semantic_values).and_return(author: ['xyz']) if i.zero? doc.will_export_as(:some_format, "application/some-format") if i == 1 doc end diff --git a/spec/views/catalog/index.json.jbuilder_spec.rb b/spec/views/catalog/index.json.jbuilder_spec.rb index 657e076a53..f33b46117e 100644 --- a/spec/views/catalog/index.json.jbuilder_spec.rb +++ b/spec/views/catalog/index.json.jbuilder_spec.rb @@ -65,7 +65,7 @@ id: '123', type: 'Book', attributes: { - 'title': { + title: { id: 'http://test.host/catalog/123#title', type: 'document_value', attributes: { @@ -80,7 +80,7 @@ id: '456', type: 'Article', attributes: { - 'title': { + title: { id: 'http://test.host/catalog/456#title', type: 'document_value', attributes: { diff --git a/tasks/blacklight.rake b/tasks/blacklight.rake index 907779c2a3..e4a00b7774 100644 --- a/tasks/blacklight.rake +++ b/tasks/blacklight.rake @@ -20,7 +20,7 @@ def system_with_error_handling(*args) end end -def with_solr +def with_solr(&block) if system('docker-compose -v') begin puts "Starting Solr" @@ -32,9 +32,7 @@ def with_solr end else SolrWrapper.wrap do |solr| - solr.with_collection do - yield - end + solr.with_collection(&block) end end end