diff --git a/.rubocop.yml b/.rubocop.yml index 93d9f9bd81..59deaef368 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ # # The configuration is split into three files. Look into those files for more details. # -require: +plugins: - rubocop-capybara - rubocop-factory_bot - rubocop-rails diff --git a/.rubocop_styleguide.yml b/.rubocop_styleguide.yml index 91c745cdd9..fd219703a4 100644 --- a/.rubocop_styleguide.yml +++ b/.rubocop_styleguide.yml @@ -94,7 +94,7 @@ Metrics/PerceivedComplexity: Enabled: true Max: 14 # default 8 -Naming/PredicateName: +Naming/PredicatePrefix: Enabled: false Naming/VariableNumber: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8403c4cdb6..09312b9253 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,44 @@ # This configuration was generated by # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp` -# using RuboCop version 1.64.1. +# using RuboCop version 1.81.6. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: RequireParenthesesForMethodChains. +Lint/AmbiguousRange: + Exclude: + - 'app/models/concerns/permalink_generator.rb' + +# Offense count: 6 +Lint/CopDirectiveSyntax: + Exclude: + - 'app/services/orders/bulk_cancel_service.rb' + - 'lib/tasks/simplecov.rake' + - 'spec/models/database_spec.rb' + - 'spec/system/admin/bulk_order_management_spec.rb' + - 'spec/system/admin/enterprise_relationships_spec.rb' + +# Offense count: 2 +Lint/DuplicateMethods: + Exclude: + - 'app/models/spree/order.rb' + - 'engines/order_management/app/services/order_management/subscriptions/form.rb' + +# Offense count: 3 +Lint/UselessConstantScoping: + Exclude: + - 'app/services/weights_and_measures.rb' + - 'lib/reporting/report_metadata_builder.rb' + +# Offense count: 1 +Lint/UselessOr: + Exclude: + - 'app/models/product_import/entry_validator.rb' + # Offense count: 24 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max. Metrics/AbcSize: @@ -42,7 +75,7 @@ Metrics/BlockLength: - 'lib/tasks/data.rake' # Offense count: 1 -# Configuration parameters: CountBlocks, Max. +# Configuration parameters: CountBlocks, CountModifierForms, Max. Metrics/BlockNesting: Exclude: - 'app/models/spree/payment/processing.rb' @@ -182,8 +215,9 @@ Metrics/PerceivedComplexity: - 'app/models/spree/order/checkout.rb' # Offense count: 1 -# Configuration parameters: EnforcedStyle, AllowedPatterns. +# Configuration parameters: EnforcedStyle, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns. # SupportedStyles: snake_case, camelCase +# ForbiddenIdentifiers: __id__, __send__ Naming/MethodName: Exclude: - 'engines/dfc_provider/lib/dfc_provider/catalog_item.rb' @@ -195,23 +229,132 @@ Naming/MethodParameterName: Exclude: - 'engines/dfc_provider/lib/dfc_provider/catalog_item.rb' +# Offense count: 59 +# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates. +# AllowedMethods: call +# WaywardPredicates: nonzero? +Naming/PredicateMethod: + Exclude: + - 'app/controllers/admin/product_import_controller.rb' + - 'app/controllers/api/v0/order_cycles_controller.rb' + - 'app/controllers/spree/admin/overview_controller.rb' + - 'app/controllers/spree/admin/payments_controller.rb' + - 'app/controllers/voucher_adjustments_controller.rb' + - 'app/forms/enterprise_fees_bulk_update.rb' + - 'app/forms/schedule_form.rb' + - 'app/helpers/spree/orders_helper.rb' + - 'app/models/concerns/variant_stock.rb' + - 'app/models/enterprise.rb' + - 'app/models/enterprise_fee.rb' + - 'app/models/invoice/data_presenter.rb' + - 'app/models/order_cycle.rb' + - 'app/models/product_import/entry_processor.rb' + - 'app/models/product_import/entry_validator.rb' + - 'app/models/spree/order.rb' + - 'app/models/spree/order_contents.rb' + - 'app/models/spree/payment.rb' + - 'app/models/spree/payment/processing.rb' + - 'app/models/spree/state_change.rb' + - 'app/models/spree/user.rb' + - 'app/reflexes/admin/orders_reflex.rb' + - 'app/serializers/api/admin/for_order_cycle/enterprise_serializer.rb' + - 'app/serializers/api/admin/index_enterprise_serializer.rb' + - 'app/serializers/api/admin/index_order_cycle_serializer.rb' + - 'app/serializers/api/admin/order_cycle_serializer.rb' + - 'app/serializers/api/admin/order_serializer.rb' + - 'app/serializers/api/admin/schedule_serializer.rb' + - 'app/serializers/api/admin/subscription_line_item_serializer.rb' + - 'app/serializers/api/admin/user_serializer.rb' + - 'app/serializers/api/admin/variant_serializer.rb' + - 'app/serializers/api/enterprise_shopfront_serializer.rb' + - 'app/serializers/api/enterprise_thin_serializer.rb' + - 'app/serializers/api/order_serializer.rb' + - 'app/serializers/api/uncached_enterprise_serializer.rb' + - 'app/services/cart_service.rb' + - 'app/services/orders/fetch_adjustments_service.rb' + - 'app/services/orders/workflow_service.rb' + - 'app/services/sets/model_set.rb' + - 'app/services/sets/order_cycle_set.rb' + - 'app/services/sets/product_set.rb' + - 'engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb' + - 'lib/open_food_network/order_cycle_form_applicator.rb' + - 'lib/open_food_network/order_cycle_permissions.rb' + - 'lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb' + - 'lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb' + - 'lib/tasks/data/check_invalid_address_used.rake' + # Offense count: 3 -# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns. +# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns. # SupportedStyles: snake_case, camelCase Naming/VariableName: Exclude: - 'engines/dfc_provider/lib/dfc_provider/catalog_item.rb' +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +Rails/FindByOrAssignmentMemoization: + Exclude: + - 'app/controllers/admin/customers_controller.rb' + - 'app/controllers/admin/resource_controller.rb' + - 'app/controllers/api/v0/enterprise_fees_controller.rb' + - 'app/controllers/api/v0/order_cycles_controller.rb' + - 'lib/stripe/account_connector.rb' + +# Offense count: 32 +# This cop supports unsafe autocorrection (--autocorrect-all). +Rails/OrderArguments: + Exclude: + - 'app/controllers/admin/enterprise_fees_controller.rb' + - 'app/controllers/admin/enterprises_controller.rb' + - 'app/controllers/admin/order_cycles_controller.rb' + - 'app/controllers/admin/product_import_controller.rb' + - 'app/controllers/api/v0/states_controller.rb' + - 'app/controllers/spree/admin/overview_controller.rb' + - 'app/controllers/spree/admin/products_controller.rb' + - 'app/helpers/enterprises_helper.rb' + - 'app/models/enterprise.rb' + - 'app/models/enterprise_group.rb' + - 'app/models/enterprise_relationship_permission.rb' + - 'app/models/order_cycle.rb' + - 'app/models/product_import/product_importer.rb' + - 'app/models/schedule.rb' + - 'app/models/spree/country.rb' + - 'app/models/spree/order.rb' + - 'app/models/spree/shipping_rate.rb' + - 'app/models/spree/user.rb' + - 'app/models/spree/zone.rb' + - 'app/models/subscription_line_item.rb' + - 'app/models/tag_rule.rb' + - 'app/models/variant_override.rb' + - 'lib/open_food_network/address_finder.rb' + - 'spec/services/orders/generate_invoice_service_spec.rb' + - 'spec/system/admin/order_cycles/simple_spec.rb' + # Offense count: 1 # Configuration parameters: TransactionMethods. Rails/TransactionExitStatement: Exclude: - 'app/services/place_proxy_order.rb' +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/ArrayIntersect: + Exclude: + - 'app/models/spree/ability.rb' + - 'app/models/spree/variant.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/BitwisePredicate: + Exclude: + - 'app/helpers/admin/enterprises_helper.rb' + # Offense count: 23 # This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. +# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules. # SupportedStyles: nested, compact +# SupportedStylesForClasses: ~, nested, compact +# SupportedStylesForModules: ~, nested, compact Style/ClassAndModuleChildren: Exclude: - 'app/models/calculator/flat_percent_per_item.rb' @@ -237,6 +380,29 @@ Style/ClassAndModuleChildren: - 'lib/open_food_network/locking.rb' - 'spec/models/spree/payment_method_spec.rb' +# Offense count: 14 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/CollectionQuerying: + Exclude: + - 'app/controllers/spree/credit_cards_controller.rb' + - 'app/models/product_import/product_importer.rb' + - 'app/models/product_import/spreadsheet_entry.rb' + - 'app/models/spree/order.rb' + - 'app/models/spree/order_inventory.rb' + - 'app/models/spree/payment_method.rb' + - 'app/models/spree/user.rb' + - 'app/models/stripe_account.rb' + - 'app/services/order_cycles/warning_service.rb' + - 'lib/reporting/report_renderer.rb' + - 'lib/tasks/sample_data.rake' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/HashSlice: + Exclude: + - 'app/services/product_filters.rb' + - 'lib/reporting/report_row_builder.rb' + # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Style/MapToHash: @@ -274,3 +440,22 @@ Style/OptionalBooleanParameter: - 'engines/order_management/app/services/order_management/stock/estimator.rb' - 'lib/spree/core/controller_helpers/order.rb' - 'spec/support/request/web_helper.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/RedundantFormat: + Exclude: + - 'spec/models/product_importer_spec.rb' + - 'spec/requests/checkout/stripe_sca_spec.rb' + - 'spec/system/consumer/account/cards_spec.rb' + +# Offense count: 8 +# Configuration parameters: Max. +Style/SafeNavigationChainLength: + Exclude: + - 'app/controllers/concerns/extra_fields.rb' + - 'app/services/customer_syncer.rb' + - 'app/services/fdc_offer_broker.rb' + - 'engines/dfc_provider/app/services/dfc_catalog.rb' + - 'engines/dfc_provider/app/services/image_builder.rb' + - 'engines/dfc_provider/app/services/quantitative_value_builder.rb' diff --git a/Gemfile b/Gemfile index 6ce7c34560..73e0a6d151 100644 --- a/Gemfile +++ b/Gemfile @@ -194,8 +194,11 @@ group :development do gem 'query_count' gem 'rails-erd' gem 'rubocop' + gem 'rubocop-capybara' + gem 'rubocop-factory_bot' gem 'rubocop-rails' gem 'rubocop-rspec' + gem 'rubocop-rspec_rails' gem 'spring' gem 'spring-commands-rspec' gem 'spring-commands-rubocop' diff --git a/Gemfile.lock b/Gemfile.lock index 2aaf140924..8efbe8fce6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -192,8 +192,8 @@ GEM base64 (0.3.0) bcp47_spec (0.2.1) bcrypt (3.1.20) - benchmark (0.4.1) - bigdecimal (3.2.2) + benchmark (0.5.0) + bigdecimal (3.3.1) bindata (2.5.0) bindex (0.8.1) bootsnap (1.18.3) @@ -380,7 +380,7 @@ GEM highline (2.0.3) htmlentities (4.3.4) http_parser.rb (0.8.0) - i18n (1.14.5) + i18n (1.14.7) concurrent-ruby (~> 1.0) i18n-js (3.9.2) i18n (>= 0.6.6) @@ -416,7 +416,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (4.2.1) railties (>= 3.2.16) - json (2.7.2) + json (2.15.2) json-canonicalization (1.0.0) json-jwt (1.16.6) activesupport (>= 4.2) @@ -444,13 +444,14 @@ GEM base64 knapsack_pro (8.1.2) rake - language_server-protocol (3.17.0.3) + language_server-protocol (3.17.0.5) launchy (3.0.0) addressable (~> 2.8) childprocess (~> 5.0) letter_opener (1.10.0) launchy (>= 2.2, < 4) link_header (0.0.8) + lint_roller (1.1.0) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -539,10 +540,10 @@ GEM paper_trail (15.1.0) activerecord (>= 6.1) request_store (~> 1.4) - parallel (1.24.0) + parallel (1.27.0) paranoia (2.6.3) activerecord (>= 5.1, < 7.2) - parser (3.3.9.0) + parser (3.3.10.0) ast (~> 2.4.1) racc paypal-sdk-core (0.3.4) @@ -560,6 +561,7 @@ GEM pp (0.6.2) prettyprint prettyprint (0.2.0) + prism (1.6.0) private_address_check (0.5.0) pry (0.13.1) coderay (~> 1.1) @@ -671,7 +673,7 @@ GEM redis-client (>= 0.22.0) redis-client (0.26.1) connection_pool - regexp_parser (2.9.2) + regexp_parser (2.11.3) reline (0.6.2) io-console (~> 0.5) request_store (1.5.1) @@ -734,35 +736,39 @@ GEM rswag-ui (2.16.0) actionpack (>= 5.2, < 8.1) railties (>= 5.2, < 8.1) - rubocop (1.64.1) + rubocop (1.81.6) json (~> 2.3) - language_server-protocol (>= 3.17.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.31.1, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.47.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.31.3) - parser (>= 3.3.1.0) - rubocop-capybara (2.20.0) - rubocop (~> 1.41) - rubocop-factory_bot (2.25.1) - rubocop (~> 1.41) - rubocop-rails (2.28.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.47.1) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-capybara (2.22.1) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-factory_bot (2.27.1) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rails (2.33.4) activesupport (>= 4.2.0) + lint_roller (~> 1.1) rack (>= 1.1) - rubocop (>= 1.52.0, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (2.29.2) - rubocop (~> 1.40) - rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) - rubocop-rspec_rails (~> 2.28) - rubocop-rspec_rails (2.28.3) - rubocop (~> 1.40) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rspec (3.7.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rspec_rails (2.31.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rspec (~> 3.5) ruby-graphviz (1.2.5) rexml ruby-progressbar (1.13.0) @@ -873,7 +879,9 @@ GEM rugged (>= 0.27, < 1.10) simplecov simplecov_json_formatter - unicode-display_width (2.5.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.1.0) uniform_notifier (1.17.0) uri (0.13.2) valid_email2 (5.2.3) @@ -1043,8 +1051,11 @@ DEPENDENCIES rswag-api rswag-ui rubocop + rubocop-capybara + rubocop-factory_bot rubocop-rails rubocop-rspec + rubocop-rspec_rails sd_notify select2-rails! shoulda-matchers diff --git a/app/components/searchable_dropdown_component.rb b/app/components/searchable_dropdown_component.rb index c9d1549f72..1f4d5f9e87 100644 --- a/app/components/searchable_dropdown_component.rb +++ b/app/components/searchable_dropdown_component.rb @@ -30,7 +30,7 @@ class SearchableDropdownComponent < ViewComponent::Base :aria_label, :other_attrs def classes - "fullwidth #{remove_search_plugin? ? 'no-input' : ''}" + "fullwidth #{'no-input' if remove_search_plugin?}" end def data diff --git a/app/controllers/admin/bulk_line_items_controller.rb b/app/controllers/admin/bulk_line_items_controller.rb index cb818862da..f0e0fc6ee8 100644 --- a/app/controllers/admin/bulk_line_items_controller.rb +++ b/app/controllers/admin/bulk_line_items_controller.rb @@ -3,6 +3,7 @@ module Admin class BulkLineItemsController < Spree::Admin::BaseController include PaginationData + # GET /admin/bulk_line_items.json # def index diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 69de0f84f1..bea2a2adc0 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -4,6 +4,7 @@ module Admin class ReportsController < Spree::Admin::BaseController include ActiveStorage::SetCurrent include ReportsActions + helper ReportsHelper before_action :authorize_report, only: [:show, :create] diff --git a/app/controllers/api/v0/exchange_products_controller.rb b/app/controllers/api/v0/exchange_products_controller.rb index 25586088b2..ab43ede371 100644 --- a/app/controllers/api/v0/exchange_products_controller.rb +++ b/app/controllers/api/v0/exchange_products_controller.rb @@ -7,6 +7,7 @@ module Api module V0 class ExchangeProductsController < Api::V0::BaseController include PaginationData + DEFAULT_PER_PAGE = 100 skip_authorization_check only: [:index] diff --git a/app/controllers/api/v0/products_controller.rb b/app/controllers/api/v0/products_controller.rb index 6f95e1e64e..a4e7a6e4c2 100644 --- a/app/controllers/api/v0/products_controller.rb +++ b/app/controllers/api/v0/products_controller.rb @@ -7,6 +7,7 @@ module Api module V0 class ProductsController < Api::V0::BaseController include PaginationData + respond_to :json DEFAULT_PER_PAGE = 15 diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 51eaef777b..b02ff61825 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -6,6 +6,7 @@ module Spree module Admin class OrdersController < Spree::Admin::BaseController include OpenFoodNetwork::SpreeApiKeyLoader + helper CheckoutHelper before_action :load_order, only: [:edit, :update, :fire, :resend, :invoice, :print] diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 2e036ffdb6..3fce0fc118 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -10,6 +10,7 @@ module Spree include OpenFoodNetwork::SpreeApiKeyLoader include OrderCyclesHelper include EnterprisesHelper + helper ::Admin::ProductsHelper helper Spree::Admin::TaxCategoriesHelper diff --git a/app/controllers/spree/user_passwords_controller.rb b/app/controllers/spree/user_passwords_controller.rb index 6b1572757c..e753f53543 100644 --- a/app/controllers/spree/user_passwords_controller.rb +++ b/app/controllers/spree/user_passwords_controller.rb @@ -14,6 +14,7 @@ module Spree include Spree::Core::ControllerHelpers::Order include I18nHelper + before_action :set_locale # Devise::PasswordsController allows for blank passwords. diff --git a/app/forms/schedule_form.rb b/app/forms/schedule_form.rb index e596afb4a0..56eb94d7ec 100644 --- a/app/forms/schedule_form.rb +++ b/app/forms/schedule_form.rb @@ -36,9 +36,7 @@ class ScheduleForm false unless @schedule.update(permitted_resource_params) end - def order_cycle_ids - @schedule.order_cycle_ids - end + delegate :order_cycle_ids, to: :@schedule private diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index 0b21a7bb91..c69f50fa2f 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -120,7 +120,7 @@ module InjectionHelper def inject_enterprise_attributes(enterprise_attributes) render partial: "json/injection_ams", - locals: { name: 'enterpriseAttributes', json: enterprise_attributes.to_json.to_s } + locals: { name: 'enterpriseAttributes', json: enterprise_attributes.to_json } end def inject_saved_credit_cards diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index e8c38f0b73..1caab98aa9 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -44,9 +44,7 @@ module ReportsHelper .pluck(:name, :id) end - def currency_symbol - Spree::Money.currency_symbol - end + delegate :currency_symbol, to: :'Spree::Money' def enterprise_fee_owner_ids(orders) EnterpriseFee.where(id: enterprise_fee_ids(orders)) diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb index a31aa38141..7ed94e80ad 100644 --- a/app/helpers/terms_and_conditions_helper.rb +++ b/app/helpers/terms_and_conditions_helper.rb @@ -10,9 +10,7 @@ module TermsAndConditionsHelper TermsOfService.required?(distributor) end - def platform_terms_required? - TermsOfService.platform_terms_required? - end + delegate :platform_terms_required?, to: :TermsOfService def distributor_terms_required? TermsOfService.distributor_terms_required?(current_order.distributor) diff --git a/app/jobs/bulk_invoice_job.rb b/app/jobs/bulk_invoice_job.rb index c77eb077f9..948ca3c3ad 100644 --- a/app/jobs/bulk_invoice_job.rb +++ b/app/jobs/bulk_invoice_job.rb @@ -2,6 +2,7 @@ class BulkInvoiceJob < ApplicationJob include CableReady::Broadcaster + delegate :render, to: ActionController::Base attr_reader :options diff --git a/app/jobs/report_job.rb b/app/jobs/report_job.rb index c9ea5353fd..dd7e372aef 100644 --- a/app/jobs/report_job.rb +++ b/app/jobs/report_job.rb @@ -3,6 +3,7 @@ # Renders a report and stores it in a given blob. class ReportJob < ApplicationJob include CableReady::Broadcaster + delegate :render, to: ActionController::Base before_perform :enable_active_storage_urls diff --git a/app/models/concerns/log_destroy_performer.rb b/app/models/concerns/log_destroy_performer.rb index 62215c2f6a..068d698de6 100644 --- a/app/models/concerns/log_destroy_performer.rb +++ b/app/models/concerns/log_destroy_performer.rb @@ -4,6 +4,7 @@ require 'active_support/concern' module LogDestroyPerformer extend ActiveSupport::Concern + included do attr_accessor :destroyed_by diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index aefc96f9c5..649c069134 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -408,7 +408,7 @@ class Enterprise < ApplicationRecord def category # Make this crazy logic human readable so we can argue about it sanely. cat = is_primary_producer ? "producer_" : "non_producer_" - cat << ("sells_#{sells}") + cat << "sells_#{sells}" # Map backend cases to front end cases. case cat diff --git a/app/models/invoice/data_presenter.rb b/app/models/invoice/data_presenter.rb index f45e35612b..405afdaf1f 100644 --- a/app/models/invoice/data_presenter.rb +++ b/app/models/invoice/data_presenter.rb @@ -3,6 +3,7 @@ class Invoice class DataPresenter include ::ActionView::Helpers::NumberHelper + attr_reader :invoice delegate :display_number, :data, :previous_invoice, to: :invoice @@ -142,7 +143,7 @@ class Invoice end def paid? - data[:payment_state] == 'paid' || data[:payment_state] == 'credit_owed' + ['paid', 'credit_owed'].include?(data[:payment_state]) end def outstanding_balance? diff --git a/app/models/invoice/data_presenter/base.rb b/app/models/invoice/data_presenter/base.rb index c653573cf6..a1e6b2ce6c 100644 --- a/app/models/invoice/data_presenter/base.rb +++ b/app/models/invoice/data_presenter/base.rb @@ -4,6 +4,7 @@ class Invoice class DataPresenter class Base include ::ActionView::Helpers::NumberHelper + attr_reader :data def initialize(data) diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index ca933c37fe..37e8031ecd 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -81,17 +81,13 @@ module ProductImport @reset_counts end - def enterprises_index - @spreadsheet_data.enterprises_index - end + delegate :enterprises_index, to: :@spreadsheet_data def enterprise_products @processor&.enterprise_products end - def total_enterprise_products - @processor.total_enterprise_products - end + delegate :total_enterprise_products, to: :@processor def entries_json entries = {} @@ -130,13 +126,9 @@ module ProductImport @processor.inventory_updated end - def products_reset_count - @processor.products_reset_count - end + delegate :products_reset_count, to: :@processor - def total_saved_count - @processor.total_saved_count - end + delegate :total_saved_count, to: :@processor def import_results { entries: entries_json, reset_counts: } @@ -183,7 +175,7 @@ module ProductImport end def staged_import? - @import_settings&.key?(:start) && @import_settings&.key?(:end) + @import_settings&.key?(:start) && @import_settings.key?(:end) end def init_permissions diff --git a/app/models/spree/calculator.rb b/app/models/spree/calculator.rb index 7c1f11c274..abcabe5539 100644 --- a/app/models/spree/calculator.rb +++ b/app/models/spree/calculator.rb @@ -31,9 +31,7 @@ module Spree self.class.name.titleize.gsub("Calculator/", "") end - def description - self.class.description - end + delegate :description, to: :class def available?(_object) true diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 6b9134ce4f..0ba30064c5 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -97,7 +97,7 @@ module Spree } validate :disallow_guest_order validates :email, presence: true, - format: /\A([\w.%+\-']+)@([\w\-]+\.)+(\w{2,})\z/i, + format: /\A([\w.%+\-']+)@([\w-]+\.)+(\w{2,})\z/i, if: :require_email validates :order_cycle, presence: true, on: :require_distribution @@ -417,7 +417,7 @@ module Spree # Helper methods for checkout steps def paid? - payment_state == 'paid' || payment_state == 'credit_owed' + ['paid', 'credit_owed'].include?(payment_state) end # "Checkout" is the initial state and, for card payments, "pending" is the state after auth diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb index ae7debae6f..a39d6ac0e9 100644 --- a/app/models/spree/shipping_method.rb +++ b/app/models/spree/shipping_method.rb @@ -3,6 +3,7 @@ module Spree class ShippingMethod < ApplicationRecord include CalculatedAdjustments + DISPLAY_ON_OPTIONS = { both: "", back_end: "back_end" diff --git a/app/serializers/api/open_street_map_config_serializer.rb b/app/serializers/api/open_street_map_config_serializer.rb index 29f87ad34e..bdd8622548 100644 --- a/app/serializers/api/open_street_map_config_serializer.rb +++ b/app/serializers/api/open_street_map_config_serializer.rb @@ -8,24 +8,14 @@ module Api :open_street_map_default_latitude, :open_street_map_default_longitude - def open_street_map_enabled - ContentConfig.open_street_map_enabled - end + delegate :open_street_map_enabled, to: :ContentConfig - def open_street_map_provider_name - ContentConfig.open_street_map_provider_name - end + delegate :open_street_map_provider_name, to: :ContentConfig - def open_street_map_provider_options - ContentConfig.open_street_map_provider_options - end + delegate :open_street_map_provider_options, to: :ContentConfig - def open_street_map_default_latitude - ContentConfig.open_street_map_default_latitude - end + delegate :open_street_map_default_latitude, to: :ContentConfig - def open_street_map_default_longitude - ContentConfig.open_street_map_default_longitude - end + delegate :open_street_map_default_longitude, to: :ContentConfig end end diff --git a/app/services/embedded_page_service.rb b/app/services/embedded_page_service.rb index 6e979c9722..efffaf6e16 100644 --- a/app/services/embedded_page_service.rb +++ b/app/services/embedded_page_service.rb @@ -36,7 +36,7 @@ class EmbeddedPageService def embedding_without_https? @request.referer && URI(@request.referer).scheme != 'https' && - !Rails.env.test? && !Rails.env.development? + !Rails.env.local? end def process_embedded_request diff --git a/engines/dfc_provider/app/controllers/dfc_provider/supplied_products_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/supplied_products_controller.rb index 9ccd6ebb66..caad056ecb 100644 --- a/engines/dfc_provider/app/controllers/dfc_provider/supplied_products_controller.rb +++ b/engines/dfc_provider/app/controllers/dfc_provider/supplied_products_controller.rb @@ -31,6 +31,11 @@ module DfcProvider ) end + def show + product = SuppliedProductBuilder.supplied_product(variant) + render json: DfcIo.export(product) + end + def create supplied_product = import&.first @@ -45,11 +50,6 @@ module DfcProvider render json: DfcIo.export(supplied_product) end - def show - product = SuppliedProductBuilder.supplied_product(variant) - render json: DfcIo.export(product) - end - def update supplied_product = import&.first diff --git a/engines/web/app/controllers/web/api/v0/cookies_consent_controller.rb b/engines/web/app/controllers/web/api/v0/cookies_consent_controller.rb index 59a3e62f7d..33e2daaea6 100644 --- a/engines/web/app/controllers/web/api/v0/cookies_consent_controller.rb +++ b/engines/web/app/controllers/web/api/v0/cookies_consent_controller.rb @@ -7,6 +7,7 @@ module Web module V0 class CookiesConsentController < BaseController include ActionController::Cookies + respond_to :json def show diff --git a/lib/reporting/report_template.rb b/lib/reporting/report_template.rb index f8cfe01e08..7ba7f99448 100644 --- a/lib/reporting/report_template.rb +++ b/lib/reporting/report_template.rb @@ -3,6 +3,7 @@ module Reporting class ReportTemplate include ReportsHelper + attr_accessor :user, :params, :ransack_params delegate :render_as, :as_json, :to_html, :to_csv, :to_xlsx, :to_pdf, :to_json, to: :renderer diff --git a/lib/spree/core/controller_helpers/common.rb b/lib/spree/core/controller_helpers/common.rb index 26aef4347a..1297c24094 100644 --- a/lib/spree/core/controller_helpers/common.rb +++ b/lib/spree/core/controller_helpers/common.rb @@ -5,6 +5,7 @@ module Spree module ControllerHelpers module Common extend ActiveSupport::Concern + included do helper_method :title helper_method :title= diff --git a/lib/spree/i18n.rb b/lib/spree/i18n.rb index 38fbd40b00..e82cc0dae7 100644 --- a/lib/spree/i18n.rb +++ b/lib/spree/i18n.rb @@ -22,9 +22,7 @@ module Spree alias_method :t, :translate - def context - Spree::ViewContext.context - end + delegate :context, to: :'Spree::ViewContext' def virtual_path return unless context diff --git a/lib/tasks/sample_data/order_cycle_factory.rb b/lib/tasks/sample_data/order_cycle_factory.rb index 13ca7fe62e..dc490617f7 100644 --- a/lib/tasks/sample_data/order_cycle_factory.rb +++ b/lib/tasks/sample_data/order_cycle_factory.rb @@ -5,6 +5,7 @@ require "tasks/sample_data/logging" module SampleData class OrderCycleFactory include Logging + # rubocop:disable Metrics/MethodLength def create_samples log "Creating order cycles" diff --git a/lib/tasks/subscriptions/test.rake b/lib/tasks/subscriptions/test.rake index c4349f1b7b..39747b6f26 100644 --- a/lib/tasks/subscriptions/test.rake +++ b/lib/tasks/subscriptions/test.rake @@ -22,7 +22,8 @@ namespace :ofn do ProxyOrder.find_by(order_cycle_id:)&.update!( order_id: nil, confirmed_at: nil, - placed_at: nil) + placed_at: nil + ) # Run placement job to create orders SubscriptionPlacementJob.perform_now diff --git a/spec/controllers/api/v0/customers_controller_spec.rb b/spec/controllers/api/v0/customers_controller_spec.rb index 57389a238a..30febcbce2 100644 --- a/spec/controllers/api/v0/customers_controller_spec.rb +++ b/spec/controllers/api/v0/customers_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' module Api RSpec.describe V0::CustomersController do include AuthenticationHelper + render_views let(:user) { create(:user) } diff --git a/spec/controllers/api/v0/orders_controller_spec.rb b/spec/controllers/api/v0/orders_controller_spec.rb index 418d45d8d4..159ff4bebb 100644 --- a/spec/controllers/api/v0/orders_controller_spec.rb +++ b/spec/controllers/api/v0/orders_controller_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Api::V0::OrdersController do include AuthenticationHelper + render_views let!(:regular_user) { create(:user) } diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb index 3b1cb45673..5fe0e4bb24 100644 --- a/spec/controllers/api/v0/product_images_controller_spec.rb +++ b/spec/controllers/api/v0/product_images_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe Api::V0::ProductImagesController do include AuthenticationHelper include FileHelper + render_views describe "uploading an image" do diff --git a/spec/controllers/api/v0/shops_controller_spec.rb b/spec/controllers/api/v0/shops_controller_spec.rb index a494ebb254..876562c533 100644 --- a/spec/controllers/api/v0/shops_controller_spec.rb +++ b/spec/controllers/api/v0/shops_controller_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Api::V0::ShopsController do include AuthenticationHelper + render_views context "as a non-authenticated user" do diff --git a/spec/controllers/shops_controller_spec.rb b/spec/controllers/shops_controller_spec.rb index 914da71979..b89fb67e90 100644 --- a/spec/controllers/shops_controller_spec.rb +++ b/spec/controllers/shops_controller_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe ShopsController do include WebHelper + render_views let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 839d286a7c..f2494e1e97 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -1033,8 +1033,6 @@ RSpec.describe ProductImport::ProductImporter do end end -private - def import_data(csv_data, args = {}) import_user = args[:import_user] || admin import_into = args[:import_into] || 'product_list' diff --git a/spec/models/spree/preferences/preferable_spec.rb b/spec/models/spree/preferences/preferable_spec.rb index 465b4f858e..6876551f83 100644 --- a/spec/models/spree/preferences/preferable_spec.rb +++ b/spec/models/spree/preferences/preferable_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Spree::Preferences::Preferable do a_class = A = Class.new do include Spree::Preferences::Preferable + attr_reader :id def initialize diff --git a/spec/system/admin/configuration/general_settings_spec.rb b/spec/system/admin/configuration/general_settings_spec.rb index 5f2f33c921..0607a2bc57 100644 --- a/spec/system/admin/configuration/general_settings_spec.rb +++ b/spec/system/admin/configuration/general_settings_spec.rb @@ -63,8 +63,6 @@ RSpec.describe "General Settings" do end end -private - def update_and_assert_message click_button 'Update' within("[class='flash success']") do diff --git a/spec/system/admin/configuration/shipping_categories_spec.rb b/spec/system/admin/configuration/shipping_categories_spec.rb index 3cd42e211b..6345e870e1 100644 --- a/spec/system/admin/configuration/shipping_categories_spec.rb +++ b/spec/system/admin/configuration/shipping_categories_spec.rb @@ -5,6 +5,7 @@ require 'system_helper' RSpec.describe "Shipping Categories" do include AuthenticationHelper include WebHelper + let(:admin_user) { create(:user) } context 'user visits shipping categories page' do diff --git a/spec/system/admin/multilingual_spec.rb b/spec/system/admin/multilingual_spec.rb index a4135bdfdd..0c54b97cb3 100644 --- a/spec/system/admin/multilingual_spec.rb +++ b/spec/system/admin/multilingual_spec.rb @@ -5,6 +5,7 @@ require 'system_helper' RSpec.describe 'Multilingual' do include AuthenticationHelper include WebHelper + let(:admin_user) { create(:admin_user) } before do diff --git a/spec/system/admin/order_cycles/complex_updating_specific_time_spec.rb b/spec/system/admin/order_cycles/complex_updating_specific_time_spec.rb index 4d109e5243..9f85f84326 100644 --- a/spec/system/admin/order_cycles/complex_updating_specific_time_spec.rb +++ b/spec/system/admin/order_cycles/complex_updating_specific_time_spec.rb @@ -165,8 +165,8 @@ RSpec.xdescribe ' # And it should have some variants selected selected_initial_variants = initial_variants.take initial_variants.size - 1 - expect(oc.variants.map(&:id)).to match_array((selected_initial_variants.map(&:id) + [v1.id, - v2.id])) + expect(oc.variants.map(&:id)).to match_array(selected_initial_variants.map(&:id) + [v1.id, + v2.id]) # And the collection details should have been updated expect(oc.exchanges.where(pickup_time: 'New time 0', diff --git a/spec/system/admin/products_v3/actions_spec.rb b/spec/system/admin/products_v3/actions_spec.rb index 9435ca128a..6ce798332a 100644 --- a/spec/system/admin/products_v3/actions_spec.rb +++ b/spec/system/admin/products_v3/actions_spec.rb @@ -306,7 +306,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do within "table.products" do # Products does not include the cloned product. - expect(all_input_values).not_to match /COPY OF #{('L' * 254)}/ + expect(all_input_values).not_to match /COPY OF #{'L' * 254}/ end end end diff --git a/spec/system/admin/reports/packing_report_spec.rb b/spec/system/admin/reports/packing_report_spec.rb index 686162e389..63e1fb684e 100644 --- a/spec/system/admin/reports/packing_report_spec.rb +++ b/spec/system/admin/reports/packing_report_spec.rb @@ -183,8 +183,6 @@ RSpec.describe "Packing Reports" do end end -private - def check_prefilled_dates expect(page).to have_input "q[order_completed_at_gt]", value: open_datetime, visible: false expect(page).to have_input "q[order_completed_at_lt]", value: close_datetime, visible: false diff --git a/spec/system/consumer/sitemap_spec.rb b/spec/system/consumer/sitemap_spec.rb index 255606c2ae..f8acb5d65d 100644 --- a/spec/system/consumer/sitemap_spec.rb +++ b/spec/system/consumer/sitemap_spec.rb @@ -13,8 +13,6 @@ RSpec.describe 'sitemap' do end end -private - def return_page(website) # routing does not include the port of the session, this method adds it url = URI(page.driver.browser.url) diff --git a/spec/validators/date_time_string_validator_spec.rb b/spec/validators/date_time_string_validator_spec.rb index 17539a42ab..f69301d252 100644 --- a/spec/validators/date_time_string_validator_spec.rb +++ b/spec/validators/date_time_string_validator_spec.rb @@ -17,6 +17,7 @@ RSpec.describe DateTimeStringValidator do let(:instance) do Class.new do include ActiveModel::Validations + attr_accessor :timestamp validates :timestamp, date_time_string: true diff --git a/spec/validators/integer_array_validator_spec.rb b/spec/validators/integer_array_validator_spec.rb index fc447f7df2..d2775a41f2 100644 --- a/spec/validators/integer_array_validator_spec.rb +++ b/spec/validators/integer_array_validator_spec.rb @@ -17,6 +17,7 @@ RSpec.describe IntegerArrayValidator do let(:instance) do Class.new do include ActiveModel::Validations + attr_accessor :ids validates :ids, integer_array: true diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb index 95ee8a0ab5..5b80c65b96 100644 --- a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb +++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb @@ -4,6 +4,7 @@ require "spec_helper" RSpec.describe "spree/admin/payment_methods/index.html.haml" do include AuthenticationHelper + helper Spree::Admin::NavigationHelper helper Spree::Admin::BaseHelper helper Spree::Core::Engine.routes.url_helpers diff --git a/spec/views/spree/shared/_order_details.html.haml_spec.rb b/spec/views/spree/shared/_order_details.html.haml_spec.rb index 3acc484f0e..fe2b49a19b 100644 --- a/spec/views/spree/shared/_order_details.html.haml_spec.rb +++ b/spec/views/spree/shared/_order_details.html.haml_spec.rb @@ -4,6 +4,7 @@ require "spec_helper" RSpec.describe "spree/shared/_order_details.html.haml" do include AuthenticationHelper + helper Spree::BaseHelper helper CheckoutHelper helper OrderHelper