From dbaef7c53dfcdbb2a094ebe9ea50e02b0b605639 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 20 Dec 2023 15:19:32 -0600 Subject: [PATCH] Add new rubocops and autocorrect --- .rubocop.yml | 400 ++++++++++++++++++ .rubocop_todo.yml | 43 +- app/controllers/application_controller.rb | 2 +- app/controllers/cdl_controller.rb | 2 +- .../iiif/auth/v2/probe_service_controller.rb | 2 +- app/controllers/webauth_controller.rb | 2 +- app/models/purl.rb | 6 +- app/models/user.rb | 2 +- app/services/iiif/v1/auth_service.rb | 4 +- spec/abilities/ability_spec.rb | 340 +++++++-------- spec/abilities/cocina_ability_spec.rb | 2 +- spec/controllers/cdl_controller_spec.rb | 14 +- spec/controllers/file_controller_spec.rb | 2 +- spec/controllers/media_controller_spec.rb | 27 +- spec/controllers/object_controller_spec.rb | 2 +- spec/models/purl_spec.rb | 2 +- spec/models/stacks_file_spec.rb | 2 +- spec/models/stacks_media_token_spec.rb | 20 +- spec/models/user_spec.rb | 6 +- spec/rails_helper.rb | 2 +- spec/requests/file_auth_request_spec.rb | 2 +- spec/requests/file_spec.rb | 5 +- spec/requests/iiif/auth/v1/tokens_spec.rb | 8 +- .../iiif/auth/v2/probe_service_spec.rb | 50 +-- spec/requests/iiif_auth_request_spec.rb | 2 +- spec/requests/iiif_spec.rb | 16 +- spec/requests/media_auth_request_spec.rb | 70 +-- spec/requests/media_headers_request_spec.rb | 2 +- spec/routing/cdl_routing_spec.rb | 2 +- spec/routing/file_routing_spec.rb | 4 +- spec/services/iiif_info_service_spec.rb | 15 +- spec/services/iiif_metadata_service_spec.rb | 10 +- .../media_authentication_json_spec.rb | 3 +- 33 files changed, 739 insertions(+), 332 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 04226069..77c63767 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -201,3 +201,403 @@ Performance/Squeeze: Enabled: true Performance/StringInclude: Enabled: true +Gemspec/DeprecatedAttributeAssignment: # new in 1.30 + Enabled: true +Gemspec/DevelopmentDependencies: # new in 1.44 + Enabled: true +Gemspec/RequireMFA: # new in 1.23 + Enabled: true +Layout/LineContinuationLeadingSpace: # new in 1.31 + Enabled: true +Layout/LineContinuationSpacing: # new in 1.31 + 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/ConstantOverwrittenInRescue: # new in 1.31 + Enabled: true +Lint/DeprecatedConstants: # new in 1.8 + Enabled: true +Lint/DuplicateBranch: # new in 1.3 + Enabled: true +Lint/DuplicateMagicComment: # new in 1.37 + Enabled: true +Lint/DuplicateMatchPattern: # new in 1.50 + 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/ItWithoutArgumentsInBlock: # new in 1.59 + Enabled: true +Lint/LambdaWithoutLiteralBlock: # new in 1.8 + Enabled: true +Lint/LiteralAssignmentInCondition: # new in 1.58 + Enabled: true +Lint/MixedCaseRange: # new in 1.53 + Enabled: true +Lint/NoReturnInBeginEndBlocks: # new in 1.2 + Enabled: true +Lint/NonAtomicFileOperation: # new in 1.31 + 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/RedundantRegexpQuantifiers: # new in 1.53 + Enabled: true +Lint/RefinementImportMethods: # new in 1.27 + Enabled: true +Lint/RequireRangeParentheses: # new in 1.32 + 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/UselessRescue: # new in 1.43 + Enabled: true +Lint/UselessRuby2Keywords: # new in 1.23 + Enabled: true +Metrics/CollectionLiteralLength: # new in 1.47 + Enabled: true +Naming/BlockForwarding: # new in 1.24 + Enabled: true +Security/CompoundHash: # new in 1.28 + Enabled: true +Security/IoMethods: # new in 1.22 + Enabled: true +Style/ArgumentsForwarding: # new in 1.1 + Enabled: true +Style/ArrayIntersect: # new in 1.40 + Enabled: true +Style/CollectionCompact: # new in 1.2 + Enabled: true +Style/ComparableClamp: # new in 1.44 + Enabled: true +Style/ConcatArrayLiterals: # new in 1.41 + Enabled: true +Style/DataInheritance: # new in 1.49 + Enabled: true +Style/DirEmpty: # new in 1.48 + Enabled: true +Style/DocumentDynamicEvalDefinition: # new in 1.1 + Enabled: true +Style/EmptyHeredoc: # new in 1.32 + Enabled: true +Style/EndlessMethod: # new in 1.8 + Enabled: true +Style/EnvHome: # new in 1.29 + Enabled: true +Style/ExactRegexpMatch: # new in 1.51 + Enabled: true +Style/FetchEnvVar: # new in 1.28 + Enabled: true +Style/FileEmpty: # new in 1.48 + Enabled: true +Style/FileRead: # new in 1.24 + Enabled: true +Style/FileWrite: # new in 1.24 + 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/MagicCommentFormat: # new in 1.35 + Enabled: true +Style/MapCompactWithConditionalBlock: # new in 1.30 + Enabled: true +Style/MapToHash: # new in 1.24 + Enabled: true +Style/MapToSet: # new in 1.42 + Enabled: true +Style/MinMaxComparison: # new in 1.42 + Enabled: true +Style/MultilineInPatternThen: # new in 1.16 + Enabled: true +Style/NegatedIfElseCondition: # new in 1.2 + Enabled: true +Style/NestedFileDirname: # new in 1.26 + 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/ObjectThen: # new in 1.28 + Enabled: true +Style/OpenStructUse: # new in 1.23 + Enabled: true +Style/OperatorMethodCall: # new in 1.37 + Enabled: true +Style/QuotedSymbols: # new in 1.16 + Enabled: true +Style/RedundantArgument: # new in 1.4 + Enabled: true +Style/RedundantArrayConstructor: # new in 1.52 + Enabled: true +Style/RedundantConstantBase: # new in 1.40 + Enabled: true +Style/RedundantCurrentDirectoryInPath: # new in 1.53 + Enabled: true +Style/RedundantDoubleSplatHashBraces: # new in 1.41 + Enabled: true +Style/RedundantEach: # new in 1.38 + Enabled: true +Style/RedundantFilterChain: # new in 1.52 + Enabled: true +Style/RedundantHeredocDelimiterQuotes: # new in 1.45 + Enabled: true +Style/RedundantInitialize: # new in 1.27 + Enabled: true +Style/RedundantLineContinuation: # new in 1.49 + Enabled: true +Style/RedundantRegexpArgument: # new in 1.53 + Enabled: true +Style/RedundantRegexpConstructor: # new in 1.52 + Enabled: true +Style/RedundantSelfAssignmentBranch: # new in 1.19 + Enabled: true +Style/RedundantStringEscape: # new in 1.37 + Enabled: true +Style/ReturnNilInPredicateMethodDefinition: # new in 1.53 + Enabled: true +Style/SelectByRegexp: # new in 1.22 + Enabled: true +Style/SingleLineDoEndBlock: # new in 1.57 + Enabled: true +Style/StringChars: # new in 1.12 + Enabled: true +Style/SuperWithArgsParentheses: # new in 1.58 + Enabled: true +Style/SwapValues: # new in 1.1 + Enabled: true +Style/YAMLFileRead: # new in 1.53 + Enabled: true +Rails/ActionControllerFlashBeforeRender: # new in 2.16 + Enabled: true +Rails/ActionControllerTestCase: # new in 2.14 + Enabled: true +Rails/ActionOrder: # new in 2.17 + Enabled: true +Rails/ActiveSupportOnLoad: # new in 2.16 + 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/CompactBlank: # new in 2.13 + Enabled: true +Rails/DangerousColumnNames: # new in 2.21 + Enabled: true +Rails/DeprecatedActiveModelErrorsMethods: # new in 2.14 + Enabled: true +Rails/DotSeparatedKeys: # new in 2.15 + Enabled: true +Rails/DuplicateAssociation: # new in 2.14 + Enabled: true +Rails/DuplicateScope: # new in 2.14 + Enabled: true +Rails/DurationArithmetic: # new in 2.13 + Enabled: true +Rails/EagerEvaluationLogMessage: # new in 2.11 + Enabled: true +Rails/EnvLocal: # new in 2.22 + Enabled: true +Rails/ExpandedDateRange: # new in 2.11 + Enabled: true +Rails/FreezeTime: # new in 2.16 + Enabled: true +Rails/I18nLazyLookup: # new in 2.14 + Enabled: true +Rails/I18nLocaleAssignment: # new in 2.11 + Enabled: true +Rails/I18nLocaleTexts: # new in 2.14 + Enabled: true +Rails/IgnoredColumnsAssignment: # new in 2.17 + Enabled: true +Rails/MigrationClassName: # new in 2.14 + Enabled: true +Rails/RedundantActiveRecordAllMethod: # new in 2.21 + Enabled: true +Rails/RedundantPresenceValidationOnBelongsTo: # new in 2.13 + Enabled: true +Rails/RedundantTravelBack: # new in 2.12 + Enabled: true +Rails/ResponseParsedBody: # new in 2.18 + Enabled: true +Rails/RootJoinChain: # new in 2.13 + Enabled: true +Rails/RootPathnameMethods: # new in 2.16 + Enabled: true +Rails/RootPublicPath: # new in 2.15 + Enabled: true +Rails/SelectMap: # new in 2.21 + Enabled: true +Rails/SquishedSQLHeredocs: # new in 2.8 + Enabled: true +Rails/StripHeredoc: # new in 2.15 + Enabled: true +Rails/ThreeStateBooleanColumn: # new in 2.19 + Enabled: true +Rails/TimeZoneAssignment: # new in 2.10 + Enabled: true +Rails/ToFormattedS: # new in 2.15 + Enabled: true +Rails/ToSWithArgument: # new in 2.16 + Enabled: true +Rails/TopLevelHashWithIndifferentAccess: # new in 2.16 + Enabled: true +Rails/TransactionExitStatement: # new in 2.14 + Enabled: true +Rails/UnusedIgnoredColumns: # new in 2.11 + Enabled: true +Rails/UnusedRenderContent: # new in 2.21 + Enabled: true +Rails/WhereEquals: # new in 2.9 + Enabled: true +Rails/WhereMissing: # new in 2.16 + Enabled: true +Rails/WhereNot: # new in 2.8 + Enabled: true +Rails/WhereNotWithMultipleConditions: # new in 2.17 + Enabled: true +Capybara/ClickLinkOrButtonStyle: # new in 2.19 + Enabled: true +Capybara/MatchStyle: # new in 2.17 + Enabled: true +Capybara/NegationMatcher: # new in 2.14 + Enabled: true +Capybara/SpecificActions: # new in 2.14 + Enabled: true +Capybara/SpecificFinders: # new in 2.13 + Enabled: true +Capybara/SpecificMatcher: # new in 2.12 + Enabled: true +Capybara/RSpec/HaveSelector: # new in 2.19 + Enabled: true +Capybara/RSpec/PredicateMatcher: # new in 2.19 + Enabled: true +FactoryBot/AssociationStyle: # new in 2.23 + Enabled: true +FactoryBot/ConsistentParenthesesStyle: # new in 2.14 + Enabled: true +FactoryBot/FactoryAssociationWithStrategy: # new in 2.23 + Enabled: true +FactoryBot/FactoryNameStyle: # new in 2.16 + Enabled: true +FactoryBot/IdSequence: # new in <> + Enabled: true +FactoryBot/RedundantFactoryOption: # new in 2.23 + Enabled: true +FactoryBot/SyntaxMethods: # new in 2.7 + Enabled: true +RSpec/BeEmpty: # new in 2.20 + Enabled: true +RSpec/BeEq: # new in 2.9.0 + Enabled: true +RSpec/BeNil: # new in 2.9.0 + Enabled: true +RSpec/ChangeByZero: # new in 2.11 + Enabled: true +RSpec/ContainExactly: # new in 2.19 + Enabled: true +RSpec/DuplicatedMetadata: # new in 2.16 + Enabled: true +RSpec/EmptyMetadata: # new in 2.24 + Enabled: true +RSpec/Eq: # new in 2.24 + Enabled: true +RSpec/ExcessiveDocstringSpacing: # new in 2.5 + Enabled: true +RSpec/IdenticalEqualityAssertion: # new in 2.4 + Enabled: true +RSpec/IndexedLet: # new in 2.20 + Enabled: true +RSpec/MatchArray: # new in 2.19 + Enabled: true +RSpec/MetadataStyle: # new in 2.24 + Enabled: true +RSpec/NoExpectationExample: # new in 2.13 + Enabled: true +RSpec/PendingWithoutReason: # new in 2.16 + Enabled: true +RSpec/ReceiveMessages: # new in 2.23 + Enabled: true +RSpec/RedundantAround: # new in 2.19 + Enabled: true +RSpec/SkipBlockInsideExample: # new in 2.19 + Enabled: true +RSpec/SortMetadata: # new in 2.14 + Enabled: true +RSpec/SpecFilePathFormat: # new in 2.24 + Enabled: true +RSpec/SpecFilePathSuffix: # new in 2.24 + Enabled: true +RSpec/SubjectDeclaration: # new in 2.5 + Enabled: true +RSpec/VerifiedDoubleReference: # new in 2.10.0 + Enabled: true +RSpec/Rails/AvoidSetupHook: # new in 2.4 + Enabled: true +RSpec/Rails/HaveHttpStatus: # new in 2.12 + Enabled: true +RSpec/Rails/InferredSpecType: # new in 2.14 + Enabled: true +RSpec/Rails/MinitestAssertions: # new in 2.17 + Enabled: true +RSpec/Rails/NegationBeValid: # new in 2.23 + Enabled: true +RSpec/Rails/TravelAround: # new in 2.19 + Enabled: true +Performance/BlockGivenWithExplicitBlock: # new in 1.9 + Enabled: true +Performance/CollectionLiteralInLoop: # new in 1.8 + Enabled: true +Performance/ConcurrentMonotonicTime: # new in 1.12 + Enabled: true +Performance/ConstantRegexp: # new in 1.9 + Enabled: true +Performance/MapCompact: # new in 1.11 + Enabled: true +Performance/MapMethodChain: # new in 1.19 + Enabled: true +Performance/MethodObjectAsBlock: # new in 1.9 + Enabled: true +Performance/RedundantEqualityComparisonBlock: # new in 1.10 + Enabled: true +Performance/RedundantSplitRegexpArgument: # new in 1.10 + Enabled: true +Performance/StringIdentifierArgument: # new in 1.13 + Enabled: true +Performance/Sum: # new in 1.8 + Enabled: true \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a9ae0aaa..afabdb7d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-12-11 17:46:51 UTC using RuboCop version 1.58.0. +# on 2023-12-20 21:18:36 UTC using RuboCop version 1.59.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 @@ -15,7 +15,12 @@ Layout/MultilineMethodCallBraceLayout: - 'spec/routing/file_routing_spec.rb' - 'spec/routing/media_routing_spec.rb' -# Offense count: 8 +# Offense count: 1 +Lint/NoReturnInBeginEndBlocks: + Exclude: + - 'app/models/stacks_file.rb' + +# Offense count: 9 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 22 @@ -25,7 +30,7 @@ Metrics/AbcSize: Metrics/CyclomaticComplexity: Max: 10 -# Offense count: 15 +# Offense count: 14 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 25 @@ -45,7 +50,7 @@ RSpec/AnyInstance: - 'spec/requests/iiif_spec.rb' - 'spec/requests/media_auth_request_spec.rb' -# Offense count: 65 +# Offense count: 66 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: @@ -79,7 +84,7 @@ RSpec/EmptyLineAfterExampleGroup: - 'spec/abilities/ability_spec.rb' - 'spec/requests/file_auth_request_spec.rb' -# Offense count: 34 +# Offense count: 38 # This cop supports safe autocorrection (--autocorrect). RSpec/EmptyLineAfterFinalLet: Exclude: @@ -113,7 +118,7 @@ RSpec/EmptyLineAfterSubject: - 'spec/models/stacks_image_spec.rb' - 'spec/services/iiif_metadata_service_spec.rb' -# Offense count: 32 +# Offense count: 35 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 16 @@ -138,7 +143,13 @@ RSpec/HookArgument: - 'spec/requests/file_auth_request_spec.rb' - 'spec/requests/iiif_auth_request_spec.rb' -# Offense count: 6 +# Offense count: 2 +# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns. +RSpec/IndexedLet: + Exclude: + - 'spec/models/stacks_media_token_spec.rb' + +# Offense count: 7 # This cop supports safe autocorrection (--autocorrect). RSpec/LeadingSubject: Exclude: @@ -155,11 +166,11 @@ RSpec/MessageSpies: - 'spec/controllers/file_controller_spec.rb' - 'spec/controllers/media_controller_spec.rb' -# Offense count: 75 +# Offense count: 81 RSpec/MultipleExpectations: Max: 12 -# Offense count: 63 +# Offense count: 64 # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. # SupportedStyles: always, named_only RSpec/NamedSubject: @@ -177,7 +188,7 @@ RSpec/NamedSubject: - 'spec/services/iiif_metadata_service_spec.rb' - 'spec/services/media_authentication_json_spec.rb' -# Offense count: 46 +# Offense count: 47 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 5 @@ -199,7 +210,7 @@ RSpec/SubjectStub: Exclude: - 'spec/models/stacks_media_token_spec.rb' -# Offense count: 13 +# Offense count: 14 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: @@ -209,14 +220,18 @@ RSpec/VerifiedDoubles: - 'spec/models/stacks_media_token_spec.rb' - 'spec/services/iiif_info_service_spec.rb' -# Offense count: 2 +# Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: slashes, arguments Rails/FilePath: Exclude: - 'app/controllers/application_controller.rb' - - 'spec/controllers/file_controller_spec.rb' + +# Offense count: 1 +Rails/I18nLocaleTexts: + Exclude: + - 'app/controllers/webauth_controller.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). @@ -260,7 +275,7 @@ Style/StringConcatenation: - 'spec/controllers/object_controller_spec.rb' - 'spec/models/stacks_media_token_spec.rb' -# Offense count: 3 +# Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinSize. # SupportedStyles: percent, brackets diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2dbcd5a3..f8925e03 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -26,7 +26,7 @@ def set_cors_headers end def rescue_can_can(exception) - Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}" + Rails.logger.debug { "Access denied on #{exception.action} #{exception.subject.inspect}" } render file: "#{Rails.root}/public/403.html", status: :forbidden, layout: false end diff --git a/app/controllers/cdl_controller.rb b/app/controllers/cdl_controller.rb index 30c42ff8..b318a98a 100644 --- a/app/controllers/cdl_controller.rb +++ b/app/controllers/cdl_controller.rb @@ -17,7 +17,7 @@ def show render json: { payload: existing_payload&.except(:token), availability_url: ("#{Settings.cdl.url}/availability/#{barcode}" if barcode) - }.reject { |_k, v| v.blank? } + }.compact_blank end def show_options diff --git a/app/controllers/iiif/auth/v2/probe_service_controller.rb b/app/controllers/iiif/auth/v2/probe_service_controller.rb index 8cc17ef4..51c82bdd 100644 --- a/app/controllers/iiif/auth/v2/probe_service_controller.rb +++ b/app/controllers/iiif/auth/v2/probe_service_controller.rb @@ -19,7 +19,7 @@ def show # rubocop:disable Metrics:AbcSize if !file.valid? json[:status] = 400 - json[:note] = { "en": file.errors.full_messages } + json[:note] = { en: file.errors.full_messages } elsif !file.readable? json[:status] = 404 elsif can? :access, file diff --git a/app/controllers/webauth_controller.rb b/app/controllers/webauth_controller.rb index 1acc01bf..d8ac0d8d 100644 --- a/app/controllers/webauth_controller.rb +++ b/app/controllers/webauth_controller.rb @@ -10,7 +10,7 @@ class WebauthController < ApplicationController before_action :write_auth_session_info, except: [:logout] def login - flash[:success] = 'You have been successfully logged in.' + flash.now[:success] = 'You have been successfully logged in.' respond_to do |format| format.html { render html: ''.html_safe } diff --git a/app/models/purl.rb b/app/models/purl.rb index f3caa802..7426a55b 100644 --- a/app/models/purl.rb +++ b/app/models/purl.rb @@ -37,10 +37,10 @@ def public_json(druid) end end - def files(druid, &block) - return to_enum(:files, druid) unless block_given? + def files(druid, &) + return to_enum(:files, druid) unless block - Settings.features.cocina ? files_from_json(druid, &block) : files_from_xml(druid, &block) + Settings.features.cocina ? files_from_json(druid, &) : files_from_xml(druid, &) end def files_from_json(druid) diff --git a/app/models/user.rb b/app/models/user.rb index 2bace4d8..a3b41e67 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,7 +25,7 @@ def anonymous_locatable_user? end def stanford? - ldap_groups.present? && (ldap_groups & Settings.user.stanford_groups).any? + ldap_groups.present? && ldap_groups.intersect?(Settings.user.stanford_groups) end def token_user? diff --git a/app/services/iiif/v1/auth_service.rb b/app/services/iiif/v1/auth_service.rb index 8240c601..e69ac90f 100644 --- a/app/services/iiif/v1/auth_service.rb +++ b/app/services/iiif/v1/auth_service.rb @@ -22,8 +22,8 @@ def to_iiif 'profile' => 'http://iiif.io/api/auth/1/login', 'label' => 'Stanford users: log in to access all available features.', 'header' => 'Stanford-affiliated? Log in to view', - 'description' => 'Stanford users can click Log in below to access all fea'\ - 'tures.', + 'description' => 'Stanford users can click Log in below to access all fea' \ + 'tures.', 'confirmLabel' => 'Log in', 'failureHeader' => 'Unable to authenticate', 'failureDescription' => 'The authentication service cannot be reached.', diff --git a/spec/abilities/ability_spec.rb b/spec/abilities/ability_spec.rb index 2dc5646c..dcfd5504 100644 --- a/spec/abilities/ability_spec.rb +++ b/spec/abilities/ability_spec.rb @@ -48,14 +48,14 @@ context 'with a world-readable file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end it { is_expected.to be_able_to(:download, file) } @@ -71,14 +71,14 @@ context 'with a stanford-only file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end it { is_expected.to be_able_to(:download, file) } @@ -94,14 +94,14 @@ context 'with read rights but not download' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -118,14 +118,14 @@ context 'with a file with no read access' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -144,14 +144,14 @@ context 'with a world-readable file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end it { is_expected.to be_able_to(:download, file) } @@ -166,14 +166,14 @@ context 'with a stanford-only file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -188,14 +188,14 @@ context 'with a stanford-only file that is not the thumbnail' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end let(:thumbnail_metadata) { 'x/y.jpg' } @@ -206,14 +206,14 @@ context 'with a stanford-only file that is the first image in an object without an explicit thumbnail' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end let(:content_metadata) do @@ -233,14 +233,14 @@ context 'with read rights but not download' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -256,14 +256,14 @@ context 'with a no-download file that is not the thumbnail' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end let(:thumbnail_metadata) { 'x/y.jpg' } @@ -310,14 +310,14 @@ context 'with media that allows read but not download' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - location1 - - - + <<~EOF + + + + location1 + + + EOF end context 'for an anonymous user from a configured location' do @@ -348,14 +348,14 @@ context 'for an anonymous user' do context 'with a world-readable file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end it { is_expected.to be_able_to(:download, file) } @@ -370,14 +370,14 @@ context 'with a stanford-only file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -392,14 +392,14 @@ context 'with a an unreadable file' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -414,14 +414,14 @@ context 'with read rights but not download' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - + <<~EOF + + + + + + + EOF end it { is_expected.not_to be_able_to(:download, file) } @@ -437,17 +437,17 @@ context 'with world (no-download), and full access for stanford users' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - Stanford - - - + <<~EOF + + + + + + + Stanford + + + EOF end @@ -479,20 +479,20 @@ describe 'for objects with file specific rights' do context 'with an object that defaults to world, but restricts the video to no-download' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - - - - movie.mp4 - - - - - + <<~EOF + + + + + + + + movie.mp4 + + + + + EOF end @@ -511,20 +511,20 @@ context 'with an object that defaults to stanford, but restricts the image to location1' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - - image.jpg - - location1 - - - + <<~EOF + + + + Stanford + + + + image.jpg + + location1 + + + EOF end @@ -578,16 +578,16 @@ end let(:jwt_tokens) { [] } let(:rights_xml) do - <<-EOF.strip_heredoc - - - - - Stanford - - - - + <<~EOF + + + + + Stanford + + + + EOF end @@ -598,7 +598,7 @@ let(:jwt_tokens) do [ JWT.encode( - { aud: image.id, sub: 'a', exp: (Time.zone.now + 1.hour).to_i }, + { aud: image.id, sub: 'a', exp: 1.hour.from_now.to_i }, Settings.cdl.jwt.secret, Settings.cdl.jwt.algorithm ) diff --git a/spec/abilities/cocina_ability_spec.rb b/spec/abilities/cocina_ability_spec.rb index 18ad56b7..9a1abcde 100644 --- a/spec/abilities/cocina_ability_spec.rb +++ b/spec/abilities/cocina_ability_spec.rb @@ -470,7 +470,7 @@ let(:jwt_tokens) do [ JWT.encode( - { aud: image.id, sub: 'a', exp: (Time.zone.now + 1.hour).to_i }, + { aud: image.id, sub: 'a', exp: 1.hour.from_now.to_i }, Settings.cdl.jwt.secret, Settings.cdl.jwt.algorithm ) diff --git a/spec/controllers/cdl_controller_spec.rb b/spec/controllers/cdl_controller_spec.rb index bdf4869b..910d5f49 100644 --- a/spec/controllers/cdl_controller_spec.rb +++ b/spec/controllers/cdl_controller_spec.rb @@ -5,7 +5,7 @@ RSpec.describe CdlController do let(:user) { User.new id: 'username', jwt_tokens: [token] } let(:token) { JWT.encode(payload, Settings.cdl.jwt.secret, Settings.cdl.jwt.algorithm) } - let(:payload) { { aud: 'druid', sub: 'username', exp: (Time.zone.now + 1.day).to_i, barcode: '36105110268922' } } + let(:payload) { { aud: 'druid', sub: 'username', exp: 1.day.from_now.to_i, barcode: '36105110268922' } } before do allow(controller).to receive(:current_user).and_return(user) @@ -21,8 +21,8 @@ it 'includes a url to look up availability' do get :show, params: { id: 'other-druid' } - expect(response.status).to eq 200 - expect(JSON.parse(response.body).with_indifferent_access).to include( + expect(response).to have_http_status :ok + expect(response.parsed_body.with_indifferent_access).to include( availability_url: match(%(cdl/availability/36105110268922)) ) end @@ -31,8 +31,8 @@ it 'renders some information from the token' do get :show, params: { id: 'druid' } - expect(response.status).to eq 200 - expect(JSON.parse(response.body).with_indifferent_access).to include( + expect(response).to have_http_status :ok + expect(response.parsed_body.with_indifferent_access).to include( payload: hash_including(sub: 'username', aud: 'druid', exp: a_kind_of(Numeric)) ) end @@ -40,7 +40,7 @@ it 'includes a url to look up availability' do get :show, params: { id: 'druid' } - expect(JSON.parse(response.body).with_indifferent_access).to include( + expect(response.parsed_body.with_indifferent_access).to include( availability_url: match(%(cdl/availability/36105110268922)) ) end @@ -90,7 +90,7 @@ allow(Purl).to receive(:barcode).with('other-druid').and_return(nil) get :create, params: { id: 'other-druid' } - expect(response.status).to eq 400 + expect(response).to have_http_status :bad_request end end end diff --git a/spec/controllers/file_controller_spec.rb b/spec/controllers/file_controller_spec.rb index 465c3685..cb82e48c 100644 --- a/spec/controllers/file_controller_spec.rb +++ b/spec/controllers/file_controller_spec.rb @@ -38,7 +38,7 @@ subject { get :show, params: { id: druid, file_name: 'xf680rd3068_1.jp2' } } before do - path = File.join(Rails.root, 'spec/fixtures/nr/349/ct/7889/image.jp2') + path = Rails.root.join('spec/fixtures/nr/349/ct/7889/image.jp2') allow(file).to receive_messages(mtime: Time.zone.now, path:) end diff --git a/spec/controllers/media_controller_spec.rb b/spec/controllers/media_controller_spec.rb index dd2e88c1..31131cfb 100644 --- a/spec/controllers/media_controller_spec.rb +++ b/spec/controllers/media_controller_spec.rb @@ -18,14 +18,14 @@ expect(controller).to receive(:token_valid?).with(encrypted_token, id, file_name, ip_addr).and_return true get :verify_token, params: { stacks_token: encrypted_token, id:, file_name:, user_ip: ip_addr } expect(response.body).to eq 'valid token' - expect(response.status).to eq 200 + expect(response).to have_http_status :ok end it 'rejects a token when token_valid? returns false' do expect(controller).to receive(:token_valid?).with(encrypted_token, id, file_name, ip_addr).and_return false get :verify_token, params: { stacks_token: encrypted_token, id:, file_name:, user_ip: ip_addr } expect(response.body).to eq 'invalid token' - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end @@ -36,31 +36,31 @@ it 'verifies a valid token' do get :verify_token, params: valid_token expect(response.body).to eq 'valid token' - expect(response.status).to eq 200 + expect(response).to have_http_status :ok end it 'rejects a token with a corrupted encrypted token string' do get :verify_token, params: valid_token.merge(stacks_token: "#{encrypted_token}aaaa") expect(response.body).to eq 'invalid token' - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it 'rejects a token for the wrong id' do get :verify_token, params: valid_token.merge(id: 'zy098xv7654') expect(response.body).to eq 'invalid token' - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it 'rejects a token for the wrong file name' do get :verify_token, params: valid_token.merge(file_name: 'some_other_file.mp3') expect(response.body).to eq 'invalid token' - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it 'rejects a token from the wrong IP address' do get :verify_token, params: valid_token.merge(user_ip: '192.168.1.101') expect(response.body).to eq 'invalid token' - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end it 'rejects a token that is too old' do @@ -68,7 +68,7 @@ allow_any_instance_of(StacksMediaToken).to receive(:timestamp).and_return(expired_timestamp) get :verify_token, params: valid_token expect(response.body).to eq 'invalid token' - expect(response.status).to eq 403 + expect(response).to have_http_status :forbidden end end end @@ -77,7 +77,7 @@ it 'should call through to StacksMediaToken.verify_encrypted_token? and return the result' do expect(StacksMediaToken).to receive(:verify_encrypted_token?) .with('stacks_token', 'id', 'file_name', 'ip_addr').and_return(true) - expect(controller.send(:token_valid?, 'stacks_token', 'id', 'file_name', 'ip_addr')).to eq true + expect(controller.send(:token_valid?, 'stacks_token', 'id', 'file_name', 'ip_addr')).to be true end end @@ -89,14 +89,13 @@ test_hash = { foo: :bar } expect(controller).to receive(:hash_for_auth_check).and_return(test_hash) get :auth_check, params: { id:, file_name:, format: :js } - body = JSON.parse(response.body) + body = response.parsed_body expect(body).to eq('foo' => 'bar') end context 'success' do let(:token) { instance_double(StacksMediaToken, to_encrypted_string: 'sekret-token') } before do - allow(controller).to receive(:can?).and_return(true) allow(StacksMediaToken).to receive(:new).and_return(token) next unless Settings.features.cocina # below mocking is only needed if cocina is being parsed instead of legacy rights XML @@ -106,19 +105,19 @@ # tested elsewhere. This approach is a bit more readable, and less brittle since it doesn't break the StacksMediaStream abstraction. stacks_media_stream = instance_double(StacksMediaStream, stanford_restricted?: false, restricted_by_location?: false, embargoed?: false, embargo_release_date: nil) - allow(controller).to receive(:current_media).and_return(stacks_media_stream) + allow(controller).to receive_messages(can?: true, current_media: stacks_media_stream) end it 'returns json that indicates a successful auth check (including token)' do get :auth_check, params: { id:, file_name:, format: :js } - body = JSON.parse(response.body) + body = response.parsed_body expect(body['status']).to eq 'success' expect(body['token']).to eq 'sekret-token' end it 'returns info about applicable access restrictions' do get :auth_check, params: { id:, file_name:, format: :js } - body = JSON.parse(response.body) + body = response.parsed_body expect(body['access_restrictions']).to eq({ 'stanford_restricted' => false, 'restricted_by_location' => false, diff --git a/spec/controllers/object_controller_spec.rb b/spec/controllers/object_controller_spec.rb index f1d13757..2948d766 100644 --- a/spec/controllers/object_controller_spec.rb +++ b/spec/controllers/object_controller_spec.rb @@ -22,7 +22,7 @@ instance_double(Faraday::Response, status: 404, success?: false) ) get :show, params: { id: 'foo' } - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end diff --git a/spec/models/purl_spec.rb b/spec/models/purl_spec.rb index 310c21d8..db203142 100644 --- a/spec/models/purl_spec.rb +++ b/spec/models/purl_spec.rb @@ -86,7 +86,7 @@ it 'gets all the files for a resource' do actual = described_class.files('abc').map { |file| "#{file.id}/#{file.file_name}" } - expect(actual).to match_array ['abc/26855.jp2', 'abc/123.jp2'] + expect(actual).to contain_exactly('abc/26855.jp2', 'abc/123.jp2') end end diff --git a/spec/models/stacks_file_spec.rb b/spec/models/stacks_file_spec.rb index 5172e701..ea45ee85 100644 --- a/spec/models/stacks_file_spec.rb +++ b/spec/models/stacks_file_spec.rb @@ -42,7 +42,7 @@ context 'with an unreadable file' do let(:permissions) { nil } - it { is_expected.to eq nil } + it { is_expected.to be_nil } end end end diff --git a/spec/models/stacks_media_token_spec.rb b/spec/models/stacks_media_token_spec.rb index 377d55d9..ea771231 100644 --- a/spec/models/stacks_media_token_spec.rb +++ b/spec/models/stacks_media_token_spec.rb @@ -24,25 +24,25 @@ describe '#token_valid?' do it 'returns true for a valid token' do - expect(subject.send(:token_valid?, id, file_name, user_ip)).to eq true + expect(subject.send(:token_valid?, id, file_name, user_ip)).to be true end it 'returns false if the ids do not match' do - expect(subject.send(:token_valid?, 'zy098xv7654', file_name, user_ip)).to eq false + expect(subject.send(:token_valid?, 'zy098xv7654', file_name, user_ip)).to be false end it 'returns false if the file names do not match' do - expect(subject.send(:token_valid?, id, 'fed', user_ip)).to eq false + expect(subject.send(:token_valid?, id, 'fed', user_ip)).to be false end it 'returns false if the IP addresses do not match' do - expect(subject.send(:token_valid?, id, file_name, '192.168.1.101')).to eq false + expect(subject.send(:token_valid?, id, file_name, '192.168.1.101')).to be false end it 'returns false if the token is too old' do expired_timestamp = (StacksMediaToken.max_token_age + 2.seconds).ago allow(subject).to receive(:timestamp).and_return(expired_timestamp) - expect(subject.send(:token_valid?, id, file_name, user_ip)).to eq false + expect(subject.send(:token_valid?, id, file_name, user_ip)).to be false end end @@ -50,31 +50,31 @@ let(:enc_token_str) { subject.to_encrypted_string } it 'returns true for a valid token that matches the specified values' do - expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to eq true + expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to be true end it 'returns false if the signature is invalid' do invalid_sig_err = ActiveSupport::MessageVerifier::InvalidSignature allow(StacksMediaToken).to receive(:create_from_encrypted_string).with(enc_token_str).and_raise(invalid_sig_err) - expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to eq false + expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to be false end it 'returns false if the encrypted message is invalid' do invalid_msg_err = ActiveSupport::MessageEncryptor::InvalidMessage allow(StacksMediaToken).to receive(:create_from_encrypted_string).with(enc_token_str).and_raise(invalid_msg_err) - expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to eq false + expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to be false end it 'returns false on a token that has been tampered with' do invalid_token = enc_token_str + 'invalid' - expect(StacksMediaToken.verify_encrypted_token?(invalid_token, id, file_name, user_ip)).to eq false + expect(StacksMediaToken.verify_encrypted_token?(invalid_token, id, file_name, user_ip)).to be false end it 'returns false if token_valid? returns false' do mock_token = double(StacksMediaToken) allow(StacksMediaToken).to receive(:create_from_encrypted_string).with(enc_token_str).and_return(mock_token) allow(mock_token).to receive(:token_valid?).with(id, file_name, user_ip).and_return(false) - expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to eq false + expect(StacksMediaToken.verify_encrypted_token?(enc_token_str, id, file_name, user_ip)).to be false end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index adfa2dbf..b0019932 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -47,7 +47,7 @@ let(:jwt_tokens) do [ - { jti: 'a', sub: 'xyz', exp: (Time.zone.now + 1.hour).to_i } + { jti: 'a', sub: 'xyz', exp: 1.hour.from_now.to_i } ] end @@ -67,7 +67,7 @@ context 'with an expired token' do let(:jwt_tokens) do [ - { jti: 'a', sub: 'xyz', exp: (Time.zone.now - 1.hour).to_i } + { jti: 'a', sub: 'xyz', exp: 1.hour.ago.to_i } ] end @@ -79,7 +79,7 @@ context 'with a token for another user' do let(:jwt_tokens) do [ - { jti: 'a', sub: 'abc', exp: (Time.zone.now + 1.hour).to_i } + { jti: 'a', sub: 'abc', exp: 1.hour.from_now.to_i } ] end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c181c1a7..8d9ec97c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -35,7 +35,7 @@ # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures diff --git a/spec/requests/file_auth_request_spec.rb b/spec/requests/file_auth_request_spec.rb index 2812234e..818c94a3 100644 --- a/spec/requests/file_auth_request_spec.rb +++ b/spec/requests/file_auth_request_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe "Authentication for File requests", type: :request do +RSpec.describe "Authentication for File requests" do let(:allowed_loc) { 'ip.address1' } let(:user_no_loc_no_webauth) { User.new } diff --git a/spec/requests/file_spec.rb b/spec/requests/file_spec.rb index 367890a4..40c47c4a 100644 --- a/spec/requests/file_spec.rb +++ b/spec/requests/file_spec.rb @@ -2,10 +2,9 @@ require 'rails_helper' -RSpec.describe "File requests", type: :request do +RSpec.describe "File requests" do before do - allow(Purl).to receive(:public_xml).and_return('') - allow(Purl).to receive(:public_json).and_return(public_json) + allow(Purl).to receive_messages(public_xml: '', public_json:) end let(:public_json) do diff --git a/spec/requests/iiif/auth/v1/tokens_spec.rb b/spec/requests/iiif/auth/v1/tokens_spec.rb index b4b9a38b..1d513893 100644 --- a/spec/requests/iiif/auth/v1/tokens_spec.rb +++ b/spec/requests/iiif/auth/v1/tokens_spec.rb @@ -54,7 +54,7 @@ let(:user) { User.new id: 'xyz', webauth_user: true } it 'returns the token response' do - expect(response.status).to eq 200 + expect(response).to have_http_status :ok data = response.parsed_body expect(data['accessToken']).not_to be_blank @@ -69,7 +69,7 @@ end it 'returns the error response' do - expect(response.status).to eq 401 + expect(response).to have_http_status :unauthorized expect(response.parsed_body['error']).to eq 'missingCredentials' end @@ -81,7 +81,7 @@ it 'returns an error response' do get '/image/iiif/token/whatever' - expect(response.status).to eq 401 + expect(response).to have_http_status :unauthorized expect(response.parsed_body['error']).to eq 'missingCredentials' end @@ -98,7 +98,7 @@ let(:jwt_tokens) do [ - { jti: 'a', aud: 'whatever', sub: 'xyz', exp: (Time.zone.now + 1.hour).to_i } + { jti: 'a', aud: 'whatever', sub: 'xyz', exp: 1.hour.from_now.to_i } ] end diff --git a/spec/requests/iiif/auth/v2/probe_service_spec.rb b/spec/requests/iiif/auth/v2/probe_service_spec.rb index 415875c5..5ecae13f 100644 --- a/spec/requests/iiif/auth/v2/probe_service_spec.rb +++ b/spec/requests/iiif/auth/v2/probe_service_spec.rb @@ -299,14 +299,14 @@ } end let(:rights_xml) do - <<-EOF.strip_heredoc - - - - #{xml_location} - - - + <<~EOF + + + + #{xml_location} + + + EOF end @@ -380,15 +380,15 @@ } end let(:rights_xml) do - <<-EOF.strip_heredoc - - - - 2099-05-15 - stanford - - - + <<~EOF + + + + 2099-05-15 + stanford + + + EOF end @@ -440,14 +440,14 @@ } end let(:rights_xml) do - <<-EOF.strip_heredoc - - - - 2099-05-15 - - - + <<~EOF + + + + 2099-05-15 + + + EOF end diff --git a/spec/requests/iiif_auth_request_spec.rb b/spec/requests/iiif_auth_request_spec.rb index 004fd205..c70b9376 100644 --- a/spec/requests/iiif_auth_request_spec.rb +++ b/spec/requests/iiif_auth_request_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe "Authentication for IIIF requests", type: :request do +RSpec.describe "Authentication for IIIF requests" do let(:allowed_loc) { 'ip.address1' } let(:user_no_loc_no_webauth) { User.new } diff --git a/spec/requests/iiif_spec.rb b/spec/requests/iiif_spec.rb index 654097b3..d7b81b20 100644 --- a/spec/requests/iiif_spec.rb +++ b/spec/requests/iiif_spec.rb @@ -61,7 +61,7 @@ get '/image/iiif/nr349ct7889/abc' expect(response).to redirect_to('/image/iiif/nr349ct7889/abc/info.json') - expect(response.status).to eq 303 + expect(response).to have_http_status :see_other end end @@ -70,7 +70,7 @@ get '/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/info.json', headers: { HTTP_ACCEPT: 'application/json' } expect(response.media_type).to eq 'application/json' - json = JSON.parse(response.body) + json = response.parsed_body expect(json['tiles']).to eq [{ 'width' => 256, 'height' => 256, 'scaleFactors' => [1, 2, 4, 8, 16] }] expect(response.headers['Link']).to eq ';rel="profile"' end @@ -79,7 +79,7 @@ get '/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/info.json', headers: { HTTP_ACCEPT: 'application/ld+json' } expect(response.media_type).to eq 'application/ld+json' - json = JSON.parse(response.body) + json = response.parsed_body expect(json['tiles']).to eq [{ 'width' => 256, 'height' => 256, 'scaleFactors' => [1, 2, 4, 8, 16] }] end @@ -242,7 +242,7 @@ it 'replaces the sizes element to reflect the only downloadable (thumbnail) size' do get '/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/info.json' - json = JSON.parse(response.body) + json = response.parsed_body expect(json['sizes']).to eq [{ 'width' => 266, 'height' => 400 }] end @@ -307,7 +307,7 @@ canonical_url: "http://www.example.com/image/iiif/nr349ct7889/nr349ct7889_00_0001" ) expect(response.media_type).to eq 'image/jpeg' - expect(response.status).to eq 200 + expect(response).to have_http_status :ok end end @@ -320,7 +320,7 @@ it 'is ignored when instantiating StacksImage' do get "/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/0,640,2552,2552/100,100/0/default.jpg?ignored=ignored&host=host" - expect(response.status).to eq 200 + expect(response).to have_http_status :ok end end @@ -332,7 +332,7 @@ it 'returns 404 Not Found' do get "/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/0,640,2552,2552/100,100/0/default.jpg?ignored=ignored&host=host" - expect(response.status).to eq 404 + expect(response).to have_http_status :not_found end end @@ -360,7 +360,7 @@ get '/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/pct:3,3,77,77/full/0/default.jpg' expect(response.media_type).to eq 'image/jpeg' - expect(response.status).to eq 200 + expect(response).to have_http_status :ok end end end diff --git a/spec/requests/media_auth_request_spec.rb b/spec/requests/media_auth_request_spec.rb index a69ed22d..cbb74c43 100644 --- a/spec/requests/media_auth_request_spec.rb +++ b/spec/requests/media_auth_request_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe "Authentication for Media requests", type: :request do +RSpec.describe "Authentication for Media requests" do let(:druid) { 'bb582xs1304' } let(:format) { 'mp4' } @@ -15,14 +15,14 @@ end let(:rights_xml) do - <<-EOF.strip_heredoc - - - - Stanford - - - + <<~EOF + + + + Stanford + + + EOF end @@ -71,7 +71,7 @@ it 'indicates that the object is stanford restricted' do get "/media/#{druid}/file.#{format}/auth_check" - expect(response.parsed_body['access_restrictions']['stanford_restricted']).to eq true + expect(response.parsed_body['access_restrictions']['stanford_restricted']).to be true end end @@ -87,14 +87,14 @@ context 'location restricted' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - spec - - - + <<~EOF + + + + spec + + + EOF end let(:public_json) do @@ -132,15 +132,15 @@ context 'when the file is embargoed or stanford restricted' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - 2099-05-15 - stanford - - - + <<~EOF + + + + 2099-05-15 + stanford + + + EOF end @@ -183,14 +183,14 @@ context 'when the file is embargoed' do let(:rights_xml) do - <<-EOF.strip_heredoc - - - - 2099-05-15 - - - + <<~EOF + + + + 2099-05-15 + + + EOF end let(:public_json) do diff --git a/spec/requests/media_headers_request_spec.rb b/spec/requests/media_headers_request_spec.rb index 34901374..9c33a5b4 100644 --- a/spec/requests/media_headers_request_spec.rb +++ b/spec/requests/media_headers_request_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe "CORS headers for Media requests", type: :request do +RSpec.describe "CORS headers for Media requests" do before do stub_rights_xml(world_readable_rights_xml) allow(Purl).to receive(:public_json).and_return(public_json) diff --git a/spec/routing/cdl_routing_spec.rb b/spec/routing/cdl_routing_spec.rb index 0927b940..60bf4c5f 100644 --- a/spec/routing/cdl_routing_spec.rb +++ b/spec/routing/cdl_routing_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe 'CDL routes', type: :routing do +RSpec.describe 'CDL routes' do it 'routes to #show' do expect(get: '/cdl/druid').to route_to('cdl#show', id: 'druid') end diff --git a/spec/routing/file_routing_spec.rb b/spec/routing/file_routing_spec.rb index 92f4c9f9..a9a6b6d8 100644 --- a/spec/routing/file_routing_spec.rb +++ b/spec/routing/file_routing_spec.rb @@ -41,7 +41,7 @@ end it 'ü must be url escaped' do - skip('problem writing test: ü decodes to \xC3\xBC') + skip('problem writing test: ü decodes to \xC3\xBC') filename = "fü.pdf" escaped_filename = ERB::Util.url_encode(filename) # becomes %C3%BC expect(get: "/file/oo000oo0000/#{escaped_filename}").to route_to( @@ -49,7 +49,7 @@ end it '%20 in actual name (from ck155rf0207)' do - skip('problem writing test: %20 becomes space, over-aggressive param decoding?') + skip('problem writing test: %20 becomes space, over-aggressive param decoding?') filename = 'ARSCJ%202008.foo.bar.pdf' expect(get: "/file/oo000oo0000/#{ERB::Util.url_encode(filename)}").to route_to( 'file#show', id: 'oo000oo0000', file_name: filename) diff --git a/spec/services/iiif_info_service_spec.rb b/spec/services/iiif_info_service_spec.rb index 92f6fdcf..0679e95c 100644 --- a/spec/services/iiif_info_service_spec.rb +++ b/spec/services/iiif_info_service_spec.rb @@ -110,8 +110,7 @@ let(:auth_service) { image_info['service'] } before do - allow(image).to receive(:stanford_restricted?).and_return(true) - allow(image).to receive(:cdl_restricted?).and_return(false) + allow(image).to receive_messages(stanford_restricted?: true, cdl_restricted?: false) end it 'the tile height/width is 256' do @@ -132,8 +131,8 @@ expect(auth_service['failureHeader']).to eq 'Unable to authenticate' expect(auth_service['failureDescription']).to eq 'The authentication service cannot be reached.' expect(auth_service['header']).to eq 'Stanford-affiliated? Log in to view' - expect(auth_service['description']).to eq 'Stanford users can click Log'\ - ' in below to access all features.' + expect(auth_service['description']).to eq 'Stanford users can click Log ' \ + 'in below to access all features.' end it 'advertises a logout service' do @@ -226,17 +225,13 @@ before do allow(Purl).to receive(:public_json).and_return(public_json) stub_rights_xml(world_readable_rights_xml) - allow(image).to receive(:stanford_restricted?).and_return(true) - allow(image).to receive(:restricted_by_location?).and_return(true) + allow(image).to receive_messages(stanford_restricted?: true, restricted_by_location?: true) end it 'advertises support for both login and external authentication' do expect(image_info['service']).to be_present expect(image_info['service'].length).to eq 2 - expect(image_info['service'].pluck('profile')).to match_array [ - 'http://iiif.io/api/auth/1/login', - 'http://iiif.io/api/auth/1/external' - ] + expect(image_info['service'].pluck('profile')).to contain_exactly('http://iiif.io/api/auth/1/login', 'http://iiif.io/api/auth/1/external') end end diff --git a/spec/services/iiif_metadata_service_spec.rb b/spec/services/iiif_metadata_service_spec.rb index ccb5af90..014fd926 100644 --- a/spec/services/iiif_metadata_service_spec.rb +++ b/spec/services/iiif_metadata_service_spec.rb @@ -10,11 +10,11 @@ context "When a valid JSON response is received" do let(:json) do '{"@id":"https://sul-imageserver-uat.stanford.edu/cantaloupe/iiif/2/' \ - 'nr%2F349%2Fct%2F7889%2Fnr349ct7889_00_0001.jp2",' \ - '"width":3832,' \ - '"height":2552,' \ - '"tiles":[{"width":1000,"height":1000,"scaleFactors":[1,2,4,8]}],' \ - '"sizes":[{"width":1916,"height":1276}]}' + 'nr%2F349%2Fct%2F7889%2Fnr349ct7889_00_0001.jp2",' \ + '"width":3832,' \ + '"height":2552,' \ + '"tiles":[{"width":1000,"height":1000,"scaleFactors":[1,2,4,8]}],' \ + '"sizes":[{"width":1916,"height":1276}]}' end let(:response) { instance_double(HTTP::Response, code: 200, body: json) } diff --git a/spec/services/media_authentication_json_spec.rb b/spec/services/media_authentication_json_spec.rb index 00c5d035..0809920d 100644 --- a/spec/services/media_authentication_json_spec.rb +++ b/spec/services/media_authentication_json_spec.rb @@ -67,8 +67,7 @@ describe 'Stanford Restricted OR Location Restricted Media' do before do - allow(media).to receive(:restricted_by_location?).and_return(true) - allow(media).to receive(:stanford_restricted?).and_return(true) + allow(media).to receive_messages(restricted_by_location?: true, stanford_restricted?: true) end it 'returns JSON that indicates that the item is stanford restricted' do