Merge pull request #11337 from macanudo527/fix_rubocop_6

Fix autocorrect Rails Cops 2
This commit is contained in:
Maikel
2023-08-17 10:39:34 +10:00
committed by GitHub
23 changed files with 59 additions and 104 deletions

View File

@@ -449,24 +449,6 @@ Rails/CompactBlank:
- 'lib/reporting/report_ruler.rb'
- 'lib/reporting/reports/enterprise_fee_summary/parameters.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Rails/ExpandedDateRange:
Exclude:
- 'app/models/spree/product.rb'
# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: slashes, arguments
Rails/FilePath:
Exclude:
- 'app/models/product_import/product_importer.rb'
- 'lib/tasks/karma.rake'
- 'spec/base_spec_helper.rb'
- 'spec/models/content_configuration_spec.rb'
- 'spec/support/downloads_helper.rb'
# Offense count: 8
# Configuration parameters: Include.
# Include: app/models/**/*.rb
@@ -520,14 +502,6 @@ Rails/HelperInstanceVariable:
- 'app/helpers/spree/admin/orders_helper.rb'
- 'app/helpers/spree/orders_helper.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: app/controllers/**/*.rb
Rails/I18nLazyLookup:
Exclude:
- 'app/controllers/admin/proxy_orders_controller.rb'
# Offense count: 8
# Configuration parameters: Include.
# Include: spec/**/*.rb, test/**/*.rb
@@ -671,6 +645,7 @@ 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'
@@ -701,30 +676,14 @@ Rails/ResponseParsedBody:
- 'spec/controllers/spree/credit_cards_controller_spec.rb'
- 'spec/controllers/user_registrations_controller_spec.rb'
# Offense count: 4
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RootPathnameMethods:
Exclude:
- 'spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb'
- 'spec/models/content_configuration_spec.rb'
- 'spec/models/terms_of_service_file_spec.rb'
- 'spec/system/admin/configuration/terms_of_service_files_spec.rb'
# Offense count: 13
# This cop supports safe autocorrection (--autocorrect).
Rails/RootPublicPath:
Exclude:
- 'app/controllers/concerns/request_timeouts.rb'
- 'lib/spree/core/controller_helpers/common.rb'
- 'spec/controllers/api/v0/product_images_controller_spec.rb'
- 'spec/controllers/api/v0/terms_and_conditions_controller_spec.rb'
- 'spec/models/terms_of_service_file_spec.rb'
- 'spec/system/admin/bulk_product_update_spec.rb'
- 'spec/system/admin/enterprises/terms_and_conditions_spec.rb'
- 'spec/system/consumer/shopping/checkout_spec.rb'
- 'spec/system/consumer/shopping/embedded_groups_spec.rb'
- 'spec/system/consumer/split_checkout_spec.rb'
# Offense count: 4
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
@@ -741,16 +700,6 @@ Rails/SquishedSQLHeredocs:
- 'app/queries/outstanding_balance.rb'
- 'spec/queries/outstanding_balance_spec.rb'
# Offense count: 24
# This cop supports safe autocorrection (--autocorrect).
Rails/StripHeredoc:
Exclude:
- 'app/models/content_configuration.rb'
- 'app/queries/customers_with_balance.rb'
- 'app/queries/outstanding_balance.rb'
- 'lib/reporting/reports/enterprise_fee_summary/scope.rb'
- 'lib/tasks/data/truncate_data.rake'
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
@@ -1530,14 +1479,13 @@ Style/RedundantArgument:
- 'engines/dfc_provider/app/services/authorization_control.rb'
- 'spec/support/query_counter.rb'
# Offense count: 14
# 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/base_spec_helper.rb'
- 'spec/helpers/checkout_helper_spec.rb'
- 'spec/models/spree/order_spec.rb'
- 'spec/models/spree/payment_method_spec.rb'
@@ -1558,6 +1506,13 @@ Style/RedundantInitialize:
Exclude:
- 'spec/models/spree/gateway_spec.rb'
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/RedundantInterpolation:
Exclude:
- 'lib/tasks/karma.rake'
- 'spec/base_spec_helper.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpArgument:

View File

@@ -13,7 +13,7 @@ module Admin
if @proxy_order.cancel
render_as_json @proxy_order
else
render json: { errors: [t('admin.proxy_orders.cancel.could_not_cancel_the_order')] },
render json: { errors: [t('.could_not_cancel_the_order')] },
status: :unprocessable_entity
end
end
@@ -22,7 +22,7 @@ module Admin
if @proxy_order.resume
render_as_json @proxy_order
else
render json: { errors: [t('admin.proxy_orders.resume.could_not_resume_the_order')] },
render json: { errors: [t('.could_not_resume_the_order')] },
status: :unprocessable_entity
end
end

View File

@@ -16,7 +16,7 @@ module RequestTimeouts
respond_to do |type|
type.html {
render status: :gateway_timeout,
file: Rails.root.join("public/500.html"),
file: Rails.public_path.join('500.html'),
formats: [:html],
layout: nil
}

View File

@@ -71,7 +71,7 @@ class ContentConfiguration < Spree::Preferences::Configuration
preference :footer_pinterest_url, :string, default: ""
preference :footer_email, :string, default: "hello@openfoodnetwork.org"
preference :community_forum_url, :string, default: "http://community.openfoodnetwork.org"
preference :footer_links_md, :text, default: <<-EOS.strip_heredoc
preference :footer_links_md, :text, default: <<~EOS
[Newsletter sign-up](/)
[News](/)

View File

@@ -287,7 +287,7 @@ module ProductImport
end
def delete_uploaded_file
return unless @file.path == Rails.root.join('tmp', 'product_import').to_s
return unless @file.path == Rails.root.join("tmp/product_import").to_s
File.delete(@file)
end

View File

@@ -104,7 +104,7 @@ module Spree
import_date = Time.zone.parse import_date if import_date.is_a? String
import_date = import_date.to_date
joins(:variants).merge(Spree::Variant.
where(import_date: import_date.beginning_of_day..import_date.end_of_day))
where(import_date: import_date.all_day))
}
scope :with_order_cycles_inner, -> {

View File

@@ -20,7 +20,7 @@ class CustomersWithBalance
# The resulting orders are in states that belong after the checkout. Only these can be considered
# for a customer's balance.
def left_join_complete_orders
<<-SQL.strip_heredoc
<<~SQL
LEFT JOIN spree_orders ON spree_orders.customer_id = customers.id
AND #{finalized_states.to_sql}
SQL

View File

@@ -29,7 +29,7 @@ class OutstandingBalance
# Arel doesn't support CASE statements until v7.1.0 so we'll have to wait with SQL literals
# a little longer. See https://github.com/rails/arel/pull/400 for details.
def statement
<<-SQL.strip_heredoc
<<~SQL
CASE WHEN "spree_orders"."state" IN #{non_fulfilled_states_group.to_sql} THEN "spree_orders"."payment_total"
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
ELSE 0 END

View File

@@ -68,7 +68,7 @@ module Reporting
def include_adjustment_metadata
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN adjustment_metadata
ON (adjustment_metadata.adjustment_id = spree_adjustments.id)
JOIN_STRING
@@ -81,7 +81,7 @@ module Reporting
# * Hub
def include_order_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_orders
ON (
spree_orders.id = spree_adjustments.order_id
@@ -93,7 +93,7 @@ module Reporting
join_scope("LEFT OUTER JOIN customers ON (customers.id = spree_orders.customer_id)")
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS hubs
ON (hubs.id = spree_orders.distributor_id)
JOIN_STRING
@@ -106,7 +106,7 @@ module Reporting
# * Payment method
def include_payment_fee_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_payment_methods
ON (
spree_adjustments.originator_type = 'Spree::PaymentMethod'
@@ -116,7 +116,7 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS payment_hubs
ON (
spree_payment_methods.id IS NOT NULL
@@ -132,7 +132,7 @@ module Reporting
# * Shipping method
def include_shipping_fee_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_shipping_methods
ON (
spree_adjustments.originator_type = 'Spree::ShippingMethod'
@@ -148,7 +148,7 @@ module Reporting
# * Enterprise fee tax category
def include_enterprise_fee_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprise_fees
ON (
spree_adjustments.originator_type = 'EnterpriseFee'
@@ -158,14 +158,14 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises
ON (enterprises.id = enterprise_fees.enterprise_id)
JOIN_STRING
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_tax_categories
ON (spree_tax_categories.id = enterprise_fees.tax_category_id)
JOIN_STRING
@@ -179,7 +179,7 @@ module Reporting
# * Distributor
def include_order_source_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_orders AS adjustment_source_orders
ON (
spree_adjustments.adjustable_type = 'Spree::Order'
@@ -189,7 +189,7 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS adjustment_source_distributors
ON (adjustment_source_distributors.id = adjustment_source_orders.distributor_id)
JOIN_STRING
@@ -205,7 +205,7 @@ module Reporting
# * Tax category of product, if enterprise fee tells to inherit
def include_line_item_source_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_line_items
ON (
spree_adjustments.adjustable_type = 'Spree::LineItem'
@@ -215,7 +215,7 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_variants
ON (
spree_adjustments.adjustable_type = 'Spree::LineItem'
@@ -225,14 +225,14 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_products
ON (spree_products.id = spree_variants.product_id)
JOIN_STRING
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN spree_tax_categories AS product_tax_categories
ON (
enterprise_fees.inherits_tax_category IS TRUE
@@ -250,7 +250,7 @@ module Reporting
# * Incoming exchange variant
def include_incoming_exchange_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN
(
exchange_variants AS incoming_exchange_variants
@@ -271,7 +271,7 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS incoming_exchange_enterprises
ON (incoming_exchange_enterprises.id = incoming_exchanges.sender_id)
JOIN_STRING
@@ -286,7 +286,7 @@ module Reporting
# * Outgoing exchange variant
def include_outgoing_exchange_details
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN
(
exchange_variants AS outgoing_exchange_variants
@@ -307,7 +307,7 @@ module Reporting
)
join_scope(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
LEFT OUTER JOIN enterprises AS outgoing_exchange_enterprises
ON (outgoing_exchange_enterprises.id = outgoing_exchanges.receiver_id)
JOIN_STRING
@@ -366,7 +366,7 @@ module Reporting
def select_attributes
chain_to_scope do
select(
<<-JOIN_STRING.strip_heredoc
<<~JOIN_STRING
SUM(spree_adjustments.amount) AS total_amount,
spree_payment_methods.name AS payment_method_name,
spree_shipping_methods.name AS shipping_method_name,

View File

@@ -42,7 +42,7 @@ module Spree
respond_to do |type|
type.html {
render status: :not_found,
file: Rails.root.join("public/404.html"),
file: Rails.public_path.join('404.html'),
formats: [:html],
layout: nil
}

View File

@@ -32,11 +32,11 @@ namespace :ofn do
end
def warn_with_confirmation
message = <<-MSG.strip_heredoc
\n
<% highlighted_message = "This will permanently change DB contents. This is not meant to be run in production as it needs more thorough testing." %>
<%= color(highlighted_message, :blink, :on_red) %>
Are you sure you want to proceed? (y/N)
message = <<~MSG
\n
<% highlighted_message = "This will permanently change DB contents. This is not meant to be run in production as it needs more thorough testing." %>
<%= color(highlighted_message, :blink, :on_red) %>
Are you sure you want to proceed? (y/N)
MSG
exit unless HighLine.new.agree(message) { |question| question.default = "N" }

View File

@@ -39,6 +39,6 @@ namespace :karma do
I18n::JS::DEFAULT_EXPORT_DIR_PATH.replace('tmp/javascripts')
I18n::JS.export
"#{Rails.root.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH)}/translations.js"
"#{Rails.root.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH, 'translations.js')}"
end
end

View File

@@ -55,7 +55,7 @@ FactoryBot::SyntaxRunner.include FileHelper
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.fixture_path = "#{Rails.root.join('spec/fixtures')}"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false

View File

@@ -10,7 +10,7 @@ describe Api::V0::ProductImagesController, type: :controller do
describe "uploading an image" do
let(:image) { Rack::Test::UploadedFile.new(black_logo_file, 'image/png') }
let(:pdf) { Rack::Test::UploadedFile.new(pdf_path, 'application/pdf') }
let(:pdf_path) { Rails.root.join("public/Terms-of-service.pdf") }
let(:pdf_path) { Rails.public_path.join('Terms-of-service.pdf') }
let(:product_without_image) { create(:product) }
let(:product_with_image) { create(:product_with_image) }
let(:current_api_user) { create(:admin_user) }

View File

@@ -12,7 +12,7 @@ module Api
let(:enterprise_manager) { create(:user, enterprises: [enterprise]) }
describe "removing terms and conditions file" do
let(:terms_file_path) { Rails.root.join("public/Terms-of-service.pdf") }
let(:terms_file_path) { Rails.public_path.join('Terms-of-service.pdf') }
let(:terms_and_conditions_file) {
Rack::Test::UploadedFile.new(terms_file_path, "application/pdf")
}

View File

@@ -12,7 +12,7 @@ describe ContentConfiguration do
end
def image_exist?(default_url)
File.exist?(File.join(Rails.root, 'public', default_url))
Rails.public_path.join(*default_url.split("/")).exist?
end
end
end

View File

@@ -3,7 +3,7 @@
require 'spec_helper'
describe TermsOfServiceFile do
let(:pdf) { File.open(Rails.root.join("public/Terms-of-service.pdf")) }
let(:pdf) { File.open(Rails.public_path.join('Terms-of-service.pdf')) }
let(:upload) { Rack::Test::UploadedFile.new(pdf, "application/pdf") }
describe ".current" do

View File

@@ -4,7 +4,7 @@ module DownloadsHelper
TIMEOUT = 10
def self.path
Rails.root.join("tmp", "capybara")
Rails.root.join("tmp/capybara")
end
def downloaded_filename

View File

@@ -904,7 +904,7 @@ describe '
expect(page).to have_css "img.preview"
# Upload a new image file
attach_file 'image-upload', Rails.root.join("public/500.jpg"), visible: false
attach_file 'image-upload', Rails.public_path.join('500.jpg'), visible: false
# Shows spinner whilst loading
expect(page).to have_css ".spinner"

View File

@@ -24,8 +24,8 @@ describe "Uploading Terms and Conditions PDF" do
end
end
let(:original_terms) { Rails.root.join("public/Terms-of-service.pdf") }
let(:updated_terms) { Rails.root.join("public/Terms-of-ServiceUK.pdf") }
let(:original_terms) { Rails.public_path.join('Terms-of-service.pdf') }
let(:updated_terms) { Rails.public_path.join('Terms-of-ServiceUK.pdf') }
it "uploading terms and conditions" do
go_to_business_details

View File

@@ -91,7 +91,7 @@ describe "As a consumer I want to check out my cart" do
let(:user) { create(:user) }
let(:pdf_upload) {
Rack::Test::UploadedFile.new(
Rails.root.join("public/Terms-of-service.pdf"),
Rails.public_path.join('Terms-of-service.pdf'),
"application/pdf"
)
}

View File

@@ -15,7 +15,7 @@ describe "Using embedded shopfront functionality" do
FileUtils.copy(
Rails.root.join("spec/fixtures/files/embedded-group-preview.html"),
Rails.root.join("public/embedded-group-preview.html")
Rails.public_path.join('embedded-group-preview.html')
)
visit "/embedded-group-preview.html?#{group.permalink}"
@@ -23,7 +23,7 @@ describe "Using embedded shopfront functionality" do
after do
FileUtils.remove(
Rails.root.join("public/embedded-group-preview.html")
Rails.public_path.join('embedded-group-preview.html')
)
end

View File

@@ -993,8 +993,8 @@ describe "As a consumer, I want to checkout my order" do
describe "terms and conditions" do
let(:customer) { create(:customer, enterprise: order.distributor, user: user) }
let(:tos_url) { "https://example.org/tos" }
let(:system_terms_path) { Rails.root.join("public/Terms-of-service.pdf") }
let(:shop_terms_path) { Rails.root.join("public/Terms-of-ServiceUK.pdf") }
let(:system_terms_path) { Rails.public_path.join('Terms-of-service.pdf') }
let(:shop_terms_path) { Rails.public_path.join('Terms-of-ServiceUK.pdf') }
let(:system_terms) {
Rack::Test::UploadedFile.new(system_terms_path, "application/pdf")
}