diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ab09cda6d..44eff7c575 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,43 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp` -# using RuboCop version 1.57.1. +# using RuboCop version 1.57.2. # 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 safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'app/reflexes/white_label_reflex.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'app/models/spree/order.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'app/reflexes/white_label_reflex.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Width, AllowedPatterns. -Layout/IndentationWidth: - Exclude: - - 'app/models/spree/order.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. @@ -180,7 +148,7 @@ Metrics/AbcSize: - 'lib/tasks/enterprises.rake' - 'spec/services/order_checkout_restart_spec.rb' -# Offense count: 45 +# Offense count: 44 # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: @@ -605,7 +573,7 @@ Rails/RedundantActiveRecordAllMethod: - 'app/models/spree/variant.rb' - 'spec/system/admin/product_import_spec.rb' -# Offense count: 22 +# Offense count: 20 # This cop supports unsafe autocorrection (--autocorrect-all). Rails/RedundantPresenceValidationOnBelongsTo: Exclude: @@ -622,7 +590,6 @@ Rails/RedundantPresenceValidationOnBelongsTo: - 'app/models/spree/stock_item.rb' - 'app/models/spree/stock_movement.rb' - 'app/models/spree/tax_rate.rb' - - 'app/models/spree/variant.rb' - 'app/models/subscription_line_item.rb' - 'app/models/tag_rule.rb' - 'app/models/variant_override.rb' @@ -896,13 +863,6 @@ Style/MissingRespondToMissing: - 'app/models/spree/gateway.rb' - 'app/models/spree/preferences/configuration.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/NegatedIfElseCondition: - Exclude: - - 'app/mailers/spree/shipment_mailer.rb' - - 'spec/support/matchers/table_matchers.rb' - # Offense count: 22 # This cop supports safe autocorrection (--autocorrect). Style/NestedModifier: @@ -947,13 +907,6 @@ Style/OptionalBooleanParameter: - 'lib/spree/core/controller_helpers/order.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. -Style/ParenthesesAroundCondition: - Exclude: - - 'spec/system/support/precompile_assets.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. @@ -962,19 +915,6 @@ Style/PreferredHashMethods: Exclude: - 'app/controllers/api/v0/shipments_controller.rb' -# Offense count: 16 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: same_as_string_literals, single_quotes, double_quotes -Style/QuotedSymbols: - Exclude: - - 'app/services/exchange_products_renderer.rb' - - 'lib/stripe/credit_card_cloner.rb' - - 'spec/controllers/api/v0/exchange_products_controller_spec.rb' - - 'spec/requests/api/orders_spec.rb' - - 'spec/requests/api/v1/customers_spec.rb' - - 'spec/support/request/stripe_stubs.rb' - # Offense count: 3 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Methods. @@ -983,26 +923,6 @@ Style/RedundantArgument: - 'engines/dfc_provider/app/services/authorization_control.rb' - 'spec/support/query_counter.rb' -# Offense count: 13 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantConstantBase: - Exclude: - - 'app/controllers/split_checkout_controller.rb' - - 'app/controllers/webhook_endpoints_controller.rb' - - 'config.ru' - - 'spec/helpers/checkout_helper_spec.rb' - - 'spec/models/spree/order_spec.rb' - - 'spec/models/spree/payment_method_spec.rb' - - 'spec/models/spree/payment_spec.rb' - - 'spec/queries/complete_visible_orders_spec.rb' - - 'spec/services/paypal_items_builder_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantDoubleSplatHashBraces: - Exclude: - - 'spec/system/support/cuprite_setup.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowComments. diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 9bcd6a709e..36d17ddfe5 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -2,7 +2,7 @@ require 'open_food_network/address_finder' -class SplitCheckoutController < ::BaseController +class SplitCheckoutController < BaseController layout 'darkswarm' include OrderStockCheck diff --git a/app/controllers/webhook_endpoints_controller.rb b/app/controllers/webhook_endpoints_controller.rb index c9493f42bb..44580391de 100644 --- a/app/controllers/webhook_endpoints_controller.rb +++ b/app/controllers/webhook_endpoints_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class WebhookEndpointsController < ::BaseController +class WebhookEndpointsController < BaseController before_action :load_resource, only: :destroy def create diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb index cbe9bc62e6..0be7b55cca 100644 --- a/app/mailers/spree/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -12,7 +12,7 @@ module Spree private def base_subject - default_subject = !@delivery ? t('.picked_up_subject') : default_i18n_subject + default_subject = @delivery ? default_i18n_subject : t('.picked_up_subject') "#{@shipment.order.distributor.name} #{default_subject} ##{@shipment.order.number}" end end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index cd1d9c81f7..51851d032a 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -205,8 +205,9 @@ module Spree end def display_payment_total - Spree::Money.new(self.payment_total, currency:) + Spree::Money.new(self.payment_total, currency:) end + def to_param number.to_s.parameterize.upcase end diff --git a/app/reflexes/white_label_reflex.rb b/app/reflexes/white_label_reflex.rb index ac7fa4983b..32aa6618bc 100644 --- a/app/reflexes/white_label_reflex.rb +++ b/app/reflexes/white_label_reflex.rb @@ -12,7 +12,7 @@ class WhiteLabelReflex < ApplicationReflex f = ActionView::Helpers::FormBuilder.new(:enterprise, @enterprise, view_context, {}) html = render(partial: "admin/enterprises/form/white_label", - locals: { f:, enterprise: @enterprise }) + locals: { f:, enterprise: @enterprise }) morph "#white_label_panel", html flash[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success") diff --git a/app/services/exchange_products_renderer.rb b/app/services/exchange_products_renderer.rb index 66217cd2ec..c6cfceab22 100644 --- a/app/services/exchange_products_renderer.rb +++ b/app/services/exchange_products_renderer.rb @@ -47,7 +47,7 @@ class ExchangeProductsRenderer def products_for_outgoing_exchange supplied_products(enterprises_for_outgoing_exchange.select(:id)). includes(:variants). - where("spree_variants.id": incoming_exchanges_variants) + where('spree_variants.id': incoming_exchanges_variants) end def incoming_exchanges_variants diff --git a/config.ru b/config.ru index b834259514..c5850bfca6 100644 --- a/config.ru +++ b/config.ru @@ -2,5 +2,5 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('config/environment', __dir__) +require File.expand_path('config/environment', __dir__) run Openfoodnetwork::Application diff --git a/lib/stripe/credit_card_cloner.rb b/lib/stripe/credit_card_cloner.rb index 441efbe52a..465cc362b3 100644 --- a/lib/stripe/credit_card_cloner.rb +++ b/lib/stripe/credit_card_cloner.rb @@ -64,7 +64,7 @@ module Stripe def add_metadata_to_payment_method(payment_method_id) Stripe::PaymentMethod.update(payment_method_id, - { metadata: { "ofn-clone": true } }, + { metadata: { 'ofn-clone': true } }, stripe_account: @stripe_account) end end diff --git a/spec/controllers/api/v0/exchange_products_controller_spec.rb b/spec/controllers/api/v0/exchange_products_controller_spec.rb index 670d98902d..18c04f3825 100644 --- a/spec/controllers/api/v0/exchange_products_controller_spec.rb +++ b/spec/controllers/api/v0/exchange_products_controller_spec.rb @@ -56,7 +56,7 @@ module Api describe "pagination" do let(:exchange) { order_cycle.exchanges.outgoing.first } let(:products_relation) { - Spree::Product.includes(:variants).where("spree_variants.id": exchange.variants.map(&:id)) + Spree::Product.includes(:variants).where('spree_variants.id': exchange.variants.map(&:id)) } before do diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index f52b611d9b..9aae5df87a 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -165,7 +165,7 @@ describe CheckoutHelper, type: :helper do end context "tax rate adjustments" do - let!(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: ::Calculator::DefaultTax.new) } + let!(:tax_rate) { create(:tax_rate, amount: 0.1, calculator: Calculator::DefaultTax.new) } let!(:line_item_fee_adjustment) { create(:adjustment, originator: enterprise_fee, adjustable: order.line_items.first, order:) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index b2544ce910..030eb3704f 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -616,7 +616,7 @@ describe Spree::Order do describe "applying enterprise fees" do subject { create(:order) } - let(:fee_handler) { ::OrderFeesHandler.new(subject) } + let(:fee_handler) { OrderFeesHandler.new(subject) } before do allow(subject).to receive(:fee_handler) { fee_handler } diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index e3a72dcb28..634ed0d672 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -147,11 +147,11 @@ describe Spree::PaymentMethod do expect(free_payment_method.compute_amount(order)).to eq 0 flat_rate_payment_method = create(:payment_method, - calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) + calculator: Calculator::FlatRate.new(preferred_amount: 10)) expect(flat_rate_payment_method.compute_amount(order)).to eq 10 flat_percent_payment_method = create(:payment_method, - calculator: ::Calculator::FlatPercentItemTotal + calculator: Calculator::FlatPercentItemTotal .new(preferred_flat_percent: 10)) expect(flat_percent_payment_method.compute_amount(order)).to eq 0 diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 229af6342c..ff3edfce60 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -426,7 +426,7 @@ describe Spree::Payment do context "if payment has any adjustment" do let!(:order) { create(:order) } let!(:payment_method) { - create(:payment_method, calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) + create(:payment_method, calculator: Calculator::FlatRate.new(preferred_amount: 10)) } it "should create another adjustment and revoke the previous one" do @@ -999,7 +999,7 @@ describe Spree::Payment do let!(:shop) { create(:enterprise) } let!(:payment_method) { create(:payment_method, calculator:) } let!(:calculator) do - ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) + Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) end context "when order complete" do @@ -1036,7 +1036,7 @@ describe Spree::Payment do let(:payment) { create(:payment, order:, payment_method:, amount: order.total) } - let(:calculator) { ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) } + let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) } before do payment_method.calculator = calculator diff --git a/spec/queries/complete_visible_orders_spec.rb b/spec/queries/complete_visible_orders_spec.rb index 82f66093ff..2018674338 100644 --- a/spec/queries/complete_visible_orders_spec.rb +++ b/spec/queries/complete_visible_orders_spec.rb @@ -9,7 +9,7 @@ describe CompleteVisibleOrders do describe '#query' do let(:user) { create(:user) } let(:enterprise) { create(:enterprise) } - let(:order_permissions) { ::Permissions::Order.new(user, filter_canceled) } + let(:order_permissions) { Permissions::Order.new(user, filter_canceled) } before do user.enterprises << enterprise diff --git a/spec/requests/api/orders_spec.rb b/spec/requests/api/orders_spec.rb index 471b5a46e5..20ea82c530 100644 --- a/spec/requests/api/orders_spec.rb +++ b/spec/requests/api/orders_spec.rb @@ -32,7 +32,7 @@ describe 'api/v0/orders', swagger_doc: 'v0.yaml', type: :request do # Which would also validate the response in the test, this is an open # issue with rswag: https://github.com/rswag/rswag/issues/268 metadata[:response][:content] = { - "application/json": { + 'application/json': { schema: { '$ref' => '#/components/schemas/Order_Concise' } } } diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 002651861a..a4032d26af 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -36,7 +36,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "200", "Customers list" do param(:enterprise_id) { enterprise1.id } param("extra_fields[customer]") { :balance } - schema "$ref": "#/components/schemas/customers_collection" + schema '$ref': "#/components/schemas/customers_collection" run_test! end @@ -183,7 +183,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do enterprise_id: enterprise1.id.to_s } end - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! do expect(json_response[:data][:attributes]).to include( @@ -204,7 +204,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do enterprise_id: enterprise1.id, ) end - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! do expect(json_response[:data][:attributes]).to include( @@ -227,7 +227,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do allow_charges: true, } end - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "Parameters not allowed in this request: allow_charges" @@ -236,7 +236,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "422", "Unprocessable entity" do param(:customer) { {} } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "A required parameter is missing or empty: customer" @@ -271,7 +271,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "404", "Not found" do param(:id) { 0 } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "The resource you were looking for could not be found." @@ -283,7 +283,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "401", "Unauthorized" do param(:id) { customer1.id } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! do expect(json_error_detail).to eq "You are not authorized to perform that action." @@ -358,7 +358,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do enterprise_id: enterprise1.id.to_s } end - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! do # Tags should not be overridden when the param is missing: @@ -424,7 +424,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "422", "Unprocessable entity" do param(:id) { customer1.id } param(:customer) { {} } - schema "$ref": "#/components/schemas/error_response" + schema '$ref': "#/components/schemas/error_response" run_test! end @@ -437,7 +437,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "200", "Customer deleted" do param(:id) { customer1.id } - schema "$ref": "#/components/schemas/customer" + schema '$ref': "#/components/schemas/customer" run_test! end @@ -452,7 +452,7 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do response "200", "Customers list" do param(:enterprise_id) { enterprise1.id } - schema "$ref": "#/components/schemas/customers_collection" + schema '$ref': "#/components/schemas/customers_collection" run_test! end diff --git a/spec/services/paypal_items_builder_spec.rb b/spec/services/paypal_items_builder_spec.rb index c60b2bf8ac..227422b612 100644 --- a/spec/services/paypal_items_builder_spec.rb +++ b/spec/services/paypal_items_builder_spec.rb @@ -31,11 +31,11 @@ describe PaypalItemsBuilder do let!(:zone) { create(:zone_with_member) } let!(:included_tax_rate) { create(:tax_rate, amount: 12, included_in_price: true, zone:, - calculator: ::Calculator::DefaultTax.new) + calculator: Calculator::DefaultTax.new) } let!(:additional_tax_rate) { create(:tax_rate, amount: 34, included_in_price: false, zone:, - calculator: ::Calculator::DefaultTax.new) + calculator: Calculator::DefaultTax.new) } let!(:included_tax_adjustment) { create(:adjustment, label: "Included Tax Adjustment", order:, diff --git a/spec/support/matchers/table_matchers.rb b/spec/support/matchers/table_matchers.rb index 09b9f694ee..aaee09ed83 100644 --- a/spec/support/matchers/table_matchers.rb +++ b/spec/support/matchers/table_matchers.rb @@ -31,10 +31,7 @@ RSpec::Matchers.define :match_table do |expected_table| all("tr"). map { |r| r.all("th,td").map { |c| c.text.strip } } - if rows.count != expected_table.count - @failure_message = "found table with #{rows.count} rows, expected #{expected_table.count}" - - else + if rows.count == expected_table.count rows.each_with_index do |row, i| expected_row = expected_table[i] if row.count != expected_row.count @@ -52,6 +49,9 @@ RSpec::Matchers.define :match_table do |expected_table| break if @failure_message end end + else + @failure_message = "found table with #{rows.count} rows, expected #{expected_table.count}" + end @failure_message.nil? diff --git a/spec/support/request/stripe_stubs.rb b/spec/support/request/stripe_stubs.rb index b2943741ca..9a10c9830a 100644 --- a/spec/support/request/stripe_stubs.rb +++ b/spec/support/request/stripe_stubs.rb @@ -69,7 +69,7 @@ module StripeStubs def stub_add_metadata_request(payment_method: "pm_456", response: {}) stub = stub_request(:post, "https://api.stripe.com/v1/payment_methods/#{payment_method}") - stub = stub.with(body: { metadata: { "ofn-clone": true } }) + stub = stub.with(body: { metadata: { 'ofn-clone': true } }) stub = stub.with( headers: { 'Stripe-Account' => 'abc123' } ) diff --git a/spec/system/support/cuprite_setup.rb b/spec/system/support/cuprite_setup.rb index d3d5cd06c1..9d89e05634 100644 --- a/spec/system/support/cuprite_setup.rb +++ b/spec/system/support/cuprite_setup.rb @@ -10,17 +10,15 @@ browser_options["no-sandbox"] = nil if ENV['CI'] Capybara.register_driver(:cuprite_ofn) do |app| Capybara::Cuprite::Driver.new( app, - **{ - window_size: [1280, 800], - browser_options:, - process_timeout: 60, - timeout: 60, - # Don't load scripts from external sources, like google maps or stripe - url_whitelist: ["http://localhost", "http://0.0.0.0", "http://127.0.0.1"], - inspector: true, - headless:, - js_errors: true, - } + window_size: [1280, 800], + browser_options:, + process_timeout: 60, + timeout: 60, + # Don't load scripts from external sources, like google maps or stripe + url_whitelist: ["http://localhost", "http://0.0.0.0", "http://127.0.0.1"], + inspector: true, + headless:, + js_errors: true ) end diff --git a/spec/system/support/precompile_assets.rb b/spec/system/support/precompile_assets.rb index 2cf819cbf1..cb137f19e6 100644 --- a/spec/system/support/precompile_assets.rb +++ b/spec/system/support/precompile_assets.rb @@ -7,10 +7,9 @@ RSpec.configure do |config| # rspec --tag ~type:system # # In this case, we don't need to precompile assets. - next if ( + next if config.filter.opposite.rules[:type] == "system" || config.exclude_pattern.match?(%r{spec/system}) - ) config.before(:suite) do # We can use webpack-dev-server for tests, too!