Merge pull request #11786 from macanudo527/fix_autocorrect_rubocop

Fix Style Rubocop Errors
This commit is contained in:
Maikel
2023-11-13 10:25:03 +11:00
committed by GitHub
22 changed files with 50 additions and 132 deletions

View File

@@ -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.

View File

@@ -2,7 +2,7 @@
require 'open_food_network/address_finder'
class SplitCheckoutController < ::BaseController
class SplitCheckoutController < BaseController
layout 'darkswarm'
include OrderStockCheck

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
class WebhookEndpointsController < ::BaseController
class WebhookEndpointsController < BaseController
before_action :load_resource, only: :destroy
def create

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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:)

View File

@@ -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 }

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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' }
}
}

View File

@@ -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

View File

@@ -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:,

View File

@@ -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?

View File

@@ -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' }
)

View File

@@ -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

View File

@@ -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!