From 7c1c3044fef0c365ae9264c22b99b0c83509668e Mon Sep 17 00:00:00 2001 From: bangn Date: Mon, 31 May 2021 19:09:26 +1000 Subject: [PATCH] fix: add rubocop and fix offenses (#441) * Add rubocop dependency * fix: add rubocop and fix offenses * Remove rails cops * Fix weird alignment --- .rubocop.yml | 905 +----------------- Gemfile | 4 +- config/boot.rb | 2 +- .../latest_pact_consumer_version_orders.rb | 2 +- ..._pact_publications_by_consumer_versions.rb | 4 +- ...ulate_verifications_provider_version_id.rb | 18 +- .../20180311_optimise_head_matrix.rb | 1 - db/test/backwards_compatibility/config.ru | 2 +- .../spec/publish_pact_spec.rb | 4 +- lib/db.rb | 4 +- lib/pact/doc/generator.rb | 2 +- lib/pact/doc/interaction_view_model.rb | 8 +- lib/pact/doc/sort_interactions.rb | 1 - lib/pact_broker/api.rb | 2 + .../contracts/dry_validation_workarounds.rb | 8 +- .../verifiable_pacts_json_query_schema.rb | 2 + .../api/contracts/webhook_contract.rb | 3 + .../api/decorators/dashboard_decorator.rb | 8 +- .../decorators/dashboard_text_decorator.rb | 2 +- .../api/decorators/matrix_decorator.rb | 2 + .../api/decorators/matrix_text_decorator.rb | 2 +- .../pact_webhooks_status_decorator.rb | 4 +- .../pacticipant_collection_decorator.rb | 2 +- .../decorators/provider_pacts_decorator.rb | 1 - .../api/decorators/reason_decorator.rb | 2 + .../decorators/relationships_csv_decorator.rb | 2 + .../webhook_execution_result_decorator.rb | 4 +- lib/pact_broker/api/pact_broker_urls.rb | 6 +- .../api/renderers/html_pact_renderer.rb | 8 +- .../api/resources/default_base_resource.rb | 2 + .../deployed_versions_for_environment.rb | 2 - lib/pact_broker/api/resources/environments.rb | 8 +- .../error_response_body_generator.rb | 2 +- lib/pact_broker/api/resources/index.rb | 2 + .../api/resources/released_version.rb | 2 - lib/pact_broker/app.rb | 6 +- lib/pact_broker/badges/service.rb | 12 +- lib/pact_broker/certificates/service.rb | 2 +- lib/pact_broker/config/setting.rb | 6 +- lib/pact_broker/configuration.rb | 2 + .../contracts/contract_to_publish.rb | 2 + .../contracts/contracts_to_publish.rb | 2 + lib/pact_broker/contracts/service.rb | 2 + lib/pact_broker/date_helper.rb | 6 +- lib/pact_broker/db.rb | 2 +- lib/pact_broker/db/clean.rb | 4 - lib/pact_broker/db/clean_incremental.rb | 6 +- .../set_pacticipant_main_branch.rb | 2 +- lib/pact_broker/db/migrate_data.rb | 2 +- .../deployments/environment_service.rb | 2 +- lib/pact_broker/diagnostic/app.rb | 4 +- lib/pact_broker/domain/index_item.rb | 8 +- lib/pact_broker/domain/pact.rb | 5 +- lib/pact_broker/domain/tag.rb | 2 + lib/pact_broker/domain/verification.rb | 2 +- lib/pact_broker/domain/version.rb | 2 + lib/pact_broker/domain/webhook.rb | 2 +- lib/pact_broker/errors/error_logger.rb | 2 +- lib/pact_broker/hash_refinements.rb | 4 +- lib/pact_broker/index/service.rb | 10 +- lib/pact_broker/logging/default_formatter.rb | 2 +- lib/pact_broker/matrix/aggregated_row.rb | 2 +- lib/pact_broker/matrix/every_row.rb | 2 +- lib/pact_broker/matrix/integration.rb | 6 +- .../matrix/parse_can_i_deploy_query.rb | 2 + lib/pact_broker/matrix/parse_query.rb | 3 + lib/pact_broker/matrix/query_builder.rb | 20 +- lib/pact_broker/matrix/query_results.rb | 2 + lib/pact_broker/matrix/quick_row.rb | 36 +- lib/pact_broker/matrix/repository.rb | 16 +- lib/pact_broker/matrix/resolved_selector.rb | 4 + lib/pact_broker/matrix/service.rb | 2 + lib/pact_broker/metrics/service.rb | 5 +- lib/pact_broker/pacticipants/repository.rb | 9 +- lib/pact_broker/pacts/content.rb | 2 + lib/pact_broker/pacts/eager_loaders.rb | 2 +- lib/pact_broker/pacts/generate_sha.rb | 10 +- lib/pact_broker/pacts/lazy_loaders.rb | 2 +- lib/pact_broker/pacts/merger.rb | 2 +- lib/pact_broker/pacts/pact_publication.rb | 3 - .../pacts_for_verification_repository.rb | 30 +- lib/pact_broker/pacts/repository.rb | 6 +- lib/pact_broker/pacts/selector.rb | 2 + lib/pact_broker/pacts/service.rb | 20 +- .../pacts/squash_pacts_for_verification.rb | 1 - lib/pact_broker/pacts/verifiable_pact.rb | 4 +- .../pacts/verifiable_pact_messages.rb | 68 +- lib/pact_broker/services.rb | 2 + lib/pact_broker/tags/eager_loaders.rb | 4 +- lib/pact_broker/tasks/clean_task.rb | 12 +- lib/pact_broker/tasks/data_migration_task.rb | 4 +- .../tasks/delete_overwritten_data_task.rb | 12 +- lib/pact_broker/tasks/migration_task.rb | 4 +- lib/pact_broker/tasks/version_task.rb | 2 +- .../test/http_test_data_builder.rb | 20 +- lib/pact_broker/test/test_data_builder.rb | 16 +- lib/pact_broker/ui/helpers/matrix_helper.rb | 8 +- lib/pact_broker/ui/view_models/index_item.rb | 10 +- lib/pact_broker/versions/eager_loaders.rb | 12 +- lib/pact_broker/versions/repository.rb | 10 +- lib/pact_broker/versions/service.rb | 2 +- .../pact_and_verification_parameters.rb | 2 + lib/pact_broker/webhooks/redact_logs.rb | 4 +- lib/pact_broker/webhooks/render.rb | 5 +- lib/pact_broker/webhooks/repository.rb | 2 + lib/pact_broker/webhooks/service.rb | 4 +- lib/pact_broker/webhooks/status.rb | 4 +- lib/pact_broker/webhooks/trigger_service.rb | 8 +- lib/pact_broker/webhooks/webhook.rb | 1 - .../webhooks/webhook_request_logger.rb | 2 +- .../webhooks/webhook_request_template.rb | 3 +- lib/rack/hal_browser/redirect.rb | 2 +- lib/rack/pact_broker/no_auth.rb | 2 +- lib/webmachine/rack_adapter_monkey_patch.rb | 2 + regression/regression_helper.rb | 2 +- scaffolding/run.rb | 6 +- script/seed.rb | 26 +- spec/integration/ui/index_spec.rb | 4 +- spec/integration/ui/matrix_spec.rb | 4 +- spec/integration/webhooks/certificate_spec.rb | 2 +- .../pact/doc/interaction_view_model_spec.rb | 4 +- ...cts_json_query_schema_combinations_spec.rb | 2 +- ...verifiable_pacts_json_query_schema_spec.rb | 4 +- .../decorators/dashboard_decorator_spec.rb | 2 +- .../api/decorators/version_decorator_spec.rb | 8 +- .../api/decorators/webhook_decorator_spec.rb | 2 +- ...webhook_execution_result_decorator_spec.rb | 2 +- .../api/renderers/html_pact_renderer_spec.rb | 10 +- .../api/resources/can_i_deploy_spec.rb | 2 +- .../default_base_resource_approval_spec.rb | 5 +- .../error_response_body_generator_spec.rb | 10 +- spec/lib/pact_broker/app_spec.rb | 14 +- .../set_latest_version_sequence_value_spec.rb | 2 +- .../set_pacticipant_main_branch_spec.rb | 2 +- .../pact_broker/matrix/integration_spec.rb | 8 +- .../matrix/repository_dependency_spec.rb | 2 +- .../matrix/repository_query_limit_spec.rb | 4 +- .../pact_broker/pacticipants/service_spec.rb | 64 +- .../pacts/create_formatted_diff_spec.rb | 4 +- .../pact_publication_dataset_module_spec.rb | 2 +- .../pacts/pact_publication_spec.rb | 4 +- spec/lib/pact_broker/webhooks/render_spec.rb | 6 +- .../pact_broker/webhooks/repository_spec.rb | 8 +- spec/lib/pact_broker/webhooks/service_spec.rb | 10 +- .../webhooks/webhook_request_template_spec.rb | 2 +- spec/lib/rack/hal_browser/redirect_spec.rb | 2 +- .../add_pact_broker_version_header_spec.rb | 4 +- .../pact_broker/database_transaction_spec.rb | 3 +- .../invalid_uri_protection_spec.rb | 2 +- spec/lib/rack/pact_broker/use_when_spec.rb | 2 +- spec/lib/sequel/plugins/upsert_spec.rb | 2 +- .../change_migration_strategy_spec.rb | 4 +- spec/service_consumers/pact_helper.rb | 2 +- .../provider_states_for_pact_broker_client.rb | 2 +- .../provider_states_for_pact_ruby.rb | 2 +- spec/support/rspec_matchers.rb | 2 +- spec/support/ssl_webhook_server.rb | 2 +- tasks/db.rake | 4 +- tasks/development.rake | 4 +- 159 files changed, 491 insertions(+), 1327 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 88c3728d5..8aaa5e2a1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,9 @@ +require: + - rubocop-performance + AllCops: DisabledByDefault: true -#################### Lint ################################ - Lint/AmbiguousOperator: Description: >- Checks for ambiguous operators in the first argument of a @@ -21,7 +22,7 @@ Lint/AssignmentInCondition: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition' Enabled: true -Lint/BlockAlignment: +Layout/BlockAlignment: Description: 'Align block ends correctly.' Enabled: true @@ -29,7 +30,7 @@ Lint/CircularArgumentReference: Description: "Don't refer to the keyword argument in the default value." Enabled: true -Lint/ConditionPosition: +Layout/ConditionPosition: Description: >- Checks for condition placed in a confusing position relative to the keyword. @@ -40,7 +41,7 @@ Lint/Debugger: Description: 'Check for debugger calls.' Enabled: true -Lint/DefEndAlignment: +Layout/DefEndAlignment: Description: 'Align ends corresponding to defs correctly.' Enabled: true @@ -68,20 +69,16 @@ Lint/EmptyInterpolation: Description: 'Checks for empty string interpolation.' Enabled: true -Lint/EndAlignment: +Layout/EndAlignment: Description: 'Align ends correctly.' Enabled: true -Lint/EndInMethod: - Description: 'END blocks should not be placed inside method definitions.' - Enabled: true - Lint/EnsureReturn: Description: 'Do not use return in an ensure block.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-return-ensure' Enabled: true -Lint/Eval: +Security/Eval: Description: 'The use of eval represents a serious security risk.' Enabled: true @@ -89,18 +86,12 @@ Lint/FormatParameterMismatch: Description: 'The number of parameters to format/sprint must match the fields.' Enabled: true -Lint/HandleExceptions: +Lint/SuppressedException: Description: "Don't suppress exception." StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions' Enabled: true -Lint/InvalidCharacterLiteral: - Description: >- - Checks for invalid character literals with a non-escaped - whitespace character. - Enabled: true - -Lint/LiteralInCondition: +Lint/LiteralAsCondition: Description: 'Checks of literals used in conditions.' Enabled: true @@ -148,7 +139,7 @@ Lint/ShadowingOuterLocalVariable: for block arguments or block local variables. Enabled: true -Lint/StringConversionInInterpolation: +Lint/RedundantStringCoercion: Description: 'Checks for Object#to_s usage in string interpolation.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-to-s' Enabled: true @@ -157,7 +148,7 @@ Lint/UnderscorePrefixedVariableName: Description: 'Do not use prefix `_` for a variable that is used.' Enabled: true -Lint/UnneededDisable: +Lint/RedundantCopDisableDirective: Description: >- Checks for rubocop:disable comments that can be removed. Note: this cop is not disabled when disabling all cops. @@ -187,7 +178,7 @@ Lint/UselessAssignment: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' Enabled: true -Lint/UselessComparison: +Lint/BinaryOperatorWithIdenticalOperands: Description: 'Checks for comparison of something with itself.' Enabled: true @@ -205,14 +196,6 @@ Lint/Void: ###################### Metrics #################################### -Metrics/AbcSize: - Description: >- - A calculated magnitude based on number of assignments, - branches, and conditions. - Reference: 'http://c2.com/cgi/wiki?AbcMetric' - Enabled: false - Max: 20 - Metrics/BlockNesting: Description: 'Avoid excessive block nesting' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count' @@ -223,39 +206,39 @@ Metrics/ClassLength: Description: 'Avoid classes longer than 250 lines of code.' Enabled: true Max: 250 + Exclude: + - lib/pact_broker/test/*.rb Metrics/CyclomaticComplexity: Description: >- A complexity metric that is strongly correlated to the number of test cases needed to validate a method. Enabled: true - -Metrics/LineLength: - Description: 'Limit lines to 80 characters.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' - Enabled: false + Exclude: + - ./lib/pact_broker/ui/app.rb Metrics/MethodLength: Description: 'Avoid methods longer than 30 lines of code.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods' Enabled: true Max: 30 + Exclude: + - ./lib/pact_broker/ui/app.rb Metrics/ModuleLength: Description: 'Avoid modules longer than 250 lines of code.' Enabled: true Max: 250 + Exclude: + - spec/**/*.rb + - lib/pact_broker/api/pact_broker_urls.rb Metrics/ParameterLists: Description: 'Avoid parameter lists longer than three or four parameters.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params' Enabled: true - -Metrics/PerceivedComplexity: - Description: >- - A complexity metric geared towards measuring complexity for a - human reader. - Enabled: false + Exclude: + - lib/pact_broker/test/*.rb ##################### Performance ############################# @@ -291,7 +274,7 @@ Performance/ReverseEach: Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code' Enabled: true -Performance/Sample: +Style/Sample: Description: >- Use `sample` instead of `shuffle.first`, `shuffle.last`, and `shuffle[Fixnum]`. @@ -313,844 +296,8 @@ Performance/StringReplacement: Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code' Enabled: true -##################### Rails ################################## - -Rails/ActionFilter: - Description: 'Enforces consistent use of action filter methods.' - Enabled: false - -Rails/Date: - Description: >- - Checks the correct usage of date aware methods, - such as Date.today, Date.current etc. - Enabled: false - -Rails/Delegate: - Description: 'Prefer delegate method for delegations.' - Enabled: false - -Rails/FindBy: - Description: 'Prefer find_by over where.first.' - Enabled: false - -Rails/FindEach: - Description: 'Prefer all.find_each over all.find.' - Enabled: false - -Rails/HasAndBelongsToMany: - Description: 'Prefer has_many :through to has_and_belongs_to_many.' - Enabled: false - -Rails/Output: - Description: 'Checks for calls to puts, print, etc.' - Enabled: false - -Rails/ReadWriteAttribute: - Description: >- - Checks for read_attribute(:attr) and - write_attribute(:attr, val). - Enabled: false - -Rails/ScopeArgs: - Description: 'Checks the arguments of ActiveRecord scopes.' - Enabled: false - -Rails/TimeZone: - Description: 'Checks the correct usage of time zone aware methods.' - StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time' - Reference: 'http://danilenko.org/2012/7/6/rails_timezones' - Enabled: false - -Rails/Validation: - Description: 'Use validates :attribute, hash of validations.' - Enabled: false - -################## Style ################################# - -Style/AccessModifierIndentation: - Description: Check indentation of private/protected visibility modifiers. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected' - Enabled: false - -Style/AccessorMethodName: - Description: Check the naming of accessor methods for get_/set_. - Enabled: false - -Style/Alias: - Description: 'Use alias_method instead of alias.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method' - Enabled: false - -Style/AlignArray: - Description: >- - Align the elements of an array literal if they span more than - one line. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays' - Enabled: false - -Style/AlignHash: - Description: >- - Align the elements of a hash literal if they span more than - one line. - Enabled: false - -Style/AlignParameters: - Description: >- - Align the parameters of a method call if they span more - than one line. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent' - Enabled: false - -Style/AndOr: - Description: 'Use &&/|| instead of and/or.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-and-or-or' - Enabled: false - -Style/ArrayJoin: - Description: 'Use Array#join instead of Array#*.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#array-join' - Enabled: false - -Style/AsciiComments: - Description: 'Use only ascii symbols in comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments' - Enabled: false - -Style/AsciiIdentifiers: - Description: 'Use only ascii symbols in identifiers.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers' - Enabled: false - -Style/Attr: - Description: 'Checks for uses of Module#attr.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr' - Enabled: false - -Style/BeginBlock: - Description: 'Avoid the use of BEGIN blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks' - Enabled: false - -Style/BarePercentLiterals: - Description: 'Checks if usage of %() or %Q() matches configuration.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q-shorthand' - Enabled: false - -Style/BlockComments: - Description: 'Do not use block comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments' - Enabled: false - -Style/BlockEndNewline: - Description: 'Put end statement of multiline block on its own line.' - Enabled: false - -Style/BlockDelimiters: - Description: >- - Avoid using {...} for multi-line blocks (multiline chaining is - always ugly). - Prefer {...} over do...end for single-line blocks. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' - Enabled: false - -Style/BracesAroundHashParameters: - Description: 'Enforce braces style around hash parameters.' - Enabled: false - -Style/CaseEquality: - Description: 'Avoid explicit use of the case equality operator(===).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality' - Enabled: false - -Style/CaseIndentation: - Description: 'Indentation of when in a case/when/[else/]end.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-when-to-case' - Enabled: false - -Style/CharacterLiteral: - Description: 'Checks for uses of character literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-character-literals' - Enabled: false - -Style/ClassAndModuleCamelCase: - Description: 'Use CamelCase for classes and modules.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#camelcase-classes' - Enabled: false - -Style/ClassAndModuleChildren: - Description: 'Checks style of children classes and modules.' - Enabled: false - -Style/ClassCheck: - Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.' - Enabled: false - -Style/ClassMethods: - Description: 'Use self when defining module/class methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-class-methods' - Enabled: false - -Style/ClassVars: - Description: 'Avoid the use of class variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-class-vars' - Enabled: false - -Style/ClosingParenthesisIndentation: - Description: 'Checks the indentation of hanging closing parentheses.' - Enabled: false - -Style/ColonMethodCall: - Description: 'Do not use :: for method call.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons' - Enabled: false - -Style/CommandLiteral: - Description: 'Use `` or %x around command literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-x' - Enabled: false - -Style/CommentAnnotation: - Description: 'Checks formatting of annotation comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#annotate-keywords' - Enabled: false - -Style/CommentIndentation: - Description: 'Indentation of comments.' - Enabled: false - -Style/ConstantName: - Description: 'Constants should use SCREAMING_SNAKE_CASE.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#screaming-snake-case' - Enabled: false - -Style/DefWithParentheses: - Description: 'Use def with parentheses when there are arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false - -Style/PreferredHashMethods: - Description: 'Checks for use of deprecated Hash methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key' - Enabled: false - -Style/Documentation: - Description: 'Document classes and non-namespace modules.' - Enabled: false - -Style/DotPosition: - Description: 'Checks the position of the dot in multi-line method calls.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains' - Enabled: false - -Style/DoubleNegation: - Description: 'Checks for uses of double negation (!!).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang' - Enabled: false - -Style/EachWithObject: - Description: 'Prefer `each_with_object` over `inject` or `reduce`.' - Enabled: false - -Style/ElseAlignment: - Description: 'Align elses and elsifs correctly.' - Enabled: false - -Style/EmptyElse: - Description: 'Avoid empty else-clauses.' - Enabled: false - -Style/EmptyLineBetweenDefs: - Description: 'Use empty lines between defs.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods' - Enabled: false - -Style/EmptyLines: - Description: "Don't use several empty lines in a row." - Enabled: false - -Style/EmptyLinesAroundAccessModifier: - Description: "Keep blank lines around access modifiers." - Enabled: false - -Style/EmptyLinesAroundBlockBody: - Description: "Keeps track of empty lines around block bodies." - Enabled: false - -Style/EmptyLinesAroundClassBody: - Description: "Keeps track of empty lines around class bodies." - Enabled: false - -Style/EmptyLinesAroundModuleBody: - Description: "Keeps track of empty lines around module bodies." - Enabled: false - -Style/EmptyLinesAroundMethodBody: - Description: "Keeps track of empty lines around method bodies." - Enabled: false - -Style/EmptyLiteral: - Description: 'Prefer literals to Array.new/Hash.new/String.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#literal-array-hash' - Enabled: false - -Style/EndBlock: - Description: 'Avoid the use of END blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-END-blocks' - Enabled: false - -Style/EndOfLine: - Description: 'Use Unix-style line endings.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf' - Enabled: false - -Style/EvenOdd: - Description: 'Favor the use of Fixnum#even? && Fixnum#odd?' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false - -Style/ExtraSpacing: - Description: 'Do not use unnecessary spacing.' - Enabled: false - -Style/FileName: - Description: 'Use snake_case for source file names.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files' - Enabled: false - -Style/InitialIndentation: - Description: >- - Checks the indentation of the first non-blank non-comment line in a file. - Enabled: false - -Style/FirstParameterIndentation: - Description: 'Checks the indentation of the first parameter in a method call.' - Enabled: false - -Style/FlipFlop: - Description: 'Checks for flip flops' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops' - Enabled: false - -Style/For: - Description: 'Checks use of for or each in multiline loops.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-for-loops' - Enabled: false - -Style/FormatString: - Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf' - Enabled: false - -Style/GlobalVars: - Description: 'Do not introduce global variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars' - Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html' - Enabled: false - -Style/GuardClause: - Description: 'Check for conditionals that can be replaced with guard clauses' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false - -Style/HashSyntax: - Description: >- - Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax - { :a => 1, :b => 2 }. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals' - Enabled: false - -Style/IfUnlessModifier: - Description: >- - Favor modifier if/unless usage when you have a - single-line body. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' - Enabled: false - -Style/IfWithSemicolon: - Description: 'Do not use if x; .... Use the ternary operator instead.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs' - Enabled: false - -Style/IndentationConsistency: - Description: 'Keep indentation straight.' - Enabled: false - -Style/IndentationWidth: - Description: 'Use 2 spaces for indentation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false - -Style/IndentArray: - Description: >- - Checks the indentation of the first element in an array - literal. - Enabled: false - -Style/IndentHash: - Description: 'Checks the indentation of the first key in a hash literal.' - Enabled: false - -Style/InfiniteLoop: - Description: 'Use Kernel#loop for infinite loops.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#infinite-loop' - Enabled: false - -Style/Lambda: - Description: 'Use the new lambda literal syntax for single-line blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#lambda-multi-line' - Enabled: false - -Style/LambdaCall: - Description: 'Use lambda.call(...) instead of lambda.(...).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc-call' - Enabled: false - -Style/LeadingCommentSpace: - Description: 'Comments should start with a space.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' - Enabled: false - -Style/LineEndConcatenation: - Description: >- - Use \ instead of + or << to concatenate two string literals at - line end. - Enabled: false - -Style/MethodCallParentheses: - Description: 'Do not use parentheses for method calls with no arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens' - Enabled: false - -Style/MethodDefParentheses: - Description: >- - Checks if the method definitions have or don't have - parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false - -Style/MethodName: - Description: 'Use the configured style when naming methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false - -Style/ModuleFunction: - Description: 'Checks for usage of `extend self` in modules.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function' - Enabled: false - -Style/MultilineBlockChain: - Description: 'Avoid multi-line chains of blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' - Enabled: false - -Style/MultilineBlockLayout: - Description: 'Ensures newlines after multiline block do statements.' - Enabled: false - -Style/MultilineIfThen: - Description: 'Do not use then for multi-line if/unless.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then' - Enabled: false - -Style/MultilineOperationIndentation: - Description: >- - Checks indentation of binary operations that span more than - one line. - Enabled: false - -Style/MultilineTernaryOperator: - Description: >- - Avoid multi-line ?: (the ternary operator); - use if/unless instead. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary' - Enabled: false - -Style/NegatedIf: - Description: >- - Favor unless over if for negative conditions - (or control flow or). - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives' - Enabled: false - -Style/NegatedWhile: - Description: 'Favor until over while for negative conditions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#until-for-negatives' - Enabled: false - -Style/NestedTernaryOperator: - Description: 'Use one expression per branch in a ternary operator.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-ternary' - Enabled: false - -Style/Next: - Description: 'Use `next` to skip iteration instead of a condition at the end.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false - -Style/NilComparison: - Description: 'Prefer x.nil? to x == nil.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false - -Style/NonNilCheck: - Description: 'Checks for redundant nil checks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks' - Enabled: false - -Style/Not: - Description: 'Use ! instead of not.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bang-not-not' - Enabled: false - -Style/NumericLiterals: - Description: >- - Add underscores to large numeric literals to improve their - readability. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics' - Enabled: false - -Style/OneLineConditional: - Description: >- - Favor the ternary operator(?:) over - if/then/else/end constructs. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator' - Enabled: false - -Style/OpMethod: - Description: 'When defining binary operators, name the argument other.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg' - Enabled: false - -Style/OptionalArguments: - Description: >- - Checks for optional arguments that do not appear at the end - of the argument list - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#optional-arguments' - Enabled: false - -Style/ParallelAssignment: - Description: >- - Check for simple usages of parallel assignment. - It will only warn when the number of variables - matches on both sides of the assignment. - This also provides performance benefits - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment' - Enabled: false - -Style/ParenthesesAroundCondition: - Description: >- - Don't use parentheses around the condition of an - if/unless/while. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-parens-if' - Enabled: false - -Style/PercentLiteralDelimiters: - Description: 'Use `%`-literal delimiters consistently' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-literal-braces' - Enabled: false - -Style/PercentQLiterals: - Description: 'Checks if uses of %Q/%q match the configured preference.' - Enabled: false - -Style/PerlBackrefs: - Description: 'Avoid Perl-style regex back references.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers' - Enabled: false - -Style/PredicateName: - Description: 'Check the names of predicate methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark' - Enabled: false - -Style/Proc: - Description: 'Use proc instead of Proc.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc' - Enabled: false - -Style/RaiseArgs: - Description: 'Checks the arguments passed to raise/fail.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#exception-class-messages' - Enabled: false - -Style/RedundantBegin: - Description: "Don't use begin blocks when they are not needed." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit' - Enabled: false - -Style/RedundantException: - Description: "Checks for an obsolete RuntimeException argument in raise/fail." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror' - Enabled: false - -Style/RedundantReturn: - Description: "Don't use return where it's not required." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-return' - Enabled: false - -Style/RedundantSelf: - Description: "Don't use self where it's not needed." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-self-unless-required' - Enabled: false - -Style/RegexpLiteral: - Description: 'Use / or %r around regular expressions.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r' - Enabled: false - -Style/RescueEnsureAlignment: - Description: 'Align rescues and ensures correctly.' - Enabled: false - -Style/RescueModifier: - Description: 'Avoid using rescue in its modifier form.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers' - Enabled: false - -Style/SelfAssignment: - Description: >- - Checks for places where self-assignment shorthand should have - been used. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment' - Enabled: false - -Style/Semicolon: - Description: "Don't use semicolons to terminate expressions." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon' - Enabled: false - -Style/SignalException: - Description: 'Checks for proper usage of fail and raise.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method' - Enabled: false - -Style/SingleLineBlockParams: - Description: 'Enforces the names of some block params.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#reduce-blocks' - Enabled: false - -Style/SingleLineMethods: - Description: 'Avoid single-line methods.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-single-line-methods' - Enabled: false - -Style/SpaceBeforeFirstArg: +Layout/SpaceBeforeFirstArg: Description: >- Checks that exactly one space is used between a method name and the first argument for method calls without parentheses. Enabled: true - -Style/SpaceAfterColon: - Description: 'Use spaces after colons.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceAfterComma: - Description: 'Use spaces after commas.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceAroundKeyword: - Description: 'Use spaces around keywords.' - Enabled: false - -Style/SpaceAfterMethodName: - Description: >- - Do not put a space between a method name and the opening - parenthesis in a method definition. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: false - -Style/SpaceAfterNot: - Description: Tracks redundant space after the ! operator. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-bang' - Enabled: false - -Style/SpaceAfterSemicolon: - Description: 'Use spaces after semicolons.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceBeforeBlockBraces: - Description: >- - Checks that the left block brace has or doesn't have space - before it. - Enabled: false - -Style/SpaceBeforeComma: - Description: 'No spaces before commas.' - Enabled: false - -Style/SpaceBeforeComment: - Description: >- - Checks for missing space between code and a comment on the - same line. - Enabled: false - -Style/SpaceBeforeSemicolon: - Description: 'No spaces before semicolons.' - Enabled: false - -Style/SpaceInsideBlockBraces: - Description: >- - Checks that block braces have or don't have surrounding space. - For blocks taking parameters, checks that the left brace has - or doesn't have trailing space. - Enabled: false - -Style/SpaceAroundBlockParameters: - Description: 'Checks the spacing inside and after block parameters pipes.' - Enabled: false - -Style/SpaceAroundEqualsInParameterDefault: - Description: >- - Checks that the equals signs in parameter default assignments - have or don't have surrounding space depending on - configuration. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-around-equals' - Enabled: false - -Style/SpaceAroundOperators: - Description: 'Use a single space around operators.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceInsideBrackets: - Description: 'No spaces after [ or before ].' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceInsideHashLiteralBraces: - Description: "Use spaces inside hash literal braces - or don't." - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false - -Style/SpaceInsideParens: - Description: 'No spaces after ( or before ).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceInsideRangeLiteral: - Description: 'No spaces inside range literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals' - Enabled: false - -Style/SpaceInsideStringInterpolation: - Description: 'Checks for padding/surrounding spaces inside string interpolation.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#string-interpolation' - Enabled: false - -Style/SpecialGlobalVars: - Description: 'Avoid Perl-style global variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms' - Enabled: false - -Style/StringLiterals: - Description: 'Checks if uses of quotes match the configured preference.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals' - Enabled: false - -Style/StringLiteralsInInterpolation: - Description: >- - Checks if uses of quotes inside expressions in interpolated - strings match the configured preference. - Enabled: false - -Style/StructInheritance: - Description: 'Checks for inheritance from Struct.new.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new' - Enabled: false - -Style/SymbolLiteral: - Description: 'Use plain symbols instead of string symbols when possible.' - Enabled: false - -Style/SymbolProc: - Description: 'Use symbols as procs instead of blocks when possible.' - Enabled: false - -Style/Tab: - Description: 'No hard tabs.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false - -Style/TrailingBlankLines: - Description: 'Checks trailing blank lines and final newline.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof' - Enabled: false - -Style/TrailingCommaInArguments: - Description: 'Checks for trailing comma in parameter lists.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma' - Enabled: false - -Style/TrailingCommaInLiteral: - Description: 'Checks for trailing comma in literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' - Enabled: false - -Style/TrailingWhitespace: - Description: 'Avoid trailing whitespace.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace' - Enabled: false - -Style/TrivialAccessors: - Description: 'Prefer attr_* methods to trivial readers/writers.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr_family' - Enabled: false - -Style/UnlessElse: - Description: >- - Do not use unless with else. Rewrite these with the positive - case first. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-else-with-unless' - Enabled: false - -Style/UnneededCapitalW: - Description: 'Checks for %W when interpolation is not needed.' - Enabled: false - -Style/UnneededPercentQ: - Description: 'Checks for %q/%Q when single quotes or double quotes would do.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q' - Enabled: false - -Style/TrailingUnderscoreVariable: - Description: >- - Checks for the usage of unneeded trailing underscores at the - end of parallel variable assignment. - Enabled: false - -Style/VariableInterpolation: - Description: >- - Don't interpolate global, instance and class variables - directly in strings. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#curlies-interpolate' - Enabled: false - -Style/VariableName: - Description: 'Use the configured style when naming variables.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false - -Style/WhenThen: - Description: 'Use when x then ... for one-line cases.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#one-line-cases' - Enabled: false - -Style/WhileUntilDo: - Description: 'Checks for redundant do after while or until.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-while-do' - Enabled: false - -Style/WhileUntilModifier: - Description: >- - Favor modifier while/until usage when you have a - single-line body. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier' - Enabled: false - -Style/WordArray: - Description: 'Use %w or %W for arrays of words.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w' - Enabled: false diff --git a/Gemfile b/Gemfile index 296068331..f83b2fff9 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,8 @@ gem 'bump', '~> 0.5' group :development do gem 'pry-byebug' + gem 'rubocop', '~>1.1' + gem 'rubocop-performance' gem 'sequel-annotate', '~>1.3' end @@ -39,4 +41,4 @@ end if ENV['X_PACT_DEVELOPMENT'] == 'true' gem 'pact-support', path: '../pact-support' -end \ No newline at end of file +end diff --git a/config/boot.rb b/config/boot.rb index 0621b08ba..130725216 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -9,7 +9,7 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -if File.exists?(ENV['BUNDLE_GEMFILE']) +if File.exist?(ENV['BUNDLE_GEMFILE']) require 'bundler/setup' Bundler.require end diff --git a/db/ddl_statements/latest_pact_consumer_version_orders.rb b/db/ddl_statements/latest_pact_consumer_version_orders.rb index a2b81cddb..9f7df9294 100644 --- a/db/ddl_statements/latest_pact_consumer_version_orders.rb +++ b/db/ddl_statements/latest_pact_consumer_version_orders.rb @@ -1,7 +1,7 @@ # The consumer id, provider id, and consumer version order # for the latest consumer version that has a pact with that provider. -def latest_pact_consumer_version_orders_v1(connection = nil) +def latest_pact_consumer_version_orders_v1(_connection = nil) "select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order from all_pact_publications group by provider_id, consumer_id" diff --git a/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb b/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb index 7fb60aded..757caa251 100644 --- a/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb +++ b/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb @@ -1,4 +1,4 @@ -def latest_pact_publications_by_consumer_versions_v2(connection = nil) +def latest_pact_publications_by_consumer_versions_v2(_connection = nil) "select app.* from latest_pact_publication_ids_for_consumer_versions lpp inner join all_pact_publications app @@ -8,7 +8,7 @@ def latest_pact_publications_by_consumer_versions_v2(connection = nil) end # Don't need all the join keys, just pact_publication_id -def latest_pact_publications_by_consumer_versions_v3(connection) +def latest_pact_publications_by_consumer_versions_v3(_connection) "select app.* from latest_pact_publication_ids_for_consumer_versions lpp inner join all_pact_publications app diff --git a/db/migrations/000044_populate_verifications_provider_version_id.rb b/db/migrations/000044_populate_verifications_provider_version_id.rb index 3b7807fc3..b7d18ee11 100644 --- a/db/migrations/000044_populate_verifications_provider_version_id.rb +++ b/db/migrations/000044_populate_verifications_provider_version_id.rb @@ -7,15 +7,15 @@ version = from(:versions) .where(number: line[:provider_version], pacticipant_id: line[:provider_id]).single_record version_id = if version - version[:id] - else - from(:versions).insert( - number: line[:provider_version], - pacticipant_id: line[:provider_id], - created_at: line[:created_at], - updated_at: line[:created_at] - ) - end + version[:id] + else + from(:versions).insert( + number: line[:provider_version], + pacticipant_id: line[:provider_id], + created_at: line[:created_at], + updated_at: line[:created_at] + ) + end from(:verifications).where(id: line[:id]).update(provider_version_id: version_id) end end diff --git a/db/migrations/20180311_optimise_head_matrix.rb b/db/migrations/20180311_optimise_head_matrix.rb index 034e97d7b..6aca56b99 100644 --- a/db/migrations/20180311_optimise_head_matrix.rb +++ b/db/migrations/20180311_optimise_head_matrix.rb @@ -3,7 +3,6 @@ Sequel.migration do up do - pp = :pact_publications # For each consumer_id/provider_id/tag_name, the version order of the latest version that has a pact create_or_replace_view(:latest_tagged_pact_consumer_version_orders, latest_tagged_pact_consumer_version_orders_v2(self)) diff --git a/db/test/backwards_compatibility/config.ru b/db/test/backwards_compatibility/config.ru index a2a453bd5..ac7855542 100644 --- a/db/test/backwards_compatibility/config.ru +++ b/db/test/backwards_compatibility/config.ru @@ -9,7 +9,7 @@ FileUtils.touch "pids/#{Process.pid}" DATABASE_CREDENTIALS = {adapter: "sqlite", database: "pact_broker_database.sqlite3", :encoding => 'utf8'} app = PactBroker::App.new do | config | - config.logger.formatter = proc do |severity, datetime, progname, msg| + config.logger.formatter = proc do |severity, _datetime, _progname, msg| "v#{PactBroker::VERSION} #{severity} -- : #{msg}\n" end config.database_connection = Sequel.connect(DATABASE_CREDENTIALS.merge(:logger => config.logger)) diff --git a/db/test/backwards_compatibility/spec/publish_pact_spec.rb b/db/test/backwards_compatibility/spec/publish_pact_spec.rb index d2bf95504..cee52dbb2 100644 --- a/db/test/backwards_compatibility/spec/publish_pact_spec.rb +++ b/db/test/backwards_compatibility/spec/publish_pact_spec.rb @@ -32,7 +32,7 @@ subject { put path, nil, {'CONTENT_TYPE' => 'application/json' }; last_response } it "returns a success status" do - expect(subject.status.to_s).to match /20\d/ + expect(subject.status.to_s).to match(/20\d/) end end @@ -40,7 +40,7 @@ subject { put path, pact_content, {'CONTENT_TYPE' => 'application/json' }; last_response } it "returns a success status" do - expect(subject.status.to_s).to match /20\d/ + expect(subject.status.to_s).to match(/20\d/) end end diff --git a/lib/db.rb b/lib/db.rb index 84f1637c5..ec8f6f75a 100644 --- a/lib/db.rb +++ b/lib/db.rb @@ -39,9 +39,11 @@ def self.connect db_credentials con.extension(:pagination) con.extension(:statement_timeout) con.extend_datasets do + # rubocop: disable Lint/NestedMethodDefinition def any? !empty? end + # rubocop: enable Lint/NestedMethodDefinition end con.pool.connection_validation_timeout = -1 #Check the connection on every request con.timezone = :utc @@ -72,7 +74,7 @@ def self.postgres? PACT_BROKER_DB ||= connection_for_env ENV.fetch('RACK_ENV') def self.health_check - PACT_BROKER_DB.synchronize do |c| c + PACT_BROKER_DB.synchronize do |c| PACT_BROKER_DB.valid_connection? c end end diff --git a/lib/pact/doc/generator.rb b/lib/pact/doc/generator.rb index 63b15f57b..9d762acbc 100644 --- a/lib/pact/doc/generator.rb +++ b/lib/pact/doc/generator.rb @@ -14,7 +14,7 @@ def initialize pact_dir, doc_dir, options @file_extension = options[:file_extension] @index_renderer = options[:index_renderer] @index_name = options[:index_name] - @after = options.fetch(:after, lambda{|pact_dir, target_dir, consumer_contracts| }) + @after = options.fetch(:after, lambda{|pact_dir_arg, target_dir_arg, consumer_contracts_arg| }) end def call diff --git a/lib/pact/doc/interaction_view_model.rb b/lib/pact/doc/interaction_view_model.rb index 49e5b4dd8..38ceedbe4 100644 --- a/lib/pact/doc/interaction_view_model.rb +++ b/lib/pact/doc/interaction_view_model.rb @@ -18,10 +18,10 @@ def initialize interaction, consumer_contract def id @id ||= begin full_desc = if has_provider_state? - "#{description} given #{interaction.provider_state}" - else - description - end + "#{description} given #{interaction.provider_state}" + else + description + end CGI.escapeHTML(full_desc.gsub(/\s+/,'_')) end end diff --git a/lib/pact/doc/sort_interactions.rb b/lib/pact/doc/sort_interactions.rb index 3a440e270..c2785867a 100644 --- a/lib/pact/doc/sort_interactions.rb +++ b/lib/pact/doc/sort_interactions.rb @@ -5,7 +5,6 @@ def self.call interactions interactions.sort{|a, b| sortable_id(a) <=> sortable_id(b)} end - private def self.sortable_id interaction "#{(interaction.description || '').downcase} #{interaction.response.status} #{(interaction.provider_state || '').downcase}" diff --git a/lib/pact_broker/api.rb b/lib/pact_broker/api.rb index f46c8f1e3..307ab2e28 100644 --- a/lib/pact_broker/api.rb +++ b/lib/pact_broker/api.rb @@ -24,6 +24,7 @@ def really_put? end module PactBroker + # rubocop: disable Metrics/MethodLength def self.build_api(application_context = PactBroker::ApplicationContext.default_application_context) pact_api = Webmachine::Application.new do |app| app.routes do @@ -149,4 +150,5 @@ def self.build_api(application_context = PactBroker::ApplicationContext.default_ API ||= begin build_api end + # rubocop: enable Metrics/MethodLength end diff --git a/lib/pact_broker/api/contracts/dry_validation_workarounds.rb b/lib/pact_broker/api/contracts/dry_validation_workarounds.rb index 3c1a8390b..c1a77a1d2 100644 --- a/lib/pact_broker/api/contracts/dry_validation_workarounds.rb +++ b/lib/pact_broker/api/contracts/dry_validation_workarounds.rb @@ -14,12 +14,8 @@ def select_first_message(messages) end def flatten_array_of_hashes(array_of_hashes) - new_messages = array_of_hashes.collect do | index, hash_or_array | - array = if hash_or_array.is_a?(Hash) - hash_or_array.values.flatten - else - hash_or_array - end + array_of_hashes.collect do | index, hash_or_array | + array = hash_or_array.is_a?(Hash) ? hash_or_array.values.flatten : hash_or_array array.collect { | text | "#{text} at index #{index}"} end.flatten end diff --git a/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb b/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb index a4819920c..ddf40f2ac 100644 --- a/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +++ b/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb @@ -74,6 +74,7 @@ def self.not_provided?(value) # when setting a tag, latest=true and latest=false are both valid # when setting the branch, it doesn't make sense to verify all pacts for a branch, # so latest is not required, but cannot be set to false + # rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength def self.validate_consumer_version_selector(selector, index) errors = [] @@ -118,6 +119,7 @@ def self.validate_consumer_version_selector(selector, index) errors end + # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength end end end diff --git a/lib/pact_broker/api/contracts/webhook_contract.rb b/lib/pact_broker/api/contracts/webhook_contract.rb index c86b5a86a..e5b97ad4f 100644 --- a/lib/pact_broker/api/contracts/webhook_contract.rb +++ b/lib/pact_broker/api/contracts/webhook_contract.rb @@ -20,7 +20,10 @@ def validate(*) @first_errors.messages[key] = @first_errors.messages[key][0...1] end + # rubocop: disable Lint/NestedMethodDefinition def self.errors; @first_errors end + # rubocop: enable Lint/NestedMethodDefinition + result end diff --git a/lib/pact_broker/api/decorators/dashboard_decorator.rb b/lib/pact_broker/api/decorators/dashboard_decorator.rb index 73e8f8c0d..b440630ff 100644 --- a/lib/pact_broker/api/decorators/dashboard_decorator.rb +++ b/lib/pact_broker/api/decorators/dashboard_decorator.rb @@ -27,7 +27,7 @@ def to_hash(options) attr_reader :index_items - def items(index_items, base_url) + def items(_index_items, base_url) sorted_index_items.collect do | index_item | index_item_hash(index_item.consumer, index_item.provider, index_item.consumer_version, index_item, base_url) end @@ -53,7 +53,7 @@ def index_item_hash(consumer, provider, consumer_version, index_item, base_url) } end - def consumer_hash(index_item, consumer, consumer_version, base_url) + def consumer_hash(index_item, _consumer, _consumer_version, base_url) { name: index_item.consumer_name, version: { @@ -73,7 +73,7 @@ def consumer_hash(index_item, consumer, consumer_version, base_url) } end - def provider_hash(index_item, provider, base_url) + def provider_hash(index_item, _provider, base_url) hash = { name: index_item.provider_name, version: nil, @@ -153,7 +153,7 @@ def verification_tags(index_item, base_url) end end - def latest_webhook_execution(index_item, base_url) + def latest_webhook_execution(index_item, _base_url) if index_item.last_webhook_execution_date { triggeredAt: format_date_time(index_item.last_webhook_execution_date) diff --git a/lib/pact_broker/api/decorators/dashboard_text_decorator.rb b/lib/pact_broker/api/decorators/dashboard_text_decorator.rb index fdb93ab8a..486e95ec3 100644 --- a/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +++ b/lib/pact_broker/api/decorators/dashboard_text_decorator.rb @@ -27,7 +27,7 @@ def to_text(options) attr_reader :index_items - def items(index_items, base_url) + def items(index_items, _base_url) index_items.collect do | index_item | index_item_object(index_item) end diff --git a/lib/pact_broker/api/decorators/matrix_decorator.rb b/lib/pact_broker/api/decorators/matrix_decorator.rb index ef72dbcb9..4163ff1f1 100644 --- a/lib/pact_broker/api/decorators/matrix_decorator.rb +++ b/lib/pact_broker/api/decorators/matrix_decorator.rb @@ -67,6 +67,7 @@ def hash_for_row(line, base_url) line_hash(consumer, provider, consumer_version, provider_version, line, base_url) end + # rubocop: disable Metrics/ParameterLists def line_hash(consumer, provider, consumer_version, provider_version, line, base_url) { consumer: consumer_hash(line, consumer, consumer_version, base_url), @@ -75,6 +76,7 @@ def line_hash(consumer, provider, consumer_version, provider_version, line, base verificationResult: verification_hash(line, base_url) } end + # rubocop: enable Metrics/ParameterLists def consumer_hash(line, consumer, consumer_version, base_url) { diff --git a/lib/pact_broker/api/decorators/matrix_text_decorator.rb b/lib/pact_broker/api/decorators/matrix_text_decorator.rb index f9f9f3d19..36d62911e 100644 --- a/lib/pact_broker/api/decorators/matrix_text_decorator.rb +++ b/lib/pact_broker/api/decorators/matrix_text_decorator.rb @@ -14,7 +14,7 @@ def initialize(lines) @lines = lines end - def to_text(options) + def to_text(_options) json_decorator = PactBroker::Api::Decorators::MatrixDecorator.new(lines) data = lines.collect do | line | Line.new(line.consumer_name, line.consumer_version_number, line.pact_revision_number, line.provider_name, line.provider_version_number, line.verification_number, line.success) diff --git a/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb b/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb index 40fb1a58e..4d7b60f62 100644 --- a/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb @@ -71,8 +71,8 @@ class PactWebhooksStatusDecorator < BaseDecorator end def summary - counts = represented.group_by(&:status).each_with_object({}) do | (status, triggered_webhooks), counts | - counts[status] = triggered_webhooks.count + counts = represented.group_by(&:status).each_with_object({}) do | (status, triggered_webhooks), count | + count[status] = triggered_webhooks.count end OpenStruct.new(counts) end diff --git a/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb b/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb index ace3bc44f..5881b370f 100644 --- a/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb +++ b/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb @@ -34,7 +34,7 @@ class PacticipantCollectionDecorator < BaseDecorator end class DeprecatedPacticipantDecorator < PactBroker::Api::Decorators::PacticipantDecorator - property :title, getter: ->(something) { "DEPRECATED - Please use the embedded pacticipants collection" } + property :title, getter: ->(_something) { "DEPRECATED - Please use the embedded pacticipants collection" } end class NonEmbeddedPacticipantCollectionDecorator < BaseDecorator diff --git a/lib/pact_broker/api/decorators/provider_pacts_decorator.rb b/lib/pact_broker/api/decorators/provider_pacts_decorator.rb index 30ad076f0..7944951ee 100644 --- a/lib/pact_broker/api/decorators/provider_pacts_decorator.rb +++ b/lib/pact_broker/api/decorators/provider_pacts_decorator.rb @@ -7,7 +7,6 @@ module Decorators class ProviderPactsDecorator < BaseDecorator link :self do | context | - suffix = context[:tag] ? " with tag '#{context[:tag]}'" : "" { href: context[:resource_url], title: context[:title] diff --git a/lib/pact_broker/api/decorators/reason_decorator.rb b/lib/pact_broker/api/decorators/reason_decorator.rb index 862d66836..cb90e4d2b 100644 --- a/lib/pact_broker/api/decorators/reason_decorator.rb +++ b/lib/pact_broker/api/decorators/reason_decorator.rb @@ -22,6 +22,7 @@ def to_s attr_reader :reason, :ignored + # rubocop: disable Metrics/CyclomaticComplexity def reason_text case reason when PactBroker::Matrix::PactNotEverVerifiedByProvider @@ -74,6 +75,7 @@ def interaction_description(interaction) end end end + # rubocop: enable Metrics/CyclomaticComplexity end end end diff --git a/lib/pact_broker/api/decorators/relationships_csv_decorator.rb b/lib/pact_broker/api/decorators/relationships_csv_decorator.rb index b0ba7ceab..94723a4bc 100644 --- a/lib/pact_broker/api/decorators/relationships_csv_decorator.rb +++ b/lib/pact_broker/api/decorators/relationships_csv_decorator.rb @@ -9,6 +9,7 @@ def initialize pacts @index_items = pacts.collect{|pact| PactBroker::Domain::IndexItem.new(pact.consumer, pact.provider)} end + # rubocop: disable Metrics/CyclomaticComplexity def to_csv hash = {} @@ -32,6 +33,7 @@ def to_csv end end end + # rubocop: enable Metrics/CyclomaticComplexity def pacticipant_array pacticipant, order [pacticipant.id, pacticipant.name, 1, 1, 0, order] diff --git a/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb b/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb index 76372f67a..b8f3cc24b 100644 --- a/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +++ b/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb @@ -25,7 +25,7 @@ def headers def body begin ::JSON.parse(represented.body) - rescue StandardError => e + rescue StandardError => _ex represented.body end end @@ -50,7 +50,7 @@ def headers def body begin ::JSON.parse(represented.body) - rescue StandardError => e + rescue StandardError => _ex represented.body end end diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index b7a47a1d6..07de845b1 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -271,7 +271,7 @@ def badge_url_for_latest_pact pact, base_url = '' "#{latest_pact_url(base_url, pact)}/badge.svg" end - def matrix_url consumer_name, provider_name, base_url = '' + def matrix_url consumer_name, provider_name, _base_url = '' "/matrix/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}" end @@ -322,11 +322,11 @@ def released_versions_for_version_and_environment_url(version, environment, base "#{version_url(base_url, version)}/released-versions/environment/#{environment.uuid}" end - def deployed_version_url(deployed_version, base_url = '') + def deployed_version_url(deployed_version, _base_url = '') "/deployed-versions/#{deployed_version.uuid}" end - def released_version_url(released_version, base_url = '') + def released_version_url(released_version, _base_url = '') "/released-versions/#{released_version.uuid}" end diff --git a/lib/pact_broker/api/renderers/html_pact_renderer.rb b/lib/pact_broker/api/renderers/html_pact_renderer.rb index 79de9c24b..ad842e359 100644 --- a/lib/pact_broker/api/renderers/html_pact_renderer.rb +++ b/lib/pact_broker/api/renderers/html_pact_renderer.rb @@ -102,10 +102,10 @@ def badge_markdown_item def badge_markdown warning = if badges_protected? - "If the broker is protected by authentication, set `enable_public_badge_access` to true in the configuration to enable badges to be embedded in a markdown file.\n" - else - "" - end + "If the broker is protected by authentication, set `enable_public_badge_access` to true in the configuration to enable badges to be embedded in a markdown file.\n" + else + "" + end "#{warning}[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})" end diff --git a/lib/pact_broker/api/resources/default_base_resource.rb b/lib/pact_broker/api/resources/default_base_resource.rb index 5e9090df0..4f45f5ba0 100644 --- a/lib/pact_broker/api/resources/default_base_resource.rb +++ b/lib/pact_broker/api/resources/default_base_resource.rb @@ -114,6 +114,7 @@ def handle_exception(error) response.body = application_context.error_response_body_generator.call(error, error_reference, request.env) end + # rubocop: disable Metrics/CyclomaticComplexity def params(options = {}) return options[:default] if options.key?(:default) && request_body.empty? @@ -126,6 +127,7 @@ def params(options = {}) rescue JSON::JSONError => e raise InvalidJsonError.new("Error parsing JSON - #{e.message}") end + # rubocop: enable Metrics/CyclomaticComplexity def params_with_string_keys params(symbolize_names: false) diff --git a/lib/pact_broker/api/resources/deployed_versions_for_environment.rb b/lib/pact_broker/api/resources/deployed_versions_for_environment.rb index 6650aa874..816b53594 100644 --- a/lib/pact_broker/api/resources/deployed_versions_for_environment.rb +++ b/lib/pact_broker/api/resources/deployed_versions_for_environment.rb @@ -31,8 +31,6 @@ def policy_name private - attr_reader :deployed_versions - def environment @environment ||= environment_service.find(environment_uuid) end diff --git a/lib/pact_broker/api/resources/environments.rb b/lib/pact_broker/api/resources/environments.rb index 3fa85409e..96a724abd 100644 --- a/lib/pact_broker/api/resources/environments.rb +++ b/lib/pact_broker/api/resources/environments.rb @@ -64,10 +64,10 @@ def uuid def environments @environments ||= if request.query['name'] - [environment_service.find_by_name(request.query['name'])] - else - environment_service.find_all - end + [environment_service.find_by_name(request.query['name'])] + else + environment_service.find_all + end end def schema diff --git a/lib/pact_broker/api/resources/error_response_body_generator.rb b/lib/pact_broker/api/resources/error_response_body_generator.rb index aed8b54c7..a90beef90 100644 --- a/lib/pact_broker/api/resources/error_response_body_generator.rb +++ b/lib/pact_broker/api/resources/error_response_body_generator.rb @@ -7,7 +7,7 @@ class ErrorResponseBodyGenerator include PactBroker::Logging # env not needed, just passing in in case PF ever needs it - def self.call error, error_reference, env = {} + def self.call error, error_reference, _env = {} response_body_hash(error, error_reference).to_json end diff --git a/lib/pact_broker/api/resources/index.rb b/lib/pact_broker/api/resources/index.rb index dae795ad7..dd3421930 100644 --- a/lib/pact_broker/api/resources/index.rb +++ b/lib/pact_broker/api/resources/index.rb @@ -18,6 +18,7 @@ def to_json { _links: links }.to_json end + # rubocop: disable Metrics/MethodLength def links links_hash = { 'self' => @@ -176,6 +177,7 @@ def links links_hash end + # rubocop: enable Metrics/MethodLength def policy_name :'index::index' diff --git a/lib/pact_broker/api/resources/released_version.rb b/lib/pact_broker/api/resources/released_version.rb index a767dffb5..fb39b747f 100644 --- a/lib/pact_broker/api/resources/released_version.rb +++ b/lib/pact_broker/api/resources/released_version.rb @@ -31,8 +31,6 @@ def policy_record private - attr_reader :released_version - def released_version @released_version ||= released_version_service.find_by_uuid(uuid) end diff --git a/lib/pact_broker/app.rb b/lib/pact_broker/app.rb index ec50d31e5..0ce03457a 100644 --- a/lib/pact_broker/app.rb +++ b/lib/pact_broker/app.rb @@ -28,7 +28,7 @@ class App attr_accessor :configuration - def initialize &block + def initialize @app_builder = ::Rack::Builder.new @cascade_apps = [] @make_it_later_api_auth = ::Rack::PactBroker::ConfigurableMakeItLater.new(Rack::PactBroker::NoAuth) @@ -50,7 +50,7 @@ def initialize &block # the middleware with the app, and run it manually. # eg run MyMiddleware.new(app) def use *args, &block - @app_builder.use *args, &block + @app_builder.use(*args, &block) end # private API, not sure if this will continue to be supported @@ -126,9 +126,11 @@ def configure_database_connection PactBroker::DB.connection = configuration.database_connection PactBroker::DB.connection.timezone = :utc PactBroker::DB.connection.extend_datasets do + # rubocop: disable Lint/NestedMethodDefinition def any? !empty? end + # rubocop: enable Lint/NestedMethodDefinition end PactBroker::DB.validate_connection_config if configuration.validate_database_connection_config PactBroker::DB.set_mysql_strict_mode_if_mysql diff --git a/lib/pact_broker/badges/service.rb b/lib/pact_broker/badges/service.rb index 0d2ddfa28..237dc3fad 100644 --- a/lib/pact_broker/badges/service.rb +++ b/lib/pact_broker/badges/service.rb @@ -58,7 +58,7 @@ def badge_title pact, label, initials, metadata when 'consumer' then consumer_name when 'provider' then provider_name else "#{consumer_name}/#{provider_name}" - end + end "#{title} pact".downcase end @@ -150,11 +150,11 @@ def with_cache uri def static_svg pact, pseudo_branch_verification_status file_name = case pseudo_branch_verification_status - when :success then "pact-verified-brightgreen.svg" - when :failed then "pact-failed-red.svg" - when :stale then "pact-changed-orange.svg" - else "pact-unknown-lightgrey.svg" - end + when :success then "pact-verified-brightgreen.svg" + when :failed then "pact-failed-red.svg" + when :stale then "pact-changed-orange.svg" + else "pact-unknown-lightgrey.svg" + end file_name = "pact_not_found-unknown-lightgrey.svg" unless pact File.read(PactBroker.project_root.join("public", "images", file_name)) end diff --git a/lib/pact_broker/certificates/service.rb b/lib/pact_broker/certificates/service.rb index 4d66654b5..de5d8b92a 100644 --- a/lib/pact_broker/certificates/service.rb +++ b/lib/pact_broker/certificates/service.rb @@ -18,7 +18,7 @@ def cert_store logger.debug("Loading certificate #{certificate.subject} in to cert store") cert_store.add_cert(certificate) rescue StandardError => e - logger.warn("Error adding certificate object #{certificate.to_s} to store", e) + logger.warn("Error adding certificate object #{certificate} to store", e) end end cert_store diff --git a/lib/pact_broker/config/setting.rb b/lib/pact_broker/config/setting.rb index f63598b7e..939d3df42 100644 --- a/lib/pact_broker/config/setting.rb +++ b/lib/pact_broker/config/setting.rb @@ -8,6 +8,7 @@ def set_value_from(object) self end + # rubocop: disable Metrics/CyclomaticComplexity def value_object case type when 'json' @@ -26,6 +27,7 @@ def value_object value == "1" end end + # rubocop: enable Metrics/CyclomaticComplexity def self.get_db_value(object) case object @@ -44,6 +46,7 @@ def self.get_db_value(object) end end + # rubocop: disable Metrics/CyclomaticComplexity def self.get_db_type(object) case object when true, false @@ -62,8 +65,9 @@ def self.get_db_type(object) 'symbol' else nil - end + end end + # rubocop: enable Metrics/CyclomaticComplexity end diff --git a/lib/pact_broker/configuration.rb b/lib/pact_broker/configuration.rb index d8b2e42b8..ee7dba958 100644 --- a/lib/pact_broker/configuration.rb +++ b/lib/pact_broker/configuration.rb @@ -74,6 +74,7 @@ def initialize @semantic_logger = SemanticLogger["root"] end + # rubocop: disable Metrics/MethodLength def self.default_configuration require 'pact_broker/versions/parse_semantic_version' require 'pact_broker/pacts/generate_sha' @@ -134,6 +135,7 @@ def self.default_configuration config.metrics_sql_statement_timeout = 30 config end + # rubocop: enable Metrics/MethodLength def logger custom_logger || @semantic_logger diff --git a/lib/pact_broker/contracts/contract_to_publish.rb b/lib/pact_broker/contracts/contract_to_publish.rb index f6367842d..99c0f7f65 100644 --- a/lib/pact_broker/contracts/contract_to_publish.rb +++ b/lib/pact_broker/contracts/contract_to_publish.rb @@ -1,9 +1,11 @@ module PactBroker module Contracts ContractToPublish = Struct.new(:consumer_name, :provider_name, :decoded_content, :content_type, :specification, :on_conflict) do + # rubocop: disable Metrics/ParameterLists def self.from_hash(consumer_name: nil, provider_name: nil, decoded_content: nil, content_type: nil, specification: nil, on_conflict: nil) new(consumer_name, provider_name, decoded_content, content_type, specification, on_conflict) end + # rubocop: enable Metrics/ParameterLists def pact? specification == "pact" diff --git a/lib/pact_broker/contracts/contracts_to_publish.rb b/lib/pact_broker/contracts/contracts_to_publish.rb index 7c0a256a3..dd6df5a24 100644 --- a/lib/pact_broker/contracts/contracts_to_publish.rb +++ b/lib/pact_broker/contracts/contracts_to_publish.rb @@ -1,9 +1,11 @@ module PactBroker module Contracts ContractsToPublish = Struct.new(:pacticipant_name, :pacticipant_version_number, :tags, :branch, :build_url, :contracts) do + # rubocop: disable Metrics/ParameterLists def self.from_hash(pacticipant_name: nil, pacticipant_version_number: nil, tags: nil, branch: nil, build_url: nil, contracts: nil) new(pacticipant_name, pacticipant_version_number, tags, branch, build_url, contracts) end + # rubocop: enable Metrics/ParameterLists end end end diff --git a/lib/pact_broker/contracts/service.rb b/lib/pact_broker/contracts/service.rb index 822326f8e..033e478b3 100644 --- a/lib/pact_broker/contracts/service.rb +++ b/lib/pact_broker/contracts/service.rb @@ -150,6 +150,7 @@ def message_key_for_version_creation(parsed_contracts) private :message_key_for_version_creation + # rubocop: disable Metrics/ParameterLists def notices_for_pact(parsed_contracts, contract_to_publish, existing_pact, created_pact, listener, base_url) notices = [] notices << notice_for_pact_publication(parsed_contracts, contract_to_publish.merge?, existing_pact, created_pact) @@ -158,6 +159,7 @@ def notices_for_pact(parsed_contracts, contract_to_publish, existing_pact, creat notices.concat(next_steps_notices(created_pact)) notices end + # rubocop: enable Metrics/ParameterLists private :notices_for_pact diff --git a/lib/pact_broker/date_helper.rb b/lib/pact_broker/date_helper.rb index 60d626e4a..076bea91a 100644 --- a/lib/pact_broker/date_helper.rb +++ b/lib/pact_broker/date_helper.rb @@ -3,7 +3,7 @@ module DateHelper extend self - #Ripped from actionview/lib/action_view/helpers/date_helper.rb + # Ripped from actionview/lib/action_view/helpers/date_helper.rb def local_date_in_words datetime datetime.to_time.localtime.to_datetime.strftime("%a %d %b %Y, %l:%M%P %:z").gsub(' ', ' ') @@ -19,6 +19,7 @@ def t path, options end end + # rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength def distance_of_time_in_words(from_time, to_time = 0, options = {}) options = { scope: :'datetime.distance_in_words' @@ -87,7 +88,8 @@ def distance_of_time_in_words(from_time, to_time = 0, options = {}) else locale.t(:almost_x_years, :count => distance_in_years + 1) end - end end + end + # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength end end diff --git a/lib/pact_broker/db.rb b/lib/pact_broker/db.rb index 3f78405a8..094ea221a 100644 --- a/lib/pact_broker/db.rb +++ b/lib/pact_broker/db.rb @@ -42,7 +42,7 @@ def self.truncate database_connection, options = {} if !exceptions.include?(table_name) begin database_connection[table_name].truncate - rescue StandardError => e + rescue StandardError => _ex puts "Could not truncate table #{table_name}" end end diff --git a/lib/pact_broker/db/clean.rb b/lib/pact_broker/db/clean.rb index 7d625149d..142ed8a80 100644 --- a/lib/pact_broker/db/clean.rb +++ b/lib/pact_broker/db/clean.rb @@ -8,16 +8,12 @@ module DB class Clean include PactBroker::Logging - class Unionable < Array - alias_method :union, :+ - def union(other) Unionable.new(self + other) end end - def self.call database_connection, options = {} new(database_connection, options).call end diff --git a/lib/pact_broker/db/clean_incremental.rb b/lib/pact_broker/db/clean_incremental.rb index a8a3d75f4..8b6afd578 100644 --- a/lib/pact_broker/db/clean_incremental.rb +++ b/lib/pact_broker/db/clean_incremental.rb @@ -59,7 +59,7 @@ def call dry_run_results else before_counts = current_counts - result = PactBroker::Domain::Version.where(id: resolve_ids(version_ids_to_delete)).delete + PactBroker::Domain::Version.where(id: resolve_ids(version_ids_to_delete)).delete delete_orphan_pact_versions after_counts = current_counts @@ -167,7 +167,7 @@ def dry_run_to_delete .where(id: version_ids_to_delete.select(:id)) .all .group_by{ | v | v.pacticipant_id } - .each_with_object({}) do | (pacticipant_id, versions), thing | + .each_with_object({}) do | (_pacticipant_id, versions), thing | thing[versions.first.pacticipant.name] = { "count" => versions.count, "fromVersion" => version_info(versions.first), @@ -176,6 +176,7 @@ def dry_run_to_delete end end + # rubocop: disable Metrics/CyclomaticComplexity def dry_run_to_keep latest_to_keep = dry_run_latest_versions_to_keep.eager(:tags).each_with_object({}) do | version, r | r[version.pacticipant_id] = { @@ -197,6 +198,7 @@ def dry_run_to_keep .merge(latest_to_keep[pacticipant_id] || {}) end end + # rubocop: enable Metrics/CyclomaticComplexity def counts_to_keep db[:versions].where(id: version_ids_to_delete.select(:id)) diff --git a/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb b/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb index ff54b45fb..840f88580 100644 --- a/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb +++ b/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb @@ -8,7 +8,7 @@ class SetPacticipantMainBranch include PactBroker::Logging extend Helpers - def self.call(connection, options = {}) + def self.call(connection, _options = {}) if required_columns_exist?(connection) connection[:pacticipants].select(:id, :name).where(main_branch: nil).each do | pacticipant_row | set_main_branch(connection, pacticipant_row) diff --git a/lib/pact_broker/db/migrate_data.rb b/lib/pact_broker/db/migrate_data.rb index 4f53e9ff9..f6de40be1 100644 --- a/lib/pact_broker/db/migrate_data.rb +++ b/lib/pact_broker/db/migrate_data.rb @@ -13,7 +13,7 @@ module PactBroker module DB class MigrateData - def self.call database_connection, options = {} + def self.call database_connection, _options = {} DataMigrations::SetPacticipantIdsForVerifications.call(database_connection) DataMigrations::SetConsumerIdsForPactPublications.call(database_connection) DataMigrations::SetLatestVersionSequenceValue.call(database_connection) diff --git a/lib/pact_broker/deployments/environment_service.rb b/lib/pact_broker/deployments/environment_service.rb index 93d4c15d4..568738724 100644 --- a/lib/pact_broker/deployments/environment_service.rb +++ b/lib/pact_broker/deployments/environment_service.rb @@ -44,7 +44,7 @@ def self.delete(uuid) PactBroker::Deployments::Environment.where(uuid: uuid).delete end - def self.find_for_pacticipant(pacticipant) + def self.find_for_pacticipant(_pacticipant) find_all end end diff --git a/lib/pact_broker/diagnostic/app.rb b/lib/pact_broker/diagnostic/app.rb index e0c36a007..37af738f0 100644 --- a/lib/pact_broker/diagnostic/app.rb +++ b/lib/pact_broker/diagnostic/app.rb @@ -19,8 +19,8 @@ def call env end def build_diagnostic_app - app = Webmachine::Application.new do |app| - app.routes do + app = Webmachine::Application.new do |webmachine_app| + webmachine_app.routes do add ['diagnostic','status','heartbeat'], Diagnostic::Resources::Heartbeat, {resource_name: 'diagnostic_heartbeat'} add ['diagnostic','status','dependencies'], Diagnostic::Resources::Dependencies, {resource_name: 'diagnostic_dependencies'} end diff --git a/lib/pact_broker/domain/index_item.rb b/lib/pact_broker/domain/index_item.rb index d50b6e774..8604c9e5e 100644 --- a/lib/pact_broker/domain/index_item.rb +++ b/lib/pact_broker/domain/index_item.rb @@ -33,6 +33,7 @@ def initialize(consumer, provider, latest_pact = nil, latest = true, latest_veri end # rubocop:enable Metrics/ParameterLists + # rubocop: disable Metrics/CyclomaticComplexity def eq? other IndexItem === other && other.consumer == consumer && other.provider == provider && other.latest_pact == latest_pact && @@ -41,6 +42,7 @@ def eq? other other.webhooks == webhooks && other.latest_for_branch? == latest_for_branch? end + # rubocop: enable Metrics/CyclomaticComplexity def == other eq?(other) @@ -148,12 +150,6 @@ def include? pacticipant pacticipant.id == consumer.id || pacticipant.id == provider.id end - def <=> other - comp = consumer_name <=> other.consumer_name - return comp unless comp == 0 - provider_name <=> other.provider_name - end - # Add logic for ignoring case def <=> other comparisons = [ diff --git a/lib/pact_broker/domain/pact.rb b/lib/pact_broker/domain/pact.rb index 4b5af7f0b..96744086d 100644 --- a/lib/pact_broker/domain/pact.rb +++ b/lib/pact_broker/domain/pact.rb @@ -17,14 +17,13 @@ class Pact attr_accessor :id, :provider, :consumer_version, - :consumer, :created_at, :json_content, :consumer_version_number, :revision_number, :pact_version_sha, - :latest_verification, :head_tag_names + attr_writer :consumer, :latest_verification def initialize attributes = {} @latest_verification = UnsetAttribute.new @@ -61,7 +60,7 @@ def to_s "Pact: consumer=#{consumer.name} provider=#{provider.name}" end - def to_json options = {} + def to_json _options = {} json_content end diff --git a/lib/pact_broker/domain/tag.rb b/lib/pact_broker/domain/tag.rb index a7a50775f..b825fc54d 100644 --- a/lib/pact_broker/domain/tag.rb +++ b/lib/pact_broker/domain/tag.rb @@ -128,6 +128,7 @@ def head_tags_for_pact_publication(pact_publication) end end + # rubocop: disable Metrics/CyclomaticComplexity def before_save if version if version.order && self.version_order.nil? @@ -149,6 +150,7 @@ def before_save super end end + # rubocop: enable Metrics/CyclomaticComplexity def latest_for_pacticipant? head_tag == self diff --git a/lib/pact_broker/domain/verification.rb b/lib/pact_broker/domain/verification.rb index 4292eb982..879fed8df 100644 --- a/lib/pact_broker/domain/verification.rb +++ b/lib/pact_broker/domain/verification.rb @@ -65,7 +65,7 @@ def latest_verifications_for_all_consumer_version_tags } thing = base_query - .left_join(base_query, base_join, { table_alias: :v2 }) do | table, joined_table, something | + .left_join(base_query, base_join, { table_alias: :v2 }) do | _table, _joined_table, _something | :v2[:verification_id] > :v[:verification_id] end.where(:v2[:verification_id] => nil) diff --git a/lib/pact_broker/domain/version.rb b/lib/pact_broker/domain/version.rb index befe17cc3..3fa703a71 100644 --- a/lib/pact_broker/domain/version.rb +++ b/lib/pact_broker/domain/version.rb @@ -135,6 +135,7 @@ def delete super end + # rubocop: disable Metrics/CyclomaticComplexity def for_selector(selector) query = self query = query.where_pacticipant_name(selector.pacticipant_name) if selector.pacticipant_name @@ -150,6 +151,7 @@ def for_selector(selector) query end end + # rubocop: enable Metrics/CyclomaticComplexity # private diff --git a/lib/pact_broker/domain/webhook.rb b/lib/pact_broker/domain/webhook.rb index a4f583c62..7ad88d8cc 100644 --- a/lib/pact_broker/domain/webhook.rb +++ b/lib/pact_broker/domain/webhook.rb @@ -108,7 +108,7 @@ def execute_request(webhook_request) return http_response, error end - def template_parameters(pact, verification, event_context, options) + def template_parameters(pact, verification, event_context, _options) PactBroker::Webhooks::PactAndVerificationParameters.new(pact, verification, event_context).to_hash end diff --git a/lib/pact_broker/errors/error_logger.rb b/lib/pact_broker/errors/error_logger.rb index ff940b550..911d943ee 100644 --- a/lib/pact_broker/errors/error_logger.rb +++ b/lib/pact_broker/errors/error_logger.rb @@ -7,7 +7,7 @@ class ErrorLogger include PactBroker::Logging # don't need the env, just in case PF needs it - def self.call(error, error_reference, env = {}) + def self.call(error, error_reference, _env = {}) if log_as_warning?(error) logger.warn("Error reference #{error_reference}", error) elsif PactBroker::Errors.reportable_error?(error) diff --git a/lib/pact_broker/hash_refinements.rb b/lib/pact_broker/hash_refinements.rb index 610c9e6ec..06afa1ac3 100644 --- a/lib/pact_broker/hash_refinements.rb +++ b/lib/pact_broker/hash_refinements.rb @@ -49,7 +49,7 @@ def snakecase_keys_private(params) when Symbol then key.to_s.snakecase.to_sym else key - end + end result.merge(snake_key => snakecase_keys_private(value)) end when Array @@ -68,7 +68,7 @@ def camelcase_keys_private(params) when Symbol then key.to_s.camelcase.to_sym else key - end + end result.merge(snake_key => camelcase_keys_private(value)) end when Array diff --git a/lib/pact_broker/index/service.rb b/lib/pact_broker/index/service.rb index 84c64f9fd..2b829574e 100644 --- a/lib/pact_broker/index/service.rb +++ b/lib/pact_broker/index/service.rb @@ -30,6 +30,7 @@ def self.find_all_index_items find_index_items(page_number: 1, page_size: 100000000000) end + # rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength def self.find_index_items options = {} latest_verifications_for_cv_tags = latest_verifications_for_consumer_version_tags(options) latest_pp_ids = latest_pact_publication_ids @@ -53,7 +54,7 @@ def self.find_index_items options = {} is_overall_latest_for_integration = latest_pp_ids.include?(pact_publication.id) latest_verification = latest_verification_for_pseudo_branch(pact_publication, is_overall_latest_for_integration, latest_verifications_for_cv_tags, options[:tags]) - webhook = webhooks.find{ |webhook| webhook.is_for?(pact_publication.integration) } + webhook = webhooks.find{ |wh| wh.is_for?(pact_publication.integration) } PactBroker::Domain::IndexItem.create( pact_publication.consumer, @@ -71,9 +72,11 @@ def self.find_index_items options = {} Page.new(index_items, pagination_record_count) end + # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength # Worst. Code. Ever. # + # rubocop: disable Metrics/CyclomaticComplexity def self.latest_verification_for_pseudo_branch(pact_publication, is_overall_latest, latest_verifications_for_cv_tags, tags_option) if tags_option == true latest_verifications_for_cv_tags @@ -87,6 +90,7 @@ def self.latest_verification_for_pseudo_branch(pact_publication, is_overall_late pact_publication.integration.latest_verification end end + # rubocop: enable Metrics/CyclomaticComplexity def self.consumer_version_tags(pact_publication, tags_option) if tags_option == true @@ -98,7 +102,7 @@ def self.consumer_version_tags(pact_publication, tags_option) end end - def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, **ignored) + def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, **_ignored) latest_pp_ids = latest_pact_publication_ids pact_publications = head_pact_publications(consumer_name: consumer_name, provider_name: provider_name, tags: true) .eager(:consumer) @@ -157,7 +161,7 @@ def self.head_pact_publications(options = {}) latest.union(base.latest_by_consumer_tag) else latest - end + end query = PactBroker::Pacts::PactPublication.select_all_qualified.where(Sequel[:pact_publications][:id] => ids_query) .join_consumers(:consumers) diff --git a/lib/pact_broker/logging/default_formatter.rb b/lib/pact_broker/logging/default_formatter.rb index 734024001..b3cc01a6d 100644 --- a/lib/pact_broker/logging/default_formatter.rb +++ b/lib/pact_broker/logging/default_formatter.rb @@ -8,7 +8,7 @@ def initialize @formatter = ::Logger::Formatter.new end - def call(log, output) + def call(log, _output) self.log = log self.logger = logger @formatter.call(log.level.upcase, log.time, nil, [tags, named_tags, duration, message, payload, exception].compact.join(" ")) diff --git a/lib/pact_broker/matrix/aggregated_row.rb b/lib/pact_broker/matrix/aggregated_row.rb index ceef56912..a92fc18be 100644 --- a/lib/pact_broker/matrix/aggregated_row.rb +++ b/lib/pact_broker/matrix/aggregated_row.rb @@ -34,7 +34,7 @@ def latest_verification_for_pseudo_branch @latest_verification ||= begin verification = matrix_rows.collect do | row| row.verification || latest_verification_for_consumer_version_tag(row) - end.compact.sort_by(&:id).last + end.compact.sort_by(&:id).last if !verification && overall_latest? overall_latest_verification diff --git a/lib/pact_broker/matrix/every_row.rb b/lib/pact_broker/matrix/every_row.rb index b3b92bec0..2ceeefe96 100644 --- a/lib/pact_broker/matrix/every_row.rb +++ b/lib/pact_broker/matrix/every_row.rb @@ -27,7 +27,7 @@ class EveryRow < PactBroker::Matrix::QuickRow SELECT_ALL_COLUMN_ARGS = [:select_all_columns] + ALL_COLUMNS dataset_module do - select *SELECT_ALL_COLUMN_ARGS + select(*SELECT_ALL_COLUMN_ARGS) def join_verifications left_outer_join(:verifications, P_V_JOIN, { table_alias: :v } ) diff --git a/lib/pact_broker/matrix/integration.rb b/lib/pact_broker/matrix/integration.rb index 89357ed9d..b51d4d893 100644 --- a/lib/pact_broker/matrix/integration.rb +++ b/lib/pact_broker/matrix/integration.rb @@ -48,7 +48,7 @@ def == other def <=> other comparison = consumer_name <=> other.consumer_name return comparison if comparison != 0 - comparison =provider_name <=> other.provider_name + provider_name <=> other.provider_name end def to_hash @@ -84,10 +84,6 @@ def involves_consumer_with_name?(consumer_name) self.consumer_name == consumer_name end - def pacticipant_names - [consumer_name, provider_name] - end - def involves_pacticipant_with_name?(pacticipant_name) pacticipant_names.include?(pacticipant_name) end diff --git a/lib/pact_broker/matrix/parse_can_i_deploy_query.rb b/lib/pact_broker/matrix/parse_can_i_deploy_query.rb index 0252a5b72..a5898718c 100644 --- a/lib/pact_broker/matrix/parse_can_i_deploy_query.rb +++ b/lib/pact_broker/matrix/parse_can_i_deploy_query.rb @@ -4,6 +4,7 @@ module PactBroker module Matrix class ParseCanIDeployQuery + # rubocop: disable Metrics/CyclomaticComplexity def self.call params selector = PactBroker::Matrix::UnresolvedSelector.new options = { @@ -39,6 +40,7 @@ def self.call params return [selector], options end + # rubocop: enable Metrics/CyclomaticComplexity end end end diff --git a/lib/pact_broker/matrix/parse_query.rb b/lib/pact_broker/matrix/parse_query.rb index 553a505b5..8ebe39fa5 100644 --- a/lib/pact_broker/matrix/parse_query.rb +++ b/lib/pact_broker/matrix/parse_query.rb @@ -4,6 +4,8 @@ module PactBroker module Matrix class ParseQuery + # rubocop: disable Metrics/CyclomaticComplexity + # rubocop: disable Metrics/MethodLength def self.call query params = Rack::Utils.parse_nested_query(query) selectors = (params['q'] || []).collect do |i| @@ -64,6 +66,7 @@ def self.parse_selector(i) p.tag = i['tag'] if i['tag'] && i['tag'] != '' p end + # rubocop: enable Metrics/CyclomaticComplexity end end end diff --git a/lib/pact_broker/matrix/query_builder.rb b/lib/pact_broker/matrix/query_builder.rb index 92936de7e..f00fb28a3 100644 --- a/lib/pact_broker/matrix/query_builder.rb +++ b/lib/pact_broker/matrix/query_builder.rb @@ -64,16 +64,16 @@ def self.either_consumer_or_provider_was_specified_in_query(query_ids, qualifier # QueryIds is built from a single selector, so there is only one pacticipant_id or pacticipant_version_id def self.consumer_or_consumer_version_or_provider_or_provider_or_provider_version_match(query_ids, pacts_qualifier = :p, verifications_qualifier = :v) ors = if query_ids.pacticipant_version_id - [ - { Sequel[pacts_qualifier][:consumer_version_id] => query_ids.pacticipant_version_id }, - { Sequel[verifications_qualifier][:provider_version_id] => query_ids.pacticipant_version_id } - ] - else - [ - { Sequel[pacts_qualifier][:consumer_id] => query_ids.pacticipant_id }, - { Sequel[pacts_qualifier][:provider_id] => query_ids.pacticipant_id } - ] - end + [ + { Sequel[pacts_qualifier][:consumer_version_id] => query_ids.pacticipant_version_id }, + { Sequel[verifications_qualifier][:provider_version_id] => query_ids.pacticipant_version_id } + ] + else + [ + { Sequel[pacts_qualifier][:consumer_id] => query_ids.pacticipant_id }, + { Sequel[pacts_qualifier][:provider_id] => query_ids.pacticipant_id } + ] + end Sequel.|(*ors) end diff --git a/lib/pact_broker/matrix/query_results.rb b/lib/pact_broker/matrix/query_results.rb index f6c573d20..f513f91cb 100644 --- a/lib/pact_broker/matrix/query_results.rb +++ b/lib/pact_broker/matrix/query_results.rb @@ -3,6 +3,7 @@ module Matrix class QueryResults < Array attr_reader :considered_rows, :ignored_rows, :selectors, :options, :resolved_selectors, :resolved_ignore_selectors, :integrations + # rubocop: disable Metrics/ParameterLists def initialize considered_rows, ignored_rows, selectors, options, resolved_selectors, resolved_ignore_selectors, integrations super(considered_rows + ignored_rows) @considered_rows = considered_rows @@ -13,6 +14,7 @@ def initialize considered_rows, ignored_rows, selectors, options, resolved_selec @resolved_ignore_selectors = resolved_ignore_selectors @integrations = integrations end + # rubocop: enable Metrics/ParameterLists def rows to_a diff --git a/lib/pact_broker/matrix/quick_row.rb b/lib/pact_broker/matrix/quick_row.rb index d52ae7416..c4ff34255 100644 --- a/lib/pact_broker/matrix/quick_row.rb +++ b/lib/pact_broker/matrix/quick_row.rb @@ -20,6 +20,7 @@ module PactBroker module Matrix + # rubocop: disable Metrics/ClassLength class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consumer_versions, :p)) # Tables @@ -67,24 +68,24 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum dataset_module do include PactBroker::Repositories::Helpers - select *SELECT_ALL_COLUMN_ARGS - select *SELECT_PACTICIPANT_IDS_ARGS + select(*SELECT_ALL_COLUMN_ARGS) + select(*SELECT_PACTICIPANT_IDS_ARGS) def distinct_integrations selectors, infer_integrations query = if selectors.size == 1 - pacticipant_ids_matching_one_selector_optimised(selectors) - else - query = select_pacticipant_ids.distinct - if infer_integrations - query.matching_any_of_multiple_selectors(selectors) - else - if selectors.all?(&:only_pacticipant_name_specified?) - query.matching_multiple_selectors_without_joining_verifications(selectors) - else - query.matching_multiple_selectors_joining_verifications(selectors) - end - end - end + pacticipant_ids_matching_one_selector_optimised(selectors) + else + query = select_pacticipant_ids.distinct + if infer_integrations + query.matching_any_of_multiple_selectors(selectors) + else + if selectors.all?(&:only_pacticipant_name_specified?) + query.matching_multiple_selectors_without_joining_verifications(selectors) + else + query.matching_multiple_selectors_joining_verifications(selectors) + end + end + end query.from_self(alias: :pacticipant_ids) .select( @@ -261,10 +262,6 @@ def inner_join_verifications end end # end dataset_module - def success - verification&.success - end - def pact_version_sha pact_version.sha end @@ -393,5 +390,6 @@ def return_or_raise_if_not_set(key) end end end + # rubocop: enable Metrics/ClassLength end end diff --git a/lib/pact_broker/matrix/repository.rb b/lib/pact_broker/matrix/repository.rb index d6aaa0a96..5d6546628 100644 --- a/lib/pact_broker/matrix/repository.rb +++ b/lib/pact_broker/matrix/repository.rb @@ -29,6 +29,7 @@ class Repository GROUP_BY_PROVIDER = [:consumer_name, :consumer_version_number, :provider_name] GROUP_BY_PACT = [:consumer_name, :provider_name] + # rubocop: disable Metrics/CyclomaticComplexity def find_ids_for_pacticipant_names params criteria = {} @@ -52,6 +53,7 @@ def find_ids_for_pacticipant_names params criteria[:tag_name] = params[:tag_name] if params[:tag_name].is_a?(String) # Could be a sym from resource parameters in api.rb criteria end + # rubocop: enable Metrics/CyclomaticComplexity # Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number def find specified_selectors, options = {} @@ -116,22 +118,24 @@ def is_a_row_for_this_integration_required?(specified_pacticipant_names, consume specified_pacticipant_names.include?(consumer_name) end + # rubocop: disable Metrics/CyclomaticComplexity # It would be nicer to do this in the SQL, but it requires time that I don't have at the moment def apply_latestby options, lines return lines unless options[:latestby] group_by_columns = case options[:latestby] - when 'cvpv' then GROUP_BY_PROVIDER_VERSION_NUMBER - when 'cvp' then GROUP_BY_PROVIDER - when 'cp' then GROUP_BY_PACT - end + when 'cvpv' then GROUP_BY_PROVIDER_VERSION_NUMBER + when 'cvp' then GROUP_BY_PROVIDER + when 'cp' then GROUP_BY_PACT + end # The group with the nil provider_version_numbers will be the results of the left outer join # that don't have verifications, so we need to include them all. lines.group_by{|line| group_by_columns.collect{|key| line.send(key) }} .values - .collect{ | lines | lines.first.provider_version_number.nil? ? lines : lines.sort_by(&:provider_version_order).last } + .collect{ | line | line.first.provider_version_number.nil? ? line : line.sort_by(&:provider_version_order).last } .flatten end + # rubocop: enable Metrics/CyclomaticComplexity def query_matrix selectors, options query = base_model(options).select_all_columns @@ -230,12 +234,14 @@ def selector_for_non_existing_version(pacticipant, unresolved_selector, selector ResolvedSelector.for_pacticipant_and_non_existing_version(pacticipant, unresolved_selector, selector_type, ignore) end + # rubocop: disable Metrics/ParameterLists def selector_for_found_version(pacticipant, version, unresolved_selector, selector_type, one_of_many, resolved_ignore_selectors) ignore = resolved_ignore_selectors.any? do | s | s.pacticipant_id == pacticipant.id && (s.only_pacticipant_name_specified? || s.pacticipant_version_id == version.id) end ResolvedSelector.for_pacticipant_and_version(pacticipant, version, unresolved_selector, selector_type, ignore, one_of_many) end + # rubocop: enable Metrics/ParameterLists def selector_for_all_versions_of_a_pacticipant(pacticipant, selector_type, resolved_ignore_selectors) # Doesn't make sense to ignore this, as you can't have a can-i-deploy query diff --git a/lib/pact_broker/matrix/resolved_selector.rb b/lib/pact_broker/matrix/resolved_selector.rb index e4cfc8762..feb42e3da 100644 --- a/lib/pact_broker/matrix/resolved_selector.rb +++ b/lib/pact_broker/matrix/resolved_selector.rb @@ -34,6 +34,7 @@ def self.for_non_existing_pacticipant(original_selector, type, ignore) ) end + # rubocop: disable Metrics/ParameterLists def self.for_pacticipant_and_version(pacticipant, version, original_selector, type, ignore, one_of_many = false) ResolvedSelector.new( pacticipant_id: pacticipant.id, @@ -49,6 +50,7 @@ def self.for_pacticipant_and_version(pacticipant, version, original_selector, ty one_of_many: one_of_many ) end + # rubocop: enable Metrics/ParameterLists def self.for_pacticipant_and_non_existing_version(pacticipant, original_selector, type, ignore) ResolvedSelector.new( @@ -164,6 +166,7 @@ def consider? !ignore? end + # rubocop: disable Metrics/CyclomaticComplexity def description if latest_tagged? && pacticipant_version_number "the latest version of #{pacticipant_name} with tag #{tag} (#{pacticipant_version_number})" @@ -196,6 +199,7 @@ def description "any version of #{pacticipant_name}" end end + # rubocop: enable Metrics/CyclomaticComplexity end end end diff --git a/lib/pact_broker/matrix/service.rb b/lib/pact_broker/matrix/service.rb index 584b53f86..b125cece9 100644 --- a/lib/pact_broker/matrix/service.rb +++ b/lib/pact_broker/matrix/service.rb @@ -48,6 +48,7 @@ def find_for_consumer_and_provider_with_tags params end end + # rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength def validate_selectors selectors, options = {} error_messages = [] @@ -96,6 +97,7 @@ def validate_selectors selectors, options = {} error_messages end + # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength end end end diff --git a/lib/pact_broker/metrics/service.rb b/lib/pact_broker/metrics/service.rb index ba7a9ac81..9cba46dc5 100644 --- a/lib/pact_broker/metrics/service.rb +++ b/lib/pact_broker/metrics/service.rb @@ -19,6 +19,7 @@ module Service extend self + # rubocop: disable Metrics/MethodLength def metrics { pacticipants: { @@ -71,6 +72,7 @@ def metrics } } end + # rubocop: enable Metrics/MethodLength def pact_revision_counts query = "select revision_count as number_of_revisions, count(consumer_version_id) as consumer_version_count @@ -80,7 +82,6 @@ def pact_revision_counts PactBroker::Pacts::PactPublication.db[query].all.each_with_object({}) { |row, hash| hash[row[:number_of_revisions]] = row[:consumer_version_count] } end -# def verification_distribution query = "select verification_count as number_of_verifications, count(*) as pact_version_count from (select pact_version_id, count(*) as verification_count from verifications group by pact_version_id) foo @@ -94,7 +95,7 @@ def matrix_count PactBroker::Matrix::Row.db.with_statement_timeout(PactBroker.configuration.metrics_sql_statement_timeout) do PactBroker::Matrix::Row.count end - rescue Sequel::DatabaseError => e + rescue Sequel::DatabaseError => _ex -1 end end diff --git a/lib/pact_broker/pacticipants/repository.rb b/lib/pact_broker/pacticipants/repository.rb index dd6fb1760..c80b05a58 100644 --- a/lib/pact_broker/pacticipants/repository.rb +++ b/lib/pact_broker/pacticipants/repository.rb @@ -44,11 +44,8 @@ def find_all_pacticipant_versions_in_reverse_order name, pagination_options = ni end def find_by_name_or_create name - if pacticipant = find_by_name(name) - pacticipant - else - create(name: name) - end + pacticipant = find_by_name(name) + pacticipant ? pacticipant : create(name: name) end # Need to be able to handle two calls that make the pacticipant at the same time. @@ -70,7 +67,7 @@ def update(pacticipant_name, pacticipant) pacticipant.save end - def replace(pacticipant_name, open_struct_pacticipant) + def replace(_pacticipant_name, open_struct_pacticipant) PactBroker::Domain::Pacticipant.new( display_name: open_struct_pacticipant.display_name, repository_url: open_struct_pacticipant.repository_url, diff --git a/lib/pact_broker/pacts/content.rb b/lib/pact_broker/pacts/content.rb index cf794f4e8..73988dc8c 100644 --- a/lib/pact_broker/pacts/content.rb +++ b/lib/pact_broker/pacts/content.rb @@ -38,6 +38,7 @@ def interactions_missing_test_results end end + # rubocop: disable Metrics/CyclomaticComplexity def with_test_results(test_results) # new format if test_results.is_a?(Array) @@ -60,6 +61,7 @@ def with_test_results(test_results) end Content.from_hash(new_pact_hash) end + # rubocop: enable Metrics/CyclomaticComplexity def with_ids(overwrite_existing_id = true) new_pact_hash = pact_hash.dup diff --git a/lib/pact_broker/pacts/eager_loaders.rb b/lib/pact_broker/pacts/eager_loaders.rb index dca907cb9..312953c95 100644 --- a/lib/pact_broker/pacts/eager_loaders.rb +++ b/lib/pact_broker/pacts/eager_loaders.rb @@ -22,7 +22,7 @@ def self.populate_associations(grouped_pact_publications) end end - def self.populate_associations_for_consumer_and_provider(key, pact_publications) + def self.populate_associations_for_consumer_and_provider(_key, pact_publications) head_pact_publications_by_tag = hash_of_head_pact_publications( pact_publications.first.class, pact_publications.first.consumer, diff --git a/lib/pact_broker/pacts/generate_sha.rb b/lib/pact_broker/pacts/generate_sha.rb index bb47f113f..89154392e 100644 --- a/lib/pact_broker/pacts/generate_sha.rb +++ b/lib/pact_broker/pacts/generate_sha.rb @@ -7,12 +7,12 @@ module PactBroker module Pacts class GenerateSha - def self.call json_content, options = {} + def self.call json_content, _options = {} content_for_sha = if PactBroker.configuration.base_equality_only_on_content_that_affects_verification_results - extract_verifiable_content_for_sha(json_content) - else - json_content - end + extract_verifiable_content_for_sha(json_content) + else + json_content + end Digest::SHA1.hexdigest(content_for_sha) end diff --git a/lib/pact_broker/pacts/lazy_loaders.rb b/lib/pact_broker/pacts/lazy_loaders.rb index 3401eab6c..f8a950d65 100644 --- a/lib/pact_broker/pacts/lazy_loaders.rb +++ b/lib/pact_broker/pacts/lazy_loaders.rb @@ -8,7 +8,7 @@ module LazyLoaders .for_provider(provider) .latest_for_consumer_tag(consumer_version_tag_names) .from_self.order_by(:tag_name) - } + } end end end diff --git a/lib/pact_broker/pacts/merger.rb b/lib/pact_broker/pacts/merger.rb index c18fe9338..f21d69198 100644 --- a/lib/pact_broker/pacts/merger.rb +++ b/lib/pact_broker/pacts/merger.rb @@ -56,7 +56,7 @@ def normalized_provider_states(interaction) end def same_request_properties? original, additional - attributes_match = %w(method path query body headers).all? do |attribute| + %w(method path query body headers).all? do |attribute| original[attribute] == additional[attribute] end end diff --git a/lib/pact_broker/pacts/pact_publication.rb b/lib/pact_broker/pacts/pact_publication.rb index 88fd57cf0..8bd9b0a7e 100644 --- a/lib/pact_broker/pacts/pact_publication.rb +++ b/lib/pact_broker/pacts/pact_publication.rb @@ -74,9 +74,6 @@ def latest_verification def latest_for_branch? return nil unless consumer_version.branch self_order = self.consumer_version.order - versions_join = { - Sequel[:pact_publications][:consumer_version_id] => Sequel[:cv][:id] - } PactPublication.where(consumer_id: consumer_id, provider_id: provider_id) .join_consumer_versions(:cv, { Sequel[:cv][:branch] => consumer_version.branch} ) do Sequel[:cv][:order] > self_order diff --git a/lib/pact_broker/pacts/pacts_for_verification_repository.rb b/lib/pact_broker/pacts/pacts_for_verification_repository.rb index 46a8a8c83..8fcd1811a 100644 --- a/lib/pact_broker/pacts/pacts_for_verification_repository.rb +++ b/lib/pact_broker/pacts/pacts_for_verification_repository.rb @@ -97,26 +97,27 @@ def find_pacts_for_fallback_tags(selected_pacts, provider_name, consumer_version end end + # rubocop: disable Metrics/CyclomaticComplexity def find_pacts_by_selector(provider_name, consumer_version_selectors) provider = pacticipant_repository.find_by_name(provider_name) selectors = if consumer_version_selectors.empty? - Selectors.create_for_overall_latest - else - consumer_version_selectors.select(&:latest_for_tag?) + - consumer_version_selectors.select(&:latest_for_branch?) + - consumer_version_selectors.select(&:overall_latest?) + - consumer_version_selectors.select(&:currently_deployed?) - end + Selectors.create_for_overall_latest + else + consumer_version_selectors.select(&:latest_for_tag?) + + consumer_version_selectors.select(&:latest_for_branch?) + + consumer_version_selectors.select(&:overall_latest?) + + consumer_version_selectors.select(&:currently_deployed?) + end selectors.flat_map do | selector | query = scope_for(PactPublication).for_provider_and_consumer_version_selector(provider, selector) query.all.collect do | pact_publication | resolved_selector = if selector.currently_deployed? - selector.resolve_for_environment(pact_publication.consumer_version, pact_publication.values.fetch(:environment_name)) - else - selector.resolve(pact_publication.consumer_version) - end + selector.resolve_for_environment(pact_publication.consumer_version, pact_publication.values.fetch(:environment_name)) + else + selector.resolve(pact_publication.consumer_version) + end SelectedPact.new( pact_publication.to_domain, Selectors.new(resolved_selector) @@ -124,6 +125,7 @@ def find_pacts_by_selector(provider_name, consumer_version_selectors) end end end + # rubocop: enable Metrics/CyclomaticComplexity def find_pacts_for_which_the_latest_version_for_the_fallback_tag_is_required(provider_name, selectors) selectors.collect do | selector | @@ -187,12 +189,12 @@ def provider_tag_objects_for(provider, provider_tags_names) end # TODO ? find the WIP pacts by consumer branch - def find_wip_pact_versions_for_provider_by_provider_tags(provider, provider_tags_names, provider_tags, wip_start_date, pact_publication_scope) + def find_wip_pact_versions_for_provider_by_provider_tags(provider, provider_tags_names, _provider_tags, wip_start_date, pact_publication_scope) potential_wip_pacts_by_consumer_tag_query = PactPublication.for_provider(provider).created_after(wip_start_date).send(pact_publication_scope) potential_wip_pacts_by_consumer_tag = potential_wip_pacts_by_consumer_tag_query.all - tag_to_pact_publications = provider_tags_names.each_with_object({}) do | provider_tag_name, tag_to_pact_publications | - tag_to_pact_publications[provider_tag_name] = remove_non_wip_for_tag( + tag_to_pact_publications = provider_tags_names.each_with_object({}) do | provider_tag_name, tag_to_pact_publication | + tag_to_pact_publication[provider_tag_name] = remove_non_wip_for_tag( potential_wip_pacts_by_consumer_tag, potential_wip_pacts_by_consumer_tag_query, provider, diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index b3b24d273..3ae6c8b5e 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -23,6 +23,7 @@ module PactBroker module Pacts + # rubocop: disable Metrics/ClassLength class Repository include PactBroker::Logging include PactBroker::Repositories @@ -218,6 +219,7 @@ def search_for_latest_pact(consumer_name, provider_name, tag = nil) query.latest.all.collect(&:to_domain_with_content)[0] end + # rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength def find_pact consumer_name, consumer_version, provider_name, pact_version_sha = nil pact_publication_by_consumer_version = scope_for(LatestPactPublicationsByConsumerVersion) .consumer(consumer_name) @@ -232,7 +234,7 @@ def find_pact consumer_name, consumer_version, provider_name, pact_version_sha = .reverse_order(:consumer_version_order, :revision_number) .limit(1) - query = if consumer_version && !pact_version_sha + if consumer_version && !pact_version_sha pact_publication_by_consumer_version .eager(:tags) .collect(&:to_domain_with_content).first @@ -257,6 +259,7 @@ def find_pact consumer_name, consumer_version, provider_name, pact_version_sha = .collect(&:to_domain_with_content).first end end + # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength def find_all_revisions consumer_name, consumer_version, provider_name scope_for(AllPactPublications) @@ -370,5 +373,6 @@ def to_datetime string_or_datetime end end end + # rubocop: enable Metrics/ClassLength end end diff --git a/lib/pact_broker/pacts/selector.rb b/lib/pact_broker/pacts/selector.rb index fc8380755..c152f3281 100644 --- a/lib/pact_broker/pacts/selector.rb +++ b/lib/pact_broker/pacts/selector.rb @@ -205,6 +205,7 @@ def == other other.class == self.class && super end + # rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength def <=> other if overall_latest? || other.overall_latest? if overall_latest? == other.overall_latest? @@ -240,6 +241,7 @@ def <=> other tag <=> other.tag end end + # rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength private diff --git a/lib/pact_broker/pacts/service.rb b/lib/pact_broker/pacts/service.rb index 7533ecdb7..6c7190e65 100644 --- a/lib/pact_broker/pacts/service.rb +++ b/lib/pact_broker/pacts/service.rb @@ -123,20 +123,20 @@ def find_for_verification(provider_name, provider_version_branch, provider_versi end verifiable_wip_pacts = if options[:include_wip_pacts_since] - exclude_specified_pacts( - pact_repository.find_wip_pact_versions_for_provider(provider_name, provider_version_branch, provider_version_tags, options), - verifiable_pacts_specified_in_request) - else - [] - end + exclude_specified_pacts( + pact_repository.find_wip_pact_versions_for_provider(provider_name, provider_version_branch, provider_version_tags, options), + verifiable_pacts_specified_in_request) + else + [] + end verifiable_pacts_specified_in_request + verifiable_wip_pacts end def exclude_specified_pacts(wip_pacts, specified_pacts) wip_pacts.reject do | wip_pact | - specified_pacts.any? do | specified_pacts | - wip_pact.pact_version_sha == specified_pacts.pact_version_sha + specified_pacts.any? do | specified_pact | + wip_pact.pact_version_sha == specified_pact.pact_version_sha end end end @@ -145,7 +145,7 @@ def exclude_specified_pacts(wip_pacts, specified_pacts) # Overwriting an existing pact with the same consumer/provider/consumer version number def update_pact params, existing_pact - logger.info "Updating existing pact publication with params #{params.reject{ |k, v| k == :json_content}}" + logger.info "Updating existing pact publication with params #{params.reject{ |k, _v| k == :json_content}}" logger.debug "Content #{params[:json_content]}" pact_version_sha = generate_sha(params[:json_content]) json_content = add_interaction_ids(params[:json_content]) @@ -170,7 +170,7 @@ def update_pact params, existing_pact # When no publication for the given consumer/provider/consumer version number exists def create_pact params, version, provider - logger.info "Creating new pact publication with params #{params.reject{ |k, v| k == :json_content}}" + logger.info "Creating new pact publication with params #{params.reject{ |k, _v| k == :json_content}}" logger.debug "Content #{params[:json_content]}" pact_version_sha = generate_sha(params[:json_content]) json_content = add_interaction_ids(params[:json_content]) diff --git a/lib/pact_broker/pacts/squash_pacts_for_verification.rb b/lib/pact_broker/pacts/squash_pacts_for_verification.rb index 43b617297..8dc9c8f84 100644 --- a/lib/pact_broker/pacts/squash_pacts_for_verification.rb +++ b/lib/pact_broker/pacts/squash_pacts_for_verification.rb @@ -10,7 +10,6 @@ def self.call(provider_version_tags, selected_pact, include_pending_status = fal if include_pending_status pending_provider_tags = [] - non_pending_provider_tags = [] pending = nil if provider_version_tags.any? pending_provider_tags = domain_pact.select_pending_provider_version_tags(provider_version_tags) diff --git a/lib/pact_broker/pacts/verifiable_pact.rb b/lib/pact_broker/pacts/verifiable_pact.rb index 92e8f2a6b..368e0a2bc 100644 --- a/lib/pact_broker/pacts/verifiable_pact.rb +++ b/lib/pact_broker/pacts/verifiable_pact.rb @@ -6,6 +6,7 @@ module Pacts class VerifiablePact < SimpleDelegator attr_reader :selectors, :pending, :pending_provider_tags, :non_pending_provider_tags, :provider_branch, :wip + # rubocop: disable Metrics/ParameterLists # TODO refactor this constructor def initialize(pact, selectors, pending = nil, pending_provider_tags = [], non_pending_provider_tags = [], provider_branch = nil, wip = false) super(pact) @@ -16,6 +17,7 @@ def initialize(pact, selectors, pending = nil, pending_provider_tags = [], non_p @provider_branch = provider_branch @wip = wip end + # rubocop: enable Metrics/ParameterLists def self.create_for_wip_for_provider_branch(pact, selectors, provider_branch) new(pact, selectors, true, [], [], provider_branch, true) @@ -29,7 +31,7 @@ def self.deduplicate(verifiable_pacts) verifiable_pacts .group_by { | verifiable_pact | verifiable_pact.pact_version_sha } .values - .collect { | verifiable_pacts | verifiable_pacts.reduce(&:+) } + .collect { | verifiable_pact | verifiable_pact.reduce(&:+) } end def pending? diff --git a/lib/pact_broker/pacts/verifiable_pact_messages.rb b/lib/pact_broker/pacts/verifiable_pact_messages.rb index cce61bc4f..961562ace 100644 --- a/lib/pact_broker/pacts/verifiable_pact_messages.rb +++ b/lib/pact_broker/pacts/verifiable_pact_messages.rb @@ -19,10 +19,10 @@ def initialize(verifiable_pact, pact_version_url) def pact_description position_descs = if head_consumer_tags.empty? && branches.empty? - ["latest"] - else - head_consumer_tags.collect { |tag| "latest with tag #{tag}" } + branches.collect{ |branch| "latest from branch #{branch}" } - end + ["latest"] + else + head_consumer_tags.collect { |tag| "latest with tag #{tag}" } + branches.collect{ |branch| "latest from branch #{branch}" } + end "Pact between #{consumer_name} and #{provider_name}, consumer version #{consumer_version_number}, #{position_descs.join(", ")}" end @@ -78,7 +78,7 @@ def pact_version_short_description attr_reader :verifiable_pact, :pact_version_url def join(list, last_joiner = " and ") - join_unquoted(list.collect { | word | "'#{word}'" }, last_joiner = " and ") + join_unquoted(list.collect { | word | "'#{word}'" }, last_joiner) end def join_unquoted(list, last_joiner = " and ") @@ -175,40 +175,42 @@ def selectors_descriptions(selectors) end end + # rubocop: disable Metrics/CyclomaticComplexity def selector_description selector description = if selector.overall_latest? - consumer_label = selector.consumer ? selector.consumer : 'a consumer' - "latest version of #{consumer_label} that has a pact with #{provider_name}" - elsif selector.latest_for_tag? - version_label = selector.consumer ? "version of #{selector.consumer}" : "version" - if selector.fallback_tag? - "latest #{version_label} tagged '#{selector.fallback_tag}' (fallback tag used as no pact was found with tag '#{selector.tag}')" - else - "latest #{version_label} tagged '#{selector.tag}'" - end - elsif selector.latest_for_branch? - version_label = selector.consumer ? "version of #{selector.consumer}" : "version" - if selector.fallback_branch? - "latest #{version_label} from branch '#{selector.fallback_branch}' (fallback branch used as no pact was found from branch '#{selector.branch}')" - else - "latest #{version_label} from branch '#{selector.branch}'" - end - elsif selector.all_for_tag_and_consumer? - "all #{selector.consumer} versions tagged '#{selector.tag}'" - elsif selector.all_for_tag? - "all consumer versions tagged '#{selector.tag}'" - elsif selector.currently_deployed? - "version(s) currently deployed to #{selector.environment}" - else - selector.to_json - end + consumer_label = selector.consumer ? selector.consumer : 'a consumer' + "latest version of #{consumer_label} that has a pact with #{provider_name}" + elsif selector.latest_for_tag? + version_label = selector.consumer ? "version of #{selector.consumer}" : "version" + if selector.fallback_tag? + "latest #{version_label} tagged '#{selector.fallback_tag}' (fallback tag used as no pact was found with tag '#{selector.tag}')" + else + "latest #{version_label} tagged '#{selector.tag}'" + end + elsif selector.latest_for_branch? + version_label = selector.consumer ? "version of #{selector.consumer}" : "version" + if selector.fallback_branch? + "latest #{version_label} from branch '#{selector.fallback_branch}' (fallback branch used as no pact was found from branch '#{selector.branch}')" + else + "latest #{version_label} from branch '#{selector.branch}'" + end + elsif selector.all_for_tag_and_consumer? + "all #{selector.consumer} versions tagged '#{selector.tag}'" + elsif selector.all_for_tag? + "all consumer versions tagged '#{selector.tag}'" + elsif selector.currently_deployed? + "version(s) currently deployed to #{selector.environment}" + else + selector.to_json + end "#{description} (#{selector.consumer_version.number})" end + # rubocop: enable Metrics/CyclomaticComplexity def currently_deployed_selectors_description(selectors) - selectors.group_by(&:consumer).flat_map do | consumer_name, selectors | + selectors.group_by(&:consumer).flat_map do | consumer_name, consumer_selectors | display_name = consumer_name ? "version(s) of #{consumer_name}" : "consumer version(s)" - environments_and_versions = selectors.collect{ | selector | "#{selector.environment} (#{selector.consumer_version.number})" } + environments_and_versions = consumer_selectors.collect{ | selector | "#{selector.environment} (#{selector.consumer_version.number})" } "#{display_name} currently deployed to #{join_unquoted(environments_and_versions)}" end end @@ -217,6 +219,7 @@ def short_selector_descriptions selectors.collect{ | selector | short_selector_description(selector) }.join(", ") end + # rubocop: disable Metrics/CyclomaticComplexity # this is used by Pact Go to create the test method name, so needs to be concise def short_selector_description selector if selector.overall_latest? @@ -243,6 +246,7 @@ def short_selector_description selector selector.to_json end end + # rubocop: enable Metrics/CyclomaticComplexity def selectors verifiable_pact.selectors diff --git a/lib/pact_broker/services.rb b/lib/pact_broker/services.rb index 3795f4f20..5d70e6284 100644 --- a/lib/pact_broker/services.rb +++ b/lib/pact_broker/services.rb @@ -89,6 +89,7 @@ def contract_service get(:contract_service) end + # rubocop: disable Metrics/MethodLength def register_default_services register_service(:index_service) do require 'pact_broker/index/service' @@ -185,6 +186,7 @@ def register_default_services PactBroker::Contracts::Service end end + # rubocop: enable Metrics/MethodLength end end diff --git a/lib/pact_broker/tags/eager_loaders.rb b/lib/pact_broker/tags/eager_loaders.rb index 5a02954cd..99015a091 100644 --- a/lib/pact_broker/tags/eager_loaders.rb +++ b/lib/pact_broker/tags/eager_loaders.rb @@ -12,8 +12,8 @@ def self.initialize_association(tags) end def self.populate_associations(tags) - group_by_pacticipant_id(tags).each do | pacticipant_id, tags | - populate_associations_by_pacticipant(pacticipant_id, tags) + group_by_pacticipant_id(tags).each do | pacticipant_id, participant_tags | + populate_associations_by_pacticipant(pacticipant_id, participant_tags) end end diff --git a/lib/pact_broker/tasks/clean_task.rb b/lib/pact_broker/tasks/clean_task.rb index 02148b71d..04efdcdb4 100644 --- a/lib/pact_broker/tasks/clean_task.rb +++ b/lib/pact_broker/tasks/clean_task.rb @@ -13,7 +13,7 @@ def initialize &block @version_deletion_limit = 1000 @dry_run = false @keep_version_selectors = PactBroker::DB::CleanIncremental::DEFAULT_KEEP_SELECTORS - rake_task &block + rake_task(&block) end def keep_version_selectors=(keep_version_selectors) @@ -27,7 +27,7 @@ def rake_task &block namespace :pact_broker do namespace :db do desc "Clean unnecessary pacts and verifications from database" - task :clean do | t, args | + task :clean do | _t, _args | instance_eval(&block) @@ -57,13 +57,13 @@ def rake_task &block elapsed_seconds = (end_time - start_time).to_i output "Results (#{elapsed_seconds} seconds)", results end - - def output string, payload = {} - logger ? logger.info(string, payload: payload) : puts("#{string} #{payload.to_json}") - end end end end + + def output string, payload = {} + logger ? logger.info(string, payload: payload) : puts("#{string} #{payload.to_json}") + end end end end diff --git a/lib/pact_broker/tasks/data_migration_task.rb b/lib/pact_broker/tasks/data_migration_task.rb index ac4a2a378..1942423e8 100644 --- a/lib/pact_broker/tasks/data_migration_task.rb +++ b/lib/pact_broker/tasks/data_migration_task.rb @@ -18,14 +18,14 @@ class DataMigrationTask < ::Rake::TaskLib attr_accessor :database_connection def initialize &block - rake_task &block + rake_task(&block) end def rake_task &block namespace :pact_broker do namespace :db do desc "Run data migrations for pact broker database" - task :migrate_data do | t, args | + task :migrate_data do | _t, _args | require 'pact_broker/db' instance_eval(&block) PactBroker::DB.run_data_migrations database_connection diff --git a/lib/pact_broker/tasks/delete_overwritten_data_task.rb b/lib/pact_broker/tasks/delete_overwritten_data_task.rb index b8f1554fb..8b041dd3c 100644 --- a/lib/pact_broker/tasks/delete_overwritten_data_task.rb +++ b/lib/pact_broker/tasks/delete_overwritten_data_task.rb @@ -9,14 +9,14 @@ class DeleteOverwrittenDataTask < ::Rake::TaskLib def initialize &block @max_age = 7 - rake_task &block + rake_task(&block) end def rake_task &block namespace :pact_broker do namespace :db do desc "Delete overwritten pacts and verifications from database" - task :delete_overwritten_data do | t, args | + task :delete_overwritten_data do | _t, _args | require 'pact_broker/db/delete_overwritten_data' require 'yaml' @@ -41,13 +41,13 @@ def rake_task &block elapsed_seconds = (end_time - start_time).to_i output "Results (#{elapsed_seconds} seconds)", results end - - def output string, payload = {} - logger ? logger.info(string, payload: payload) : puts("#{string} #{payload.to_json}") - end end end end + + def output string, payload = {} + logger ? logger.info(string, payload: payload) : puts("#{string} #{payload.to_json}") + end end end end diff --git a/lib/pact_broker/tasks/migration_task.rb b/lib/pact_broker/tasks/migration_task.rb index e49c36cc9..c0beafe59 100644 --- a/lib/pact_broker/tasks/migration_task.rb +++ b/lib/pact_broker/tasks/migration_task.rb @@ -20,14 +20,14 @@ class MigrationTask < ::Rake::TaskLib def initialize &block @options = {} - rake_task &block + rake_task(&block) end def rake_task &block namespace :pact_broker do namespace :db do desc "Run sequel migrations for pact broker database" - task :migrate, [:target] do | t, args | + task :migrate, [:target] do | _t, args | require 'pact_broker/db/migrate' require 'pact_broker/db/version' diff --git a/lib/pact_broker/tasks/version_task.rb b/lib/pact_broker/tasks/version_task.rb index 5f6904c3e..6d4212c83 100644 --- a/lib/pact_broker/tasks/version_task.rb +++ b/lib/pact_broker/tasks/version_task.rb @@ -18,7 +18,7 @@ class VersionTask < ::Rake::TaskLib attr_accessor :database_connection def initialize &block - rake_task &block + rake_task(&block) end def rake_task &block diff --git a/lib/pact_broker/test/http_test_data_builder.rb b/lib/pact_broker/test/http_test_data_builder.rb index bcf3f83c1..57b37af19 100644 --- a/lib/pact_broker/test/http_test_data_builder.rb +++ b/lib/pact_broker/test/http_test_data_builder.rb @@ -20,7 +20,7 @@ def initialize(pact_broker_base_url, auth = {}) end end faraday.headers['Authorization'] = "Bearer #{auth[:token]}" if auth[:token] - faraday.adapter Faraday.default_adapter + faraday.adapter Faraday.default_adapter end end @@ -41,8 +41,8 @@ def comment string end def create_tagged_pacticipant_version(pacticipant:, version:, tag:) - [*tag].each do | tag | - create_tag(pacticipant: pacticipant, version: version, tag: tag) + [*tag].each do | t | + create_tag(pacticipant: pacticipant, version: version, tag: t) end self end @@ -98,8 +98,8 @@ def publish_pact(consumer: last_consumer_name, consumer_version:, provider: last create_version(pacticipant: consumer, version: consumer_version, branch: branch) if branch - [*tag].each do | tag | - create_tag(pacticipant: consumer, version: consumer_version, tag: tag) + [*tag].each do | t | + create_tag(pacticipant: consumer, version: consumer_version, tag: t) end puts "" if [*tag].any? @@ -189,7 +189,7 @@ def create_global_webhook_for_contract_changed(uuid: nil, url: "https://postman- } } path = "webhooks/#{uuid}" - response = client.put(path, request_body.to_json).tap { |response| check_for_error(response) } + client.put(path, request_body.to_json).tap { |response| check_for_error(response) } separate self end @@ -219,7 +219,7 @@ def create_global_webhook_for_verification_published(uuid: nil, url: "https://po } } path = "webhooks/#{uuid}" - response = client.put(path, request_body.to_json).tap { |response| check_for_error(response) } + client.put(path, request_body.to_json).tap { |response| check_for_error(response) } separate self end @@ -227,7 +227,7 @@ def create_global_webhook_for_verification_published(uuid: nil, url: "https://po def delete_webhook(uuid:) puts "Deleting webhook with uuid #{uuid}" path = "webhooks/#{uuid}" - response = client.delete(path).tap { |response| check_for_error(response) } + client.delete(path).tap { |response| check_for_error(response) } separate self end @@ -306,7 +306,7 @@ def publish_verification_results(url_of_pact_to_verify, provider, provider_versi } puts "Publishing verification" puts results.to_yaml - response = client.post(verification_results_url, results.to_json).tap { |response| check_for_error(response) } + client.post(verification_results_url, results.to_json).tap { |response| check_for_error(response) } end def encode string @@ -321,4 +321,4 @@ def check_for_error(response) end end end -end \ No newline at end of file +end diff --git a/lib/pact_broker/test/test_data_builder.rb b/lib/pact_broker/test/test_data_builder.rb index 0425f062c..ba062dd1e 100644 --- a/lib/pact_broker/test/test_data_builder.rb +++ b/lib/pact_broker/test/test_data_builder.rb @@ -55,11 +55,11 @@ class TestDataBuilder attr_reader :deployed_version attr_reader :released_version - def initialize(params = {}) + def initialize(_params = {}) @now = DateTime.now end - def comment *args + def comment *_args self end @@ -283,6 +283,7 @@ def create_pact_version_without_publication(json_content = nil ) self end + # rubocop: disable Metrics/CyclomaticComplexity def create_webhook parameters = {} params = parameters.dup consumer = params.key?(:consumer) ? params.delete(:consumer) : @consumer @@ -290,16 +291,17 @@ def create_webhook parameters = {} uuid = params[:uuid] || PactBroker::Webhooks::Service.next_uuid enabled = params.key?(:enabled) ? params.delete(:enabled) : true event_params = if params[:event_names] - params[:event_names].collect{ |event_name| {name: event_name} } - else - params[:events] || [{ name: PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME }] - end + params[:event_names].collect{ |event_name| {name: event_name} } + else + params[:events] || [{ name: PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME }] + end events = event_params.collect{ |e| PactBroker::Webhooks::WebhookEvent.new(e) } template_params = { method: 'POST', url: 'http://example.org', headers: {'Content-Type' => 'application/json'}, username: params[:username], password: params[:password]} request = PactBroker::Webhooks::WebhookRequestTemplate.new(template_params.merge(params)) @webhook = PactBroker::Webhooks::Repository.new.create uuid, PactBroker::Domain::Webhook.new(request: request, events: events, description: params[:description], enabled: enabled), consumer, provider self end + # rubocop: enable Metrics/CyclomaticComplexity def create_verification_webhook parameters = {} create_webhook(parameters.merge(event_names: [PactBroker::Webhooks::WebhookEvent::VERIFICATION_PUBLISHED])) @@ -580,7 +582,7 @@ def default_json_content "interactions" => [], "random" => rand }.to_json - end + end end end end diff --git a/lib/pact_broker/ui/helpers/matrix_helper.rb b/lib/pact_broker/ui/helpers/matrix_helper.rb index af84b3608..8c9fb9e9a 100644 --- a/lib/pact_broker/ui/helpers/matrix_helper.rb +++ b/lib/pact_broker/ui/helpers/matrix_helper.rb @@ -5,12 +5,13 @@ module MatrixHelper extend self + # rubocop: disable Metrics/CyclomaticComplexity def create_selector_objects(selector_hashes) selector_hashes.collect do | selector_hash | o = OpenStruct.new(selector_hash) - o.specify_latest_tag = o.tag && o.latest ? 'checked' : nil - o.specify_latest_branch = o.branch && o.latest ? 'checked' : nil - o.specify_all_tagged = o.tag && !o.latest ? 'checked' : nil + o.specify_latest_tag = (o.tag && o.latest) ? 'checked' : nil + o.specify_latest_branch = (o.branch && o.latest) ? 'checked' : nil + o.specify_all_tagged = (o.tag && !o.latest) ? 'checked' : nil o.specify_latest = o.latest ? 'checked' : nil o.specify_version = o.pacticipant_version_number ? 'checked' : nil o.specify_all_versions = !(o.tag || o.pacticipant_version_number || o.branch) ? 'checked' : nil @@ -35,6 +36,7 @@ def matrix_badge_url(selectors, lines, base_url) end end end + # rubocop: enable Metrics/CyclomaticComplexity end end end diff --git a/lib/pact_broker/ui/view_models/index_item.rb b/lib/pact_broker/ui/view_models/index_item.rb index 75ddea8ac..ac2b9c77f 100644 --- a/lib/pact_broker/ui/view_models/index_item.rb +++ b/lib/pact_broker/ui/view_models/index_item.rb @@ -133,11 +133,11 @@ def webhook_last_execution_date def webhook_url url = case @relationship.webhook_status - when :none - PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url - else - PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url - end + when :none + PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url + else + PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url + end PactBroker::Api::PactBrokerUrls.hal_browser_url(url, base_url) end diff --git a/lib/pact_broker/versions/eager_loaders.rb b/lib/pact_broker/versions/eager_loaders.rb index aa0857ffb..718f0a526 100644 --- a/lib/pact_broker/versions/eager_loaders.rb +++ b/lib/pact_broker/versions/eager_loaders.rb @@ -2,7 +2,7 @@ module PactBroker module Versions module EagerLoaders class LatestVersionForBranch - def self.call(eo, **other) + def self.call(eo, **_other) initialize_association(eo[:rows]) populate_associations(eo[:rows]) end @@ -12,8 +12,8 @@ def self.initialize_association(versions) end def self.populate_associations(versions) - group_by_pacticipant_id(versions).each do | pacticipant, versions | - populate_associations_by_pacticipant(pacticipant, versions) + group_by_pacticipant_id(versions).each do | pacticipant, participant_versions | + populate_associations_by_pacticipant(pacticipant, participant_versions) end end @@ -44,13 +44,13 @@ def self.latest_versions_for_pacticipant_branches(pacticipant_id, branches, vers end class LatestVersionForPacticipant - def self.call(eo, **other) + def self.call(eo, **_other) populate_associations(eo[:rows]) end def self.populate_associations(versions) - group_by_pacticipant(versions).each do | pacticipant, versions | - populate_associations_by_pacticipant(pacticipant, versions) + group_by_pacticipant(versions).each do | pacticipant, participant_versions | + populate_associations_by_pacticipant(pacticipant, participant_versions) end end diff --git a/lib/pact_broker/versions/repository.rb b/lib/pact_broker/versions/repository.rb index c3a3bcbdd..fb7e8f44b 100644 --- a/lib/pact_broker/versions/repository.rb +++ b/lib/pact_broker/versions/repository.rb @@ -106,11 +106,9 @@ def replace_tags(saved_version, open_struct_tags) end def find_by_pacticipant_id_and_number_or_create pacticipant_id, number - if version = find_by_pacticipant_id_and_number(pacticipant_id, number) - version - else - create(pacticipant_id: pacticipant_id, number: number) - end + version = find_by_pacticipant_id_and_number(pacticipant_id, number) + + version ? version : create(pacticipant_id: pacticipant_id, number: number) end def delete_by_id version_ids @@ -121,8 +119,6 @@ def delete_orphan_versions consumer, provider version_ids_with_pact_publications = PactBroker::Pacts::PactPublication.where(consumer_id: [consumer.id, provider.id]).select(:consumer_version_id).collect{|r| r[:consumer_version_id]} version_ids_with_verifications = PactBroker::Domain::Verification.where(provider_id: [provider.id, consumer.id]).select(:provider_version_id).collect{|r| r[:provider_version_id]} # Hope we don't hit max parameter constraints here... - version_ids_to_keep = (version_ids_with_pact_publications + version_ids_with_verifications).uniq - PactBroker::Domain::Version .where(Sequel[:versions][:pacticipant_id] => [consumer.id, provider.id]) .exclude(id: (version_ids_with_pact_publications + version_ids_with_verifications).uniq) diff --git a/lib/pact_broker/versions/service.rb b/lib/pact_broker/versions/service.rb index 418f5d9d3..3e59c4ca7 100644 --- a/lib/pact_broker/versions/service.rb +++ b/lib/pact_broker/versions/service.rb @@ -7,7 +7,7 @@ class Service extend PactBroker::Messages extend PactBroker::Repositories - def self.conflict_errors(existing_version, open_struct_version, version_url) + def self.conflict_errors(_existing_version, _open_struct_version, _version_url) # This validation is causing problems in the PF build when branches are merged # TODO remove this properly when re-doing the version -> branch relationship {} diff --git a/lib/pact_broker/webhooks/pact_and_verification_parameters.rb b/lib/pact_broker/webhooks/pact_and_verification_parameters.rb index e446f9647..7623928dc 100644 --- a/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +++ b/lib/pact_broker/webhooks/pact_and_verification_parameters.rb @@ -44,6 +44,7 @@ def initialize(pact, trigger_verification, webhook_context) @base_url = webhook_context.fetch(:base_url) end + # rubocop: disable Metrics/CyclomaticComplexity def to_hash @hash ||= { PACT_URL => pact ? PactBroker::Api::PactBrokerUrls.pact_version_url_with_webhook_metadata(pact, base_url) : "", @@ -64,6 +65,7 @@ def to_hash CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER => currently_deployed_provider_version_number } end + # rubocop: enable Metrics/CyclomaticComplexity private diff --git a/lib/pact_broker/webhooks/redact_logs.rb b/lib/pact_broker/webhooks/redact_logs.rb index 240bc2358..62e02a22d 100644 --- a/lib/pact_broker/webhooks/redact_logs.rb +++ b/lib/pact_broker/webhooks/redact_logs.rb @@ -14,8 +14,8 @@ def redact_logs(logs, values) def self.call logs, values substitutions = HEADER_SUBSTITUTIONS + value_substitutions(values) - substitutions.reduce(logs) do | logs, (find, replace) | - logs.gsub(find, replace) + substitutions.reduce(logs) do | agg_logs, (find, replace) | + agg_logs.gsub(find, replace) end end diff --git a/lib/pact_broker/webhooks/render.rb b/lib/pact_broker/webhooks/render.rb index c64767eff..2bef0c201 100644 --- a/lib/pact_broker/webhooks/render.rb +++ b/lib/pact_broker/webhooks/render.rb @@ -18,11 +18,10 @@ def self.call(template, params, &escaper) render_template(escape_params(params, escaper || DEFAULT_ESCAPER), template) end - private def self.render_template(params, template) - params.inject(template) do | template, (key, value) | - template.gsub("${#{key}}", value) + params.inject(template) do | agg, (key, value) | + agg.gsub("${#{key}}", value) end end diff --git a/lib/pact_broker/webhooks/repository.rb b/lib/pact_broker/webhooks/repository.rb index d84bef4b2..d34db023e 100644 --- a/lib/pact_broker/webhooks/repository.rb +++ b/lib/pact_broker/webhooks/repository.rb @@ -96,6 +96,7 @@ def find_webhooks_to_trigger consumer: , provider: , event_name: .collect(&:to_domain) end + # rubocop: disable Metrics/ParameterLists def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_type, event_name, event_context db_webhook = deliberately_unscoped(Webhook).where(uuid: webhook.uuid).single_record TriggeredWebhook.create( @@ -112,6 +113,7 @@ def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_ event_context: event_context ) end + # rubocop: enable Metrics/ParameterLists def update_triggered_webhook_status triggered_webhook, status triggered_webhook.update(status: status) diff --git a/lib/pact_broker/webhooks/service.rb b/lib/pact_broker/webhooks/service.rb index 9b8dbd038..8e3702007 100644 --- a/lib/pact_broker/webhooks/service.rb +++ b/lib/pact_broker/webhooks/service.rb @@ -110,8 +110,8 @@ def maintain_redacted_params(webhook, params) new_headers = params['request']['headers'] ||= {} existing_headers = webhook.request.headers - starred_new_headers = new_headers.select { |key, value| value =~ /^\**$/ } - starred_new_headers.each do | (key, value) | + starred_new_headers = new_headers.select { |_key, value| value =~ /^\**$/ } + starred_new_headers.each do | (key, _value) | new_headers[key] = existing_headers[key] end params['request']['headers'] = new_headers diff --git a/lib/pact_broker/webhooks/status.rb b/lib/pact_broker/webhooks/status.rb index b107d0a25..732a58ad6 100644 --- a/lib/pact_broker/webhooks/status.rb +++ b/lib/pact_broker/webhooks/status.rb @@ -2,7 +2,7 @@ module PactBroker module Webhooks class Status - def initialize pact, webhooks, latest_triggered_webhooks + def initialize _pact, webhooks, latest_triggered_webhooks @webhooks = webhooks @latest_triggered_webhooks = latest_triggered_webhooks end @@ -11,6 +11,7 @@ def to_s to_sym.to_s end + # rubocop: disable Metrics/CyclomaticComplexity def to_sym return :none if webhooks.empty? return :not_run if latest_triggered_webhooks.empty? || latest_triggered_webhooks.all?{|w| w.status == "not_run"} @@ -19,6 +20,7 @@ def to_sym end latest_triggered_webhooks.all?{|w| w.status == "success"} ? :success : :failure end + # rubocop: enable Metrics/CyclomaticComplexity private diff --git a/lib/pact_broker/webhooks/trigger_service.rb b/lib/pact_broker/webhooks/trigger_service.rb index 07ebbc71c..01f9c10b9 100644 --- a/lib/pact_broker/webhooks/trigger_service.rb +++ b/lib/pact_broker/webhooks/trigger_service.rb @@ -53,9 +53,9 @@ def create_triggered_webhooks_for_webhooks webhooks, pact, verification, event_n expanded_event_contexts = expand_events_for_currently_deployed_environments(webhook, pact, event_context) expanded_event_contexts = expanded_event_contexts.flat_map { | ec | expand_events_for_verification_of_multiple_selected_pacts(ec) } - expanded_event_contexts.collect do | event_context | - pact_for_triggered_webhook = verification ? find_pact_for_verification_triggered_webhook(pact, event_context) : pact - webhook_repository.create_triggered_webhook(next_uuid, webhook, pact_for_triggered_webhook, verification, RESOURCE_CREATION, event_name, event_context) + expanded_event_contexts.collect do | expanded_event_context | + pact_for_triggered_webhook = verification ? find_pact_for_verification_triggered_webhook(pact, expanded_event_context) : pact + webhook_repository.create_triggered_webhook(next_uuid, webhook, pact_for_triggered_webhook, verification, RESOURCE_CREATION, event_name, expanded_event_context) end end end @@ -95,7 +95,7 @@ def merge_consumer_version_selectors(consumer_version_number, selectors, event_c # verification published webhook is for reporting git statuses, # it makes more sense to trigger per consumer version number (ie. commit). def expand_events_for_verification_of_multiple_selected_pacts(event_context) - triggers = if event_context[:consumer_version_selectors].is_a?(Array) + if event_context[:consumer_version_selectors].is_a?(Array) event_context[:consumer_version_selectors] .group_by{ | selector | selector[:consumer_version_number] } .collect { | consumer_version_number, selectors | merge_consumer_version_selectors(consumer_version_number, selectors, event_context.without(:consumer_version_selectors)) } diff --git a/lib/pact_broker/webhooks/webhook.rb b/lib/pact_broker/webhooks/webhook.rb index 76ffe29af..a071d1e83 100644 --- a/lib/pact_broker/webhooks/webhook.rb +++ b/lib/pact_broker/webhooks/webhook.rb @@ -110,7 +110,6 @@ def delete super end - private def self.properties_hash_from_domain webhook is_json_request_body = !(String === webhook.request.body || webhook.request.body.nil?) # Can't rely on people to set content type diff --git a/lib/pact_broker/webhooks/webhook_request_logger.rb b/lib/pact_broker/webhooks/webhook_request_logger.rb index 08ee26613..1525f3a02 100644 --- a/lib/pact_broker/webhooks/webhook_request_logger.rb +++ b/lib/pact_broker/webhooks/webhook_request_logger.rb @@ -13,7 +13,7 @@ class WebhookRequestLogger class Formatter < Logger::Formatter Format = "[%s] %s: %s\n".freeze - def call(severity, time, progname, msg) + def call(severity, time, _progname, msg) Format % [format_datetime(time), severity, msg2str(msg)] end diff --git a/lib/pact_broker/webhooks/webhook_request_template.rb b/lib/pact_broker/webhooks/webhook_request_template.rb index 9fb7b7012..3633dc9af 100644 --- a/lib/pact_broker/webhooks/webhook_request_template.rb +++ b/lib/pact_broker/webhooks/webhook_request_template.rb @@ -13,7 +13,8 @@ class WebhookRequestTemplate HEADERS_TO_REDACT = [/authorization/i, /token/i] - attr_accessor :method, :url, :headers, :body, :username, :password, :uuid + attr_accessor :method, :url, :body, :username, :password, :uuid + attr_reader :headers # Reform gets confused by the :method method, as :method is a standard # Ruby method. diff --git a/lib/rack/hal_browser/redirect.rb b/lib/rack/hal_browser/redirect.rb index 6497954a1..831e6f793 100644 --- a/lib/rack/hal_browser/redirect.rb +++ b/lib/rack/hal_browser/redirect.rb @@ -6,7 +6,7 @@ module Rack module HalBrowser class Redirect - def initialize(app, options = {}, &block) + def initialize(app, options = {}) @app = app @excluded_paths = Array(options[:exclude]) << '/hal-browser' @hal_browser = Rack::Static.new(@app, :urls => ['/hal-browser'], :root => ::File.expand_path('../../../../vendor', __FILE__)) diff --git a/lib/rack/pact_broker/no_auth.rb b/lib/rack/pact_broker/no_auth.rb index fa8f3c6cc..7bfa9d773 100644 --- a/lib/rack/pact_broker/no_auth.rb +++ b/lib/rack/pact_broker/no_auth.rb @@ -1,7 +1,7 @@ module Rack module PactBroker class NoAuth - def initialize app, *args, &block + def initialize app, *_args @app = app end diff --git a/lib/webmachine/rack_adapter_monkey_patch.rb b/lib/webmachine/rack_adapter_monkey_patch.rb index 021bd599a..acce2520a 100644 --- a/lib/webmachine/rack_adapter_monkey_patch.rb +++ b/lib/webmachine/rack_adapter_monkey_patch.rb @@ -7,10 +7,12 @@ module Webmachine class RackRequest < Webmachine::Request attr_reader :env + # rubocop: disable Metrics/ParameterLists def initialize(method, uri, headers, body, routing_tokens, base_uri, env) super(method, uri, headers, body, routing_tokens, base_uri) @env = env end + # rubocop: enable Metrics/ParameterLists end end diff --git a/regression/regression_helper.rb b/regression/regression_helper.rb index 1ffd1e8c6..dbe90fc05 100644 --- a/regression/regression_helper.rb +++ b/regression/regression_helper.rb @@ -41,7 +41,7 @@ def app PactBroker::API end - config.after(:each) do | example, something | + config.after(:each) do | example, _something | if ENV["SHOW_REGRESSION_DIFF"] == "true" if example.exception.is_a?(Approvals::ApprovalError) require "pact/support" diff --git a/scaffolding/run.rb b/scaffolding/run.rb index a6c8dee11..441af0cab 100755 --- a/scaffolding/run.rb +++ b/scaffolding/run.rb @@ -41,10 +41,6 @@ def model_top_module model_full_class_name.split("::").first end -def repository_class_full_name - model_full_class_name.split("::")[0..1].join("::") + "::Repository" -end - # Resource def resource_top_module @@ -60,7 +56,7 @@ def resource_class_full_name end def resource_url_path - model_class_name_snakecase.gsub("_", "-") + "s" + model_class_name_snakecase.tr("_", "-") + "s" end # Decorator diff --git a/script/seed.rb b/script/seed.rb index 559126ba1..88d142f3f 100755 --- a/script/seed.rb +++ b/script/seed.rb @@ -9,7 +9,7 @@ require 'sequel' require 'logger' require 'stringio' -logger = Logger.new($stdout) +# logger = Logger.new($stdout) logger = Logger.new(StringIO.new) DATABASE_CREDENTIALS = {logger: logger, adapter: "sqlite", database: ARGV[0], :encoding => 'utf8'}.tap { |it| puts it } #DATABASE_CREDENTIALS = {adapter: "postgres", database: "pact_broker", username: 'pact_broker', password: 'pact_broker', :encoding => 'utf8'} @@ -31,19 +31,19 @@ connection[table_name].delete end - # .create_webhook(method: 'GET', url: 'https://localhost:9393?url=${pactbroker.pactUrl}', body: '${pactbroker.pactUrl}') +# .create_webhook(method: 'GET', url: 'https://localhost:9393?url=${pactbroker.pactUrl}', body: '${pactbroker.pactUrl}') -webhook_body = { - 'pactUrl' => '${pactbroker.pactUrl}', - 'verificationResultUrl' => '${pactbroker.verificationResultUrl}', - 'consumerVersionNumber' => '${pactbroker.consumerVersionNumber}', - 'providerVersionNumber' => '${pactbroker.providerVersionNumber}', - 'providerVersionTags' => '${pactbroker.providerVersionTags}', - 'consumerVersionTags' => '${pactbroker.consumerVersionTags}', - 'consumerName' => '${pactbroker.consumerName}', - 'providerName' => '${pactbroker.providerName}', - 'githubVerificationStatus' => '${pactbroker.githubVerificationStatus}' -} +# webhook_body = { +# 'pactUrl' => '${pactbroker.pactUrl}', +# 'verificationResultUrl' => '${pactbroker.verificationResultUrl}', +# 'consumerVersionNumber' => '${pactbroker.consumerVersionNumber}', +# 'providerVersionNumber' => '${pactbroker.providerVersionNumber}', +# 'providerVersionTags' => '${pactbroker.providerVersionTags}', +# 'consumerVersionTags' => '${pactbroker.consumerVersionTags}', +# 'consumerName' => '${pactbroker.consumerName}', +# 'providerName' => '${pactbroker.providerName}', +# 'githubVerificationStatus' => '${pactbroker.githubVerificationStatus}' +# } PactBroker.configuration.base_equality_only_on_content_that_affects_verification_results = false diff --git a/spec/integration/ui/index_spec.rb b/spec/integration/ui/index_spec.rb index e480193e5..1717cbd86 100644 --- a/spec/integration/ui/index_spec.rb +++ b/spec/integration/ui/index_spec.rb @@ -24,14 +24,14 @@ end it "returns a table of pacts" do - expect(subject.body.scan(' 1 + expect(subject.body.scan(' 1 end end diff --git a/spec/integration/webhooks/certificate_spec.rb b/spec/integration/webhooks/certificate_spec.rb index 780f6afed..7927a267e 100644 --- a/spec/integration/webhooks/certificate_spec.rb +++ b/spec/integration/webhooks/certificate_spec.rb @@ -6,7 +6,7 @@ def wait_for_server_to_start Faraday.new(url: "https://localhost:4444", ssl: {verify: false}) do |builder| builder.request :retry, max: 20, interval: 0.5, exceptions: [StandardError] - builder.adapter :net_http + builder.adapter :net_http end.get end diff --git a/spec/lib/pact/doc/interaction_view_model_spec.rb b/spec/lib/pact/doc/interaction_view_model_spec.rb index 66438d2e3..e0a51542f 100644 --- a/spec/lib/pact/doc/interaction_view_model_spec.rb +++ b/spec/lib/pact/doc/interaction_view_model_spec.rb @@ -70,7 +70,7 @@ module Doc end it "renders the keys in a meaningful order" do - expect(subject.request).to match /"method".*"path".*"query".*"headers".*"body"/m + expect(subject.request).to match(/"method".*"path".*"query".*"headers".*"body"/m) end context "when the body hash is empty" do @@ -116,7 +116,7 @@ module Doc end it "renders the keys in a meaningful order" do - expect(subject.response).to match /"status".*"headers".*"body"/m + expect(subject.response).to match(/"status".*"headers".*"body"/m) end context "when the body hash is empty" do diff --git a/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_spec.rb b/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_spec.rb index 5e69c99fa..ecde361ce 100644 --- a/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_spec.rb +++ b/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_spec.rb @@ -40,7 +40,7 @@ module Contracts extra_keys = ALL_PROPERTIES.keys - valid_key_combination - [:consumer] extra_keys.each do | extra_key | selector_with_extra_key = selector.merge(extra_key => ALL_PROPERTIES[extra_key]) - expect_to_be_valid = !!VALID_KEY_COMBINATIONS.find{ | valid_key_combination | valid_key_combination.sort == selector_with_extra_key.keys.sort } + expect_to_be_valid = !!VALID_KEY_COMBINATIONS.find{ | k | k.sort == selector_with_extra_key.keys.sort } params = { consumerVersionSelectors: [selector_with_extra_key] } describe "with #{selector_with_extra_key}" do diff --git a/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb b/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb index 3d441f3d5..fafb77819 100644 --- a/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +++ b/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb @@ -52,7 +52,7 @@ module Contracts end it "has an error" do - expect(subject[:consumerVersionSelectors].first).to match /can only be set.*index 0/ + expect(subject[:consumerVersionSelectors].first).to match(/can only be set.*index 0/) end context "when there are multiple errors" do @@ -110,7 +110,7 @@ module Contracts end it "flattens the messages" do - expect(subject[:consumerVersionSelectors].first).to match /must specify a value.*at index 0/ + expect(subject[:consumerVersionSelectors].first).to match(/must specify a value.*at index 0/) end end diff --git a/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb index 1d1443f07..86055a9c6 100644 --- a/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb @@ -47,7 +47,7 @@ module Decorators allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, provider).and_return('provider_url') allow_any_instance_of(DashboardDecorator).to receive(:version_url).with(base_url, consumer_version).and_return('consumer_version_url') allow_any_instance_of(DashboardDecorator).to receive(:webhooks_status_url).with(consumer, provider, base_url).and_return('webhooks_status_url') - allow_any_instance_of(DashboardDecorator).to receive(:tag_url) do | instance, base_url, tag | + allow_any_instance_of(DashboardDecorator).to receive(:tag_url) do | _instance, base_url, tag | if tag.version == consumer_version expect(tag.name).to eq 'prod' expect(tag.version).to be consumer_version diff --git a/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb index 439e8dbc1..2bcd5b105 100644 --- a/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb @@ -91,10 +91,10 @@ module Decorators it "includes a list of sorted pacts" do expect(subject[:_links][:'pb:pact-versions']).to be_instance_of(Array) - expect(subject[:_links][:'pb:pact-versions'].first[:href]).to include ("1.2.3") - expect(subject[:_links][:'pb:pact-versions'].first[:name]).to include ("Pact between") - expect(subject[:_links][:'pb:pact-versions'].first[:name]).to include ("providerA") - expect(subject[:_links][:'pb:pact-versions'].last[:name]).to include ("ProviderB") + expect(subject[:_links][:'pb:pact-versions'].first[:href]).to include("1.2.3") + expect(subject[:_links][:'pb:pact-versions'].first[:name]).to include("Pact between") + expect(subject[:_links][:'pb:pact-versions'].first[:name]).to include("providerA") + expect(subject[:_links][:'pb:pact-versions'].last[:name]).to include("ProviderB") end it "includes a link to the latest verification results for the pacts for this version" do diff --git a/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb index 510c4d15d..0d0c949fb 100644 --- a/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb @@ -147,7 +147,7 @@ module Decorators let(:description) { " " } it 'uses the scope description' do - expect(parsed_json[:description]).to match /example.org/ + expect(parsed_json[:description]).to match(/example.org/) end end end diff --git a/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb index 2a386bf19..3cac5a694 100644 --- a/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb @@ -118,7 +118,7 @@ module Decorators end it "includes a message about why the response is hidden" do - expect(subject[:message]).to match /security purposes/ + expect(subject[:message]).to match(/security purposes/) end end end diff --git a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb index 65120a4f5..e8aed43a9 100644 --- a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +++ b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb @@ -63,13 +63,13 @@ module Renderers expect(subject).to include("href='http://base/stylesheets/github.css'") expect(subject).to include('
.*Some Consumer/
-            expect(subject).to match /.*Some Provider/
+            expect(subject).to match(/.*Some Consumer/)
+            expect(subject).to match(/.*Some Provider/)
             expect(subject).to include("Date published:")
             expect(subject).to include("Thu 27 Feb 2014, 11:00am +11:00")
             expect(subject).to include("3 days ago")
-            expect(subject).to match /title.*Pact between Consumer and Provider/
-            expect(subject).to match /prod, master/
+            expect(subject).to match(/title.*Pact between Consumer and Provider/)
+            expect(subject).to match(/prod, master/)
           end
 
           it "renders the badge image" do
@@ -126,7 +126,7 @@ module Renderers
             end
 
             it "renders the JSON in HTML" do
-              expect(subject).to match /\[\s+1\s+\]/m
+              expect(subject).to match(/\[\s+1\s+\]/m)
             end
 
             it "logs a warning" do
diff --git a/spec/lib/pact_broker/api/resources/can_i_deploy_spec.rb b/spec/lib/pact_broker/api/resources/can_i_deploy_spec.rb
index 90ef2a20c..2ce2f616b 100644
--- a/spec/lib/pact_broker/api/resources/can_i_deploy_spec.rb
+++ b/spec/lib/pact_broker/api/resources/can_i_deploy_spec.rb
@@ -42,7 +42,7 @@ module Resources
 
           it "returns a 400" do
             expect(subject.status).to eq 400
-            expect(JSON.parse(subject.body)["errors"]["pacticipant"].first).to match /Foo.*found/
+            expect(JSON.parse(subject.body)["errors"]["pacticipant"].first).to match(/Foo.*found/)
           end
         end
       end
diff --git a/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb b/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb
index 9884ed940..fc5d05b03 100644
--- a/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb
+++ b/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb
@@ -1,11 +1,10 @@
 require 'pact_broker/api/resources'
-
 module PactBroker
   module Api
     module Resources
       RSpec.describe "modifiable resources (ones that require write access)" do
         let(:pact_broker_resource_classes) do
-          all_resources = ObjectSpace.each_object(::Class)
+          ObjectSpace.each_object(::Class)
             .select { |klass| klass < DefaultBaseResource }
             .select(&:name)
             .reject { |klass| klass.name.end_with?("BaseResource") }
@@ -58,4 +57,4 @@ def resource.resource_exists?
       end
     end
   end
-end
\ No newline at end of file
+end
diff --git a/spec/lib/pact_broker/api/resources/error_response_body_generator_spec.rb b/spec/lib/pact_broker/api/resources/error_response_body_generator_spec.rb
index 1c4e1dba4..7c1b6cd8b 100644
--- a/spec/lib/pact_broker/api/resources/error_response_body_generator_spec.rb
+++ b/spec/lib/pact_broker/api/resources/error_response_body_generator_spec.rb
@@ -14,7 +14,7 @@ module Resources
           subject { JSON.parse(ErrorResponseBodyGenerator.call(error, error_reference)) }
 
           it "includes an error reference" do
-            expect(subject['error']).to  include 'reference' => "bYWfnyWPlf"
+            expect(subject['error']).to include 'reference' => "bYWfnyWPlf"
           end
 
           context "when show_backtrace_in_error_response? is true" do
@@ -30,7 +30,7 @@ module Resources
               end
 
               it "includes the backtrace in the error response" do
-                expect(subject['error']).to include ('backtrace')
+                expect(subject['error']).to include('backtrace')
               end
             end
           end
@@ -48,17 +48,17 @@ module Resources
               end
 
               it "does not include the backtrace in the error response" do
-                expect(subject['error']).to_not include ('backtrace')
+                expect(subject['error']).to_not include('backtrace')
               end
             end
 
             context "when the error is not a PactBroker::Error or subclass" do
               it "uses a hardcoded error message" do
-                expect(subject['error']['message']).to match /An error/
+                expect(subject['error']['message']).to match(/An error/)
               end
 
               it "does not include the backtrace in the error response" do
-                expect(subject['error']).to_not include ('backtrace')
+                expect(subject['error']).to_not include('backtrace')
               end
             end
           end
diff --git a/spec/lib/pact_broker/app_spec.rb b/spec/lib/pact_broker/app_spec.rb
index d0102a1d8..8a6acc8a6 100644
--- a/spec/lib/pact_broker/app_spec.rb
+++ b/spec/lib/pact_broker/app_spec.rb
@@ -28,7 +28,7 @@ def configure_database_connection
 
     it "adds the X-Pact-Broker-Version header" do
       get "/"
-      expect(last_response.headers['X-Pact-Broker-Version']).to match /\d/
+      expect(last_response.headers['X-Pact-Broker-Version']).to match(/\d/)
     end
 
     class Middleware
@@ -55,8 +55,8 @@ def self.calls
     describe "before_resource and after_resource" do
       CALLBACKS = []
       before do
-        PactBroker.configuration.before_resource { | resource | CALLBACKS << "before" }
-        PactBroker.configuration.after_resource { | resource | CALLBACKS << "after" }
+        PactBroker.configuration.before_resource { | _resource | CALLBACKS << "before" }
+        PactBroker.configuration.after_resource { | _resource | CALLBACKS << "after" }
       end
 
       it "executes the callbacks" do
@@ -113,7 +113,7 @@ def self.calls
 
     describe "use_xxx_auth" do
       class TestAuth
-        def initialize app, *args, &block
+        def initialize app, *_args
           @app = Rack::Auth::Basic.new(app, "Protected") do | username, password |
             username == 'foo' && password == 'bar'
           end
@@ -182,7 +182,7 @@ class TestAuth2 < TestAuth1; end
 
     describe "authenticate" do
       before do
-        PactBroker.configuration.authenticate do | resource, authorization_header, options |
+        PactBroker.configuration.authenticate do | _resource, authorization_header, _options |
           authorization_header == 'letmein'
         end
       end
@@ -204,7 +204,7 @@ class TestAuth2 < TestAuth1; end
 
     describe "authenticate_with_basic_auth" do
       before do
-        PactBroker.configuration.authenticate_with_basic_auth do | resource, username, password, options |
+        PactBroker.configuration.authenticate_with_basic_auth do | _resource, username, password, _options |
           username == 'username' && password == 'password'
         end
       end
@@ -260,7 +260,7 @@ class TestAuth2 < TestAuth1; end
 
     describe "authorize" do
       before do
-        PactBroker.configuration.authorize do | resource, options |
+        PactBroker.configuration.authorize do | resource, _options |
           resource.request.headers['Role'] == 'important'
         end
       end
diff --git a/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb b/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb
index 0a6e4fb93..3e979644d 100644
--- a/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb
+++ b/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb
@@ -7,7 +7,7 @@ module DataMigrations
         include MigrationHelpers
 
         describe ".call" do
-          before (:all) do
+          before(:all) do
             PactBroker::Database.migrate(20190509)
           end
 
diff --git a/spec/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch_spec.rb b/spec/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch_spec.rb
index 5ab39d2ff..ed9f2df23 100644
--- a/spec/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch_spec.rb
+++ b/spec/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch_spec.rb
@@ -5,7 +5,7 @@ module DB
     module DataMigrations
       describe SetPacticipantMainBranch, data_migration: true  do
         describe ".call" do
-          before (:all) do
+          before(:all) do
             PactBroker::Database.migrate(20210529)
           end
 
diff --git a/spec/lib/pact_broker/matrix/integration_spec.rb b/spec/lib/pact_broker/matrix/integration_spec.rb
index b43c278fb..85701c9b8 100644
--- a/spec/lib/pact_broker/matrix/integration_spec.rb
+++ b/spec/lib/pact_broker/matrix/integration_spec.rb
@@ -106,11 +106,11 @@ module Matrix
           end
 
           it "returns 1 row with a verification" do
-            expect(subject.rows.select(&:has_verification?).size).to eq 1
+            expect(subject.rows.count(&:has_verification?)).to eq 1
           end
 
           it "returns 1 row without a verification" do
-            expect(subject.rows.reject(&:has_verification?).size).to eq 1
+            expect(subject.rows.count{ |row| !row.has_verification? }).to eq 1
           end
 
           it "does not allow the consumer to be deployed" do
@@ -372,11 +372,11 @@ module Matrix
             end
 
             it "finds all prod versions of Foo" do
-              expect(subject.select { |row| row.consumer_name == "Foo"}.size).to eq 2
+              expect(subject.count { |row| row.consumer_name == "Foo"}).to eq 2
             end
 
             it "finds the single prod version of Cat" do
-              expect(subject.select { |row| row.consumer_name == "Cat"}.size).to eq 1
+              expect(subject.count { |row| row.consumer_name == "Cat"}).to eq 1
             end
 
             it "is not deployable because of the missing verification for Cat v20" do
diff --git a/spec/lib/pact_broker/matrix/repository_dependency_spec.rb b/spec/lib/pact_broker/matrix/repository_dependency_spec.rb
index 534349fba..4c0defcff 100644
--- a/spec/lib/pact_broker/matrix/repository_dependency_spec.rb
+++ b/spec/lib/pact_broker/matrix/repository_dependency_spec.rb
@@ -50,7 +50,7 @@ def shorten_rows rows
 
         it "returns an array with one row that does not have a verification" do
           expect(results.first).to_not have_verification
-          expect(results.resolved_selectors.find{ |s | s[:pacticipant_name] == "Bar"}.pacticipant_version_id).to eq -1
+          expect(results.resolved_selectors.find{ |s | s[:pacticipant_name] == "Bar"}.pacticipant_version_id).to eq(-1)
         end
       end
     end
diff --git a/spec/lib/pact_broker/matrix/repository_query_limit_spec.rb b/spec/lib/pact_broker/matrix/repository_query_limit_spec.rb
index 06fa00d23..055528c79 100644
--- a/spec/lib/pact_broker/matrix/repository_query_limit_spec.rb
+++ b/spec/lib/pact_broker/matrix/repository_query_limit_spec.rb
@@ -62,14 +62,14 @@ module Matrix
         subject { Repository.new.find(selectors, options) }
 
         it "includes rows from each direction" do
-          expect(subject.count{ |r| r.consumer_name == 'Foo' }).to eq (subject.count{ |r| r.consumer_name == 'Bar' })
+          expect(subject.count{ |r| r.consumer_name == 'Foo' }).to eq(subject.count{ |r| r.consumer_name == 'Bar' })
         end
 
         context "when where is a latestby" do
           let(:options) { { limit: 4, latestby: 'cvpv'} }
 
           it "includes rows from each direction" do
-            expect(subject.count{ |r| r.consumer_name == 'Foo' }).to eq (subject.count{ |r| r.consumer_name == 'Bar' })
+            expect(subject.count{ |r| r.consumer_name == 'Foo' }).to eq(subject.count{ |r| r.consumer_name == 'Bar' })
           end
         end
       end
diff --git a/spec/lib/pact_broker/pacticipants/service_spec.rb b/spec/lib/pact_broker/pacticipants/service_spec.rb
index 34124a4e8..160f5a838 100644
--- a/spec/lib/pact_broker/pacticipants/service_spec.rb
+++ b/spec/lib/pact_broker/pacticipants/service_spec.rb
@@ -122,101 +122,69 @@ module Pacticipants
 
         context "deleting a consumer" do
           it "deletes the pacticipant" do
-            expect{ delete_consumer }.to change{
-                PactBroker::Domain::Pacticipant.all.count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Domain::Pacticipant.all.count }.by(-1)
           end
 
           it "deletes the child versions" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Domain::Version.where(number: "1.2.3").count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Domain::Version.where(number: "1.2.3").count }.by(-1)
           end
 
           it "deletes the child tags" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Domain::Tag.where(name: "prod").count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Domain::Tag.where(name: "prod").count }.by(-1)
           end
 
           it "deletes the webhooks" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Webhooks::Webhook.count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Webhooks::Webhook.count }.by(-1)
           end
 
           it "deletes the triggered webhooks" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Webhooks::TriggeredWebhook.count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Webhooks::TriggeredWebhook.count }.by(-1)
           end
 
           it "deletes the webhook executions" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Webhooks::Execution.count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Webhooks::Execution.count }.by(-1)
           end
 
           it "deletes the child pacts" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Pacts::PactPublication.count
-              }.by(-2)
+            expect{ delete_consumer }.to change{ PactBroker::Pacts::PactPublication.count }.by(-2)
           end
 
           it "deletes the verifications" do
-            expect{ delete_consumer }.to change{
-              PactBroker::Domain::Verification.count
-              }.by(-1)
+            expect{ delete_consumer }.to change{ PactBroker::Domain::Verification.count }.by(-1)
           end
         end
 
         context "deleting a provider" do
           it "deletes the pacticipant" do
-            expect{ delete_provider }.to change{
-                PactBroker::Domain::Pacticipant.all.count
-              }.by(-1)
+            expect{ delete_provider }.to change{ PactBroker::Domain::Pacticipant.all.count }.by(-1)
           end
 
           it "does not delete any versions" do
-            expect{ delete_provider }.to change{
-              PactBroker::Domain::Version.where(number: "1.2.3").count
-              }.by(0)
+            expect{ delete_provider }.to change{ PactBroker::Domain::Version.where(number: "1.2.3").count }.by(0)
           end
 
           it "deletes the child tags only if there are any" do
-            expect{ delete_provider }.to change{
-              PactBroker::Domain::Tag.where(name: "prod").count
-              }.by(0)
+            expect{ delete_provider }.to change{ PactBroker::Domain::Tag.where(name: "prod").count }.by(0)
           end
 
           it "deletes the webhooks" do
-            expect{ delete_provider }.to change{
-              PactBroker::Webhooks::Webhook.count
-              }.by(-1)
+            expect{ delete_provider }.to change{ PactBroker::Webhooks::Webhook.count }.by(-1)
           end
 
           it "deletes the triggered webhooks" do
-            expect{ delete_provider }.to change{
-              PactBroker::Webhooks::TriggeredWebhook.count
-              }.by(-1)
+            expect{ delete_provider }.to change{ PactBroker::Webhooks::TriggeredWebhook.count }.by(-1)
           end
 
           it "deletes the webhook executions" do
-            expect{ delete_provider }.to change{
-              PactBroker::Webhooks::Execution.count
-              }.by(-1)
+            expect{ delete_provider }.to change{ PactBroker::Webhooks::Execution.count }.by(-1)
           end
 
           it "deletes the child pacts" do
-            expect{ delete_provider }.to change{
-              PactBroker::Pacts::PactPublication.count
-              }.by(-2)
+            expect{ delete_provider }.to change{ PactBroker::Pacts::PactPublication.count }.by(-2)
           end
 
           it "deletes the verifications" do
-            expect{ delete_provider }.to change{
-              PactBroker::Domain::Verification.count
-              }.by(-1)
+            expect{ delete_provider }.to change{ PactBroker::Domain::Verification.count }.by(-1)
           end
 
         end
diff --git a/spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb b/spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb
index 672fedceb..9dccb7585 100644
--- a/spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb
+++ b/spec/lib/pact_broker/pacts/create_formatted_diff_spec.rb
@@ -19,8 +19,8 @@ module Pacts
 
         it "returns the formatted diff" do
           expect(subject).to include 'interactions'
-          expect(subject).to match /\-.*post/
-          expect(subject).to match /\+.*get/
+          expect(subject).to match(/\-.*post/)
+          expect(subject).to match(/\+.*get/)
           expect(subject).to_not include 'Key'
         end
       end
diff --git a/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb b/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb
index 3586a7ce8..13f902c3b 100644
--- a/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb
+++ b/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb
@@ -140,7 +140,7 @@ module Pacts
 
         it "returns the latest pact publications for each consumer/branch" do
           expect(subject.size).to eq 3
-          hashes = subject.collect(&:values)
+          subject.collect(&:values)
 
           expect(subject.find { |pp| pp.consumer_id == foo.id && pp[:tag_name] == "main" }.consumer_version.number).to eq "3"
           expect(subject.find { |pp| pp.consumer_id == foo.id && pp[:tag_name] == "feat/x" }.consumer_version.number).to eq "4"
diff --git a/spec/lib/pact_broker/pacts/pact_publication_spec.rb b/spec/lib/pact_broker/pacts/pact_publication_spec.rb
index bb7e2c079..695e40605 100644
--- a/spec/lib/pact_broker/pacts/pact_publication_spec.rb
+++ b/spec/lib/pact_broker/pacts/pact_publication_spec.rb
@@ -254,7 +254,7 @@ module Pacts
 
         it "returns the latest pact publications for each consumer/branch" do
           expect(subject.size).to eq 3
-          hashes = subject.collect(&:values)
+          subject.collect(&:values)
 
           expect(subject.find { |pp| pp.consumer_id == foo.id && pp[:branch] == "main" }.consumer_version.number).to eq "3"
           expect(subject.find { |pp| pp.consumer_id == foo.id && pp[:branch] == "feat/x" }.consumer_version.number).to eq "4"
@@ -341,7 +341,7 @@ module Pacts
 
         it "returns the latest pact publications for each consumer/branch" do
           expect(subject.size).to eq 3
-          hashes = subject.collect(&:values)
+          subject.collect(&:values)
 
           expect(subject.find { |pp| pp.consumer_id == foo.id && pp[:tag_name] == "main" }.consumer_version.number).to eq "3"
           expect(subject.find { |pp| pp.consumer_id == foo.id && pp[:tag_name] == "feat/x" }.consumer_version.number).to eq "4"
diff --git a/spec/lib/pact_broker/webhooks/render_spec.rb b/spec/lib/pact_broker/webhooks/render_spec.rb
index 6dda7a1ca..927782c5b 100644
--- a/spec/lib/pact_broker/webhooks/render_spec.rb
+++ b/spec/lib/pact_broker/webhooks/render_spec.rb
@@ -11,7 +11,7 @@ module Webhooks
       describe "#call" do
         before do
           allow(PactBroker::Api::PactBrokerUrls).to receive(:pact_version_url_with_webhook_metadata).and_return("http://foo")
-          allow(PactBroker::Api::PactBrokerUrls).to receive(:verification_url) do | verification, base_url |
+          allow(PactBroker::Api::PactBrokerUrls).to receive(:verification_url) do | verification, _base_url |
             expect(verification).to_not be nil
             "http://verification"
           end
@@ -54,11 +54,11 @@ module Webhooks
             latest_verification: failed_verification)
         end
 
-        let (:provider) do
+        let(:provider) do
           double("provider", labels: provider_labels)
         end
 
-        let (:consumer) do
+        let(:consumer) do
           double("consumer", labels: consumer_labels)
         end
 
diff --git a/spec/lib/pact_broker/webhooks/repository_spec.rb b/spec/lib/pact_broker/webhooks/repository_spec.rb
index a26bea204..6078c8bce 100644
--- a/spec/lib/pact_broker/webhooks/repository_spec.rb
+++ b/spec/lib/pact_broker/webhooks/repository_spec.rb
@@ -77,9 +77,7 @@ module Webhooks
         subject { Repository.new.delete_by_uuid(uuid) }
 
         it "deletes the webhook" do
-          expect { subject }.to change {
-            ::DB::PACT_BROKER_DB[:webhooks].where(uuid: uuid).count
-            }.by(-1)
+          expect { subject }.to change { ::DB::PACT_BROKER_DB[:webhooks].where(uuid: uuid).count }.by(-1)
         end
       end
 
@@ -765,7 +763,7 @@ module Webhooks
           end
 
           it "deletes the webhooks belonging to the consumer version" do
-            expect { subject }.to change{ TriggeredWebhook.count }.by (-1)
+            expect { subject }.to change{ TriggeredWebhook.count }.by(-1)
           end
         end
 
@@ -781,7 +779,7 @@ module Webhooks
           end
 
           it "deletes the webhooks belonging to the consumer version" do
-            expect { subject }.to change{ TriggeredWebhook.count }.by (-1)
+            expect { subject }.to change{ TriggeredWebhook.count }.by(-1)
           end
         end
       end
diff --git a/spec/lib/pact_broker/webhooks/service_spec.rb b/spec/lib/pact_broker/webhooks/service_spec.rb
index 293571ec9..085993215 100644
--- a/spec/lib/pact_broker/webhooks/service_spec.rb
+++ b/spec/lib/pact_broker/webhooks/service_spec.rb
@@ -82,7 +82,7 @@ module Webhooks
 
         it "sends through the params to the repository" do
           updated_webhook = nil
-          allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
+          allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | _instance, _uuid, webhook |
             updated_webhook = webhook
             true
           end
@@ -95,7 +95,7 @@ module Webhooks
 
           it "does not overwite the password" do
             updated_webhook = nil
-            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
+            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | _instance, _uuid, webhook |
               updated_webhook = webhook
               true
             end
@@ -117,7 +117,7 @@ module Webhooks
 
           it "does not overwite the password" do
             updated_webhook = nil
-            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
+            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | _instance, _uuid, webhook |
               updated_webhook = webhook
               true
             end
@@ -141,7 +141,7 @@ module Webhooks
 
           it "does not overwite the authorization header" do
             updated_webhook = nil
-            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
+            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | _instance, _uuid, webhook |
               updated_webhook = webhook
               true
             end
@@ -161,7 +161,7 @@ module Webhooks
 
           it "updates the password" do
             updated_webhook = nil
-            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | instance, uuid, webhook |
+            allow_any_instance_of(PactBroker::Webhooks::Repository).to receive(:update_by_uuid) do | _instance, _uuid, webhook |
               updated_webhook = webhook
               true
             end
diff --git a/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb b/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb
index 6a533e8f0..cddb99d0c 100644
--- a/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb
+++ b/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb
@@ -38,7 +38,7 @@ module Webhooks
 
       describe "#build" do
         before do
-          allow(PactBroker::Webhooks::Render).to receive(:call) do | content, pact, verification, &block |
+          allow(PactBroker::Webhooks::Render).to receive(:call) do | content, _pact, _verification |
             content + "BUILT"
           end
         end
diff --git a/spec/lib/rack/hal_browser/redirect_spec.rb b/spec/lib/rack/hal_browser/redirect_spec.rb
index be68a9bbd..41455d315 100644
--- a/spec/lib/rack/hal_browser/redirect_spec.rb
+++ b/spec/lib/rack/hal_browser/redirect_spec.rb
@@ -7,7 +7,7 @@ module HalBrowser
       include Rack::Test::Methods
 
       let(:inner_app) do
-        ->(env) { [200, {'Content-Type' => 'text/html'}, ['All good!']] }
+        ->(_env) { [200, {'Content-Type' => 'text/html'}, ['All good!']] }
       end
 
       let(:app) { Redirect.new(inner_app) }
diff --git a/spec/lib/rack/pact_broker/add_pact_broker_version_header_spec.rb b/spec/lib/rack/pact_broker/add_pact_broker_version_header_spec.rb
index afa037dfe..887268d42 100644
--- a/spec/lib/rack/pact_broker/add_pact_broker_version_header_spec.rb
+++ b/spec/lib/rack/pact_broker/add_pact_broker_version_header_spec.rb
@@ -4,11 +4,11 @@ module Rack
   module PactBroker
     describe AddPactBrokerVersionHeader do
 
-      let(:app) { AddPactBrokerVersionHeader.new(->(env){[200, {}, []]}) }
+      let(:app) { AddPactBrokerVersionHeader.new(->(_env){[200, {}, []]}) }
 
       it "adds the PactBroker version as a header" do
         get "/"
-        expect(last_response.headers['X-Pact-Broker-Version']).to match /\d/
+        expect(last_response.headers['X-Pact-Broker-Version']).to match(/\d/)
       end
 
     end
diff --git a/spec/lib/rack/pact_broker/database_transaction_spec.rb b/spec/lib/rack/pact_broker/database_transaction_spec.rb
index a0e167b03..584f4245d 100644
--- a/spec/lib/rack/pact_broker/database_transaction_spec.rb
+++ b/spec/lib/rack/pact_broker/database_transaction_spec.rb
@@ -16,7 +16,7 @@ module PactBroker
       let(:headers) { {} }
 
       let(:api) do
-        ->(env) { ::PactBroker::Domain::Pacticipant.create(name: 'Foo'); [500, headers, []] }
+        ->(_env) { ::PactBroker::Domain::Pacticipant.create(name: 'Foo'); [500, headers, []] }
       end
 
       let(:app) do
@@ -42,7 +42,6 @@ module PactBroker
         let(:existing_database_connector) { double('existing database connector') }
 
         it "does not overwrite it" do
-          actual_env = nil
           expect(api).to receive(:call).with(hash_including("pactbroker.database_connector" => existing_database_connector)).and_call_original
           subject
         end
diff --git a/spec/lib/rack/pact_broker/invalid_uri_protection_spec.rb b/spec/lib/rack/pact_broker/invalid_uri_protection_spec.rb
index c3692d82a..4d9e4f4e7 100644
--- a/spec/lib/rack/pact_broker/invalid_uri_protection_spec.rb
+++ b/spec/lib/rack/pact_broker/invalid_uri_protection_spec.rb
@@ -3,7 +3,7 @@
 module Rack
   module PactBroker
     describe InvalidUriProtection do
-      let(:target_app) { ->(env){ [200, {}, []] } }
+      let(:target_app) { ->(_env){ [200, {}, []] } }
       let(:app) { InvalidUriProtection.new(target_app) }
       let(:path) { URI.encode("/foo") }
 
diff --git a/spec/lib/rack/pact_broker/use_when_spec.rb b/spec/lib/rack/pact_broker/use_when_spec.rb
index 85bd20395..9b6e1955d 100644
--- a/spec/lib/rack/pact_broker/use_when_spec.rb
+++ b/spec/lib/rack/pact_broker/use_when_spec.rb
@@ -21,7 +21,7 @@ def call(env)
       end
 
       let(:app) do
-        target_app = -> (env) { [200, {}, []] }
+        target_app = -> (_env) { [200, {}, []] }
         builder = Rack::Builder.new
         condition = ->(env) { env['PATH_INFO'] == '/match' }
         builder.use_when condition, TestMiddleware, { "Foo" => "Bar" }
diff --git a/spec/lib/sequel/plugins/upsert_spec.rb b/spec/lib/sequel/plugins/upsert_spec.rb
index 62c5f356d..5fe5885e1 100644
--- a/spec/lib/sequel/plugins/upsert_spec.rb
+++ b/spec/lib/sequel/plugins/upsert_spec.rb
@@ -26,7 +26,7 @@ class LatestPactPublicationIdForConsumerVersion < Sequel::Model(:latest_pact_pub
 
       describe PacticipantNoUpsert do
         it "has an _insert_dataset method" do
-          expect(PacticipantNoUpsert.private_instance_methods).to include (:_insert_dataset)
+          expect(PacticipantNoUpsert.private_instance_methods).to include(:_insert_dataset)
         end
       end
 
diff --git a/spec/migrations/change_migration_strategy_spec.rb b/spec/migrations/change_migration_strategy_spec.rb
index ca4518e74..6c36d3907 100644
--- a/spec/migrations/change_migration_strategy_spec.rb
+++ b/spec/migrations/change_migration_strategy_spec.rb
@@ -48,7 +48,7 @@ def execute command
     version_id = @db[:versions].insert(number: '1.2.3', order: 1, pacticipant_id: consumer_id, created_at: DateTime.now, updated_at: DateTime.now)
     pact_json = {consumer: {name: 'Foo'}, provider: {name: 'Bar'}, interactions: []}.to_json
     pact_version_id = @db[:pact_versions].insert(sha: '123', content: pact_json, created_at: DateTime.now, consumer_id: consumer_id, provider_id: provider_id)
-    pact_publication_id = @db[:pact_publications].insert(consumer_version_id: version_id, provider_id: provider_id, revision_number: 1, pact_version_id: pact_version_id, created_at: DateTime.now)
+    @db[:pact_publications].insert(consumer_version_id: version_id, provider_id: provider_id, revision_number: 1, pact_version_id: pact_version_id, created_at: DateTime.now)
   end
 
   it "does not have a schema_migrations table" do
@@ -65,7 +65,7 @@ def execute command
 
   it "uses the schema_migrations table after v2.6.0" do
     expect(@db.table_exists?(:schema_migrations)).to be true
-    migrations_count = Dir.glob("db/migrations/**.*").select{ |f| f =~ /\/\d+/ }.count
+    migrations_count = Dir.glob("db/migrations/**.*").count{ |f| f =~ /\/\d+/ }
     expect(migrations_count).to be >= 47
     expect(@db[:schema_migrations].count).to eq migrations_count
     expect(@db[:schema_migrations].order(:filename).first[:filename]).to eq '000001_create_pacticipant_table.rb'
diff --git a/spec/service_consumers/pact_helper.rb b/spec/service_consumers/pact_helper.rb
index cbcf293d9..e7aaa1d19 100644
--- a/spec/service_consumers/pact_helper.rb
+++ b/spec/service_consumers/pact_helper.rb
@@ -23,7 +23,7 @@
 module Rack
   module PactBroker
     class DatabaseTransaction
-      def do_not_rollback? response
+      def do_not_rollback? _response
         # Dodgey hack to stop exceptions raising a Rollback error while verifying
         # Otherwise the provider states that deliberately raise exceptions
         # end up raising exceptions that break the verification tests
diff --git a/spec/service_consumers/provider_states_for_pact_broker_client.rb b/spec/service_consumers/provider_states_for_pact_broker_client.rb
index f076073d4..ab9dae5ce 100644
--- a/spec/service_consumers/provider_states_for_pact_broker_client.rb
+++ b/spec/service_consumers/provider_states_for_pact_broker_client.rb
@@ -192,7 +192,7 @@
 
   provider_state "'Condor' does not exist in the pact-broker" do
      no_op
-   end
+  end
 
    provider_state "a pact between Condor and the Pricing Service exists for the production version of Condor" do
      set_up do
diff --git a/spec/service_consumers/provider_states_for_pact_ruby.rb b/spec/service_consumers/provider_states_for_pact_ruby.rb
index 7ff96fcb1..689a1e95f 100644
--- a/spec/service_consumers/provider_states_for_pact_ruby.rb
+++ b/spec/service_consumers/provider_states_for_pact_ruby.rb
@@ -146,7 +146,7 @@
 
   provider_state "the relation for retrieving pacts for verifications exists in the index resource" do
       no_op
-    end
+  end
 
     provider_state "Foo has a pact tagged cdev with provider Bar" do
       set_up do
diff --git a/spec/support/rspec_matchers.rb b/spec/support/rspec_matchers.rb
index fc14f631e..b821c9ae9 100644
--- a/spec/support/rspec_matchers.rb
+++ b/spec/support/rspec_matchers.rb
@@ -1,4 +1,4 @@
-RSpec::Matchers.define :be_datey do |expected|
+RSpec::Matchers.define :be_datey do |_expected|
   match do |actual|
     actual.instance_of?(DateTime) || actual.instance_of?(Time)
   end
diff --git a/spec/support/ssl_webhook_server.rb b/spec/support/ssl_webhook_server.rb
index e589f98a2..bb789a5db 100644
--- a/spec/support/ssl_webhook_server.rb
+++ b/spec/support/ssl_webhook_server.rb
@@ -24,7 +24,7 @@ def webrick_opts port
     }
   end
 
-  app = ->(env) { puts "hello"; [200, {}, ['Hello world' + "\n"]] }
+  app = ->(_env) { puts "hello"; [200, {}, ['Hello world' + "\n"]] }
 
   require 'webrick'
   require 'webrick/https'
diff --git a/tasks/db.rake b/tasks/db.rake
index 16c9165a8..25d113069 100644
--- a/tasks/db.rake
+++ b/tasks/db.rake
@@ -68,13 +68,13 @@ namespace :db do
   end
 
   desc 'Migrate the Database'
-  task :migrate, [:target] => 'db:env' do |t, args|
+  task :migrate, [:target] => 'db:env' do |_t, args|
     target = args[:target] ? args[:target].to_i : nil
     PactBroker::Database.migrate(target)
   end
 
   desc 'Rollback database to specified version'
-  task :rollback, [:target] => 'db:env' do |t, args|
+  task :rollback, [:target] => 'db:env' do |_t, args|
     args.with_defaults(target: 0)
     PactBroker::Database.migrate(args[:target].to_i)
   end
diff --git a/tasks/development.rake b/tasks/development.rake
index 7f0055a3c..c9c52cc29 100644
--- a/tasks/development.rake
+++ b/tasks/development.rake
@@ -1,4 +1,3 @@
-
 desc 'Set up a dev instance of the Pact Broker'
 task 'pact_broker:dev:setup' do
   puts "Copying example directory"
@@ -19,7 +18,7 @@ task 'pact_broker:dev:setup' do
 end
 
 desc 'List the Pact Broker API routes'
-task 'pact_broker:routes', [:search_term] do | t, args |
+task 'pact_broker:routes', [:search_term] do | _, args |
   puts "Listing routes containing the term '#{args[:search_term]}'" if args[:search_term]
   require 'tempfile'
   require 'sequel'
@@ -33,7 +32,6 @@ task 'pact_broker:routes', [:search_term] do | t, args |
     PactBroker::DB.run_migrations(CONNECTION)
 
     require 'pact_broker/api'
-    PactBroker::API
 
     routes_debugging = PactBroker::API.application.routes.collect do | route |
       ["/" + route.path_spec.collect{ |part| part.is_a?(Symbol) ? ":#{part}" : part  }.join("/"), route.resource]