From c36728625d1004f47db8adc2a6bdac27aacf286e Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 4 Aug 2023 11:09:15 +0900 Subject: [PATCH 1/6] Regenerate Rubocop's TODO file --- .rubocop_todo.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9d221c9130..e9aef9b5d4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -671,6 +671,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' From aaf218176856d271632c5f4dbb00eb9f282059d0 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 4 Aug 2023 11:12:27 +0900 Subject: [PATCH 2/6] Safely autocorrect Rails/FilePath Inspecting 1484 files .............................................................................................................................................................................................................................................................................................................C.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C....................C.....................................................................................................................................................................................................................................................................C.........................................................................................................................................................................................................C........................................................................................................................................................... Offenses: app/models/product_import/product_importer.rb:290:35: C: [Corrected] Rails/FilePath: Prefer Rails.root.join('path/to'). return unless @file.path == Rails.root.join('tmp', 'product_import').to_s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/tasks/karma.rake:42:5: C: [Corrected] Rails/FilePath: Prefer Rails.root.join('path/to'). "#{Rails.root.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH)}/translations.js" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/tasks/karma.rake:42:5: C: [Correctable] Style/RedundantInterpolation: Prefer to_s over string interpolation. "#{Rails.root.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH, 'translations.js')}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/tasks/karma.rake:42:59: C: [Corrected] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations. "#{Rails.root.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH, "translations.js")}" ^^^^^^^^^^^^^^^^^ spec/base_spec_helper.rb:58:25: C: [Corrected] Rails/FilePath: Prefer Rails.root.join('path/to'). config.fixture_path = "#{::Rails.root}/spec/fixtures" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/base_spec_helper.rb:58:25: C: [Correctable] Style/RedundantInterpolation: Prefer to_s over string interpolation. config.fixture_path = "#{Rails.root.join('spec/fixtures')}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/base_spec_helper.rb:58:44: C: [Corrected] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations. config.fixture_path = "#{Rails.root.join("spec/fixtures")}" ^^^^^^^^^^^^^^^ spec/models/content_configuration_spec.rb:15:19: C: [Corrected] Rails/FilePath: Prefer Rails.root.join('path/to').to_s. File.exist?(File.join(Rails.root, 'public', default_url)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/models/content_configuration_spec.rb:15:19: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. File.exist?(Rails.root.join('public', default_url).to_s) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/support/downloads_helper.rb:7:5: C: [Corrected] Rails/FilePath: Prefer Rails.root.join('path/to'). Rails.root.join("tmp", "capybara") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1484 files inspected, 10 offenses detected, 8 offenses corrected, 2 more offenses can be corrected with `rubocop -A` --- .rubocop_todo.yml | 18 ------------------ app/models/product_import/product_importer.rb | 2 +- app/models/spree/product.rb | 2 +- lib/tasks/karma.rake | 2 +- spec/base_spec_helper.rb | 2 +- spec/models/content_configuration_spec.rb | 2 +- spec/support/downloads_helper.rb | 2 +- 7 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e9aef9b5d4..73b9590db4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index 7d0758333d..4f7401cf7d 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -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 diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 68437005e8..2b66b5f8c2 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -105,7 +105,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, -> { diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake index fe90a8d04f..2044fd04ef 100644 --- a/lib/tasks/karma.rake +++ b/lib/tasks/karma.rake @@ -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 diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 640496648f..d9c57191d1 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -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 diff --git a/spec/models/content_configuration_spec.rb b/spec/models/content_configuration_spec.rb index 141d4111cf..2446ffdefd 100644 --- a/spec/models/content_configuration_spec.rb +++ b/spec/models/content_configuration_spec.rb @@ -12,7 +12,7 @@ describe ContentConfiguration do end def image_exist?(default_url) - File.exist?(File.join(Rails.root, 'public', default_url)) + File.exist?(Rails.public_path.join(default_url).to_s) end end end diff --git a/spec/support/downloads_helper.rb b/spec/support/downloads_helper.rb index 2a6bc73b0c..d17f657e0d 100644 --- a/spec/support/downloads_helper.rb +++ b/spec/support/downloads_helper.rb @@ -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 From b60fd6b572498a02bb0a803e57a7f753cf68331a Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 4 Aug 2023 11:14:06 +0900 Subject: [PATCH 3/6] Safely autocorrect Rails/I18nLazyLookup Inspecting 1484 files .......................................C.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: app/controllers/admin/proxy_orders_controller.rb:16:35: C: [Corrected] Rails/I18nLazyLookup: Use "lazy" lookup for the text used in controllers. render json: { errors: [t('admin.proxy_orders.cancel.could_not_cancel_the_order')] }, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/controllers/admin/proxy_orders_controller.rb:25:35: C: [Corrected] Rails/I18nLazyLookup: Use "lazy" lookup for the text used in controllers. render json: { errors: [t('admin.proxy_orders.resume.could_not_resume_the_order')] }, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1484 files inspected, 2 offenses detected, 2 offenses corrected --- .rubocop_todo.yml | 21 ++++++++----------- .../admin/proxy_orders_controller.rb | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 73b9590db4..f916454c64 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -502,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 @@ -684,12 +676,11 @@ 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' @@ -1513,14 +1504,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' @@ -1541,6 +1531,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: diff --git a/app/controllers/admin/proxy_orders_controller.rb b/app/controllers/admin/proxy_orders_controller.rb index fbe51e5069..a5ee2b1c79 100644 --- a/app/controllers/admin/proxy_orders_controller.rb +++ b/app/controllers/admin/proxy_orders_controller.rb @@ -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 From 94f1b89a9f60720302ebb265df1e49518873d997 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 4 Aug 2023 11:15:45 +0900 Subject: [PATCH 4/6] Safely autocorrect Rails/RootPublicPath Inspecting 1484 files .............................................................................................C........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.........................................................................................C..........C..........................................................................................................................................................................................................................................................................................................C....................................................................................................................................................................C...................C.............................................................C.C.......C.................... Offenses: app/controllers/concerns/request_timeouts.rb:19:22: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. file: Rails.root.join("public/500.html"), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/spree/core/controller_helpers/common.rb:45:30: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. file: Rails.root.join("public/404.html"), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/controllers/api/v0/product_images_controller_spec.rb:13:22: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:pdf_path) { Rails.root.join("public/Terms-of-service.pdf") } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/controllers/api/v0/terms_and_conditions_controller_spec.rb:15:31: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:terms_file_path) { Rails.root.join("public/Terms-of-service.pdf") } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/models/terms_of_service_file_spec.rb:6:25: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:pdf) { File.open(Rails.root.join("public/Terms-of-service.pdf")) } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/admin/bulk_product_update_spec.rb:907:37: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. attach_file 'image-upload', Rails.root.join("public/500.jpg"), visible: false ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/admin/enterprises/terms_and_conditions_spec.rb:27:30: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:original_terms) { Rails.root.join("public/Terms-of-service.pdf") } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/admin/enterprises/terms_and_conditions_spec.rb:28:29: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:updated_terms) { Rails.root.join("public/Terms-of-ServiceUK.pdf") } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/consumer/shopping/checkout_spec.rb:94:9: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. Rails.root.join("public/Terms-of-service.pdf"), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/consumer/shopping/embedded_groups_spec.rb:18:9: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. Rails.root.join("public/embedded-group-preview.html") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/consumer/shopping/embedded_groups_spec.rb:26:9: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. Rails.root.join("public/embedded-group-preview.html") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/consumer/split_checkout_spec.rb:986:35: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:system_terms_path) { Rails.root.join("public/Terms-of-service.pdf") } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ spec/system/consumer/split_checkout_spec.rb:987:33: C: [Corrected] Rails/RootPublicPath: Use Rails.public_path. let(:shop_terms_path) { Rails.root.join("public/Terms-of-ServiceUK.pdf") } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1484 files inspected, 13 offenses detected, 13 offenses corrected --- .rubocop_todo.yml | 15 --------------- app/controllers/concerns/request_timeouts.rb | 2 +- lib/spree/core/controller_helpers/common.rb | 2 +- .../api/v0/product_images_controller_spec.rb | 2 +- .../v0/terms_and_conditions_controller_spec.rb | 2 +- spec/models/terms_of_service_file_spec.rb | 2 +- spec/system/admin/bulk_product_update_spec.rb | 2 +- .../enterprises/terms_and_conditions_spec.rb | 4 ++-- spec/system/consumer/shopping/checkout_spec.rb | 2 +- .../consumer/shopping/embedded_groups_spec.rb | 4 ++-- spec/system/consumer/split_checkout_spec.rb | 4 ++-- 11 files changed, 13 insertions(+), 28 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f916454c64..9b7d277981 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -684,21 +684,6 @@ Rails/RootPathnameMethods: - '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 diff --git a/app/controllers/concerns/request_timeouts.rb b/app/controllers/concerns/request_timeouts.rb index 691cba2a3d..8e2705213a 100644 --- a/app/controllers/concerns/request_timeouts.rb +++ b/app/controllers/concerns/request_timeouts.rb @@ -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 } diff --git a/lib/spree/core/controller_helpers/common.rb b/lib/spree/core/controller_helpers/common.rb index 28090659b6..8f0da80bc7 100644 --- a/lib/spree/core/controller_helpers/common.rb +++ b/lib/spree/core/controller_helpers/common.rb @@ -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 } diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb index 1e2ffee08c..464e9025cc 100644 --- a/spec/controllers/api/v0/product_images_controller_spec.rb +++ b/spec/controllers/api/v0/product_images_controller_spec.rb @@ -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) } diff --git a/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb b/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb index 142697c88a..89d0b6fc08 100644 --- a/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb +++ b/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb @@ -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") } diff --git a/spec/models/terms_of_service_file_spec.rb b/spec/models/terms_of_service_file_spec.rb index 74a28697a9..ca30c64546 100644 --- a/spec/models/terms_of_service_file_spec.rb +++ b/spec/models/terms_of_service_file_spec.rb @@ -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 diff --git a/spec/system/admin/bulk_product_update_spec.rb b/spec/system/admin/bulk_product_update_spec.rb index a2876661e7..cb1c80e281 100644 --- a/spec/system/admin/bulk_product_update_spec.rb +++ b/spec/system/admin/bulk_product_update_spec.rb @@ -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" diff --git a/spec/system/admin/enterprises/terms_and_conditions_spec.rb b/spec/system/admin/enterprises/terms_and_conditions_spec.rb index 7599259688..9b8eace1f2 100644 --- a/spec/system/admin/enterprises/terms_and_conditions_spec.rb +++ b/spec/system/admin/enterprises/terms_and_conditions_spec.rb @@ -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 diff --git a/spec/system/consumer/shopping/checkout_spec.rb b/spec/system/consumer/shopping/checkout_spec.rb index 484d1766cb..59106028e0 100644 --- a/spec/system/consumer/shopping/checkout_spec.rb +++ b/spec/system/consumer/shopping/checkout_spec.rb @@ -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" ) } diff --git a/spec/system/consumer/shopping/embedded_groups_spec.rb b/spec/system/consumer/shopping/embedded_groups_spec.rb index 7927129fca..4b3db6ea9c 100644 --- a/spec/system/consumer/shopping/embedded_groups_spec.rb +++ b/spec/system/consumer/shopping/embedded_groups_spec.rb @@ -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 diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index e2f962a13f..d648476e20 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -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") } From e5740a82bdd7bb1cc10b49f0975f211b29f5d7b2 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 4 Aug 2023 11:21:54 +0900 Subject: [PATCH 5/6] Safely autocorrect Rails/StripHeredoc Inspecting 1484 files ........................................................................................................................................................................................................................................................C.........................................................................................................................................CC...........................................................................................................................................................................................................................................................................................................................................................................................C.......................................................................C.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: app/models/content_configuration.rb:74:48: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. preference :footer_links_md, :text, default: <<-EOS.strip_heredoc ^^^^^^^^^^^^^^^^^^^^ app/queries/customers_with_balance.rb:23:5: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-SQL.strip_heredoc ^^^^^^^^^^^^^^^^^^^^ app/queries/outstanding_balance.rb:32:5: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-SQL.strip_heredoc ^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:71:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:84:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:96:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:109:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:119:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:135:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:151:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:161:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:168:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:182:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:192:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:208:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:218:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:228:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:235:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:253:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:274:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:289:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:310:13: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/reporting/reports/enterprise_fee_summary/scope.rb:369:15: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. <<-JOIN_STRING.strip_heredoc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/tasks/data/truncate_data.rake:35:17: C: [Corrected] Rails/StripHeredoc: Use squiggly heredoc (<<~) instead of strip_heredoc. message = <<-MSG.strip_heredoc ^^^^^^^^^^^^^^^^^^^^ lib/tasks/data/truncate_data.rake:36:1: C: [Corrected] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. \n ... ^^^^^^^^ 1484 files inspected, 25 offenses detected, 25 offenses corrected --- .rubocop_todo.yml | 10 ----- app/models/content_configuration.rb | 2 +- app/queries/customers_with_balance.rb | 2 +- app/queries/outstanding_balance.rb | 2 +- .../reports/enterprise_fee_summary/scope.rb | 40 +++++++++---------- lib/tasks/data/truncate_data.rake | 10 ++--- 6 files changed, 28 insertions(+), 38 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9b7d277981..5030b82a9a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -700,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. diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 2d473db24f..9276e97a4c 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -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](/) diff --git a/app/queries/customers_with_balance.rb b/app/queries/customers_with_balance.rb index 553ca88cec..623190ff4c 100644 --- a/app/queries/customers_with_balance.rb +++ b/app/queries/customers_with_balance.rb @@ -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 diff --git a/app/queries/outstanding_balance.rb b/app/queries/outstanding_balance.rb index 5f4b5b921f..637451b25c 100644 --- a/app/queries/outstanding_balance.rb +++ b/app/queries/outstanding_balance.rb @@ -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 diff --git a/lib/reporting/reports/enterprise_fee_summary/scope.rb b/lib/reporting/reports/enterprise_fee_summary/scope.rb index 3a57ea027c..7b6ed51425 100644 --- a/lib/reporting/reports/enterprise_fee_summary/scope.rb +++ b/lib/reporting/reports/enterprise_fee_summary/scope.rb @@ -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, diff --git a/lib/tasks/data/truncate_data.rake b/lib/tasks/data/truncate_data.rake index 65075a3ffb..b422d04980 100644 --- a/lib/tasks/data/truncate_data.rake +++ b/lib/tasks/data/truncate_data.rake @@ -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" } From ec490657391456bec794051258088f67dcb3905f Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Mon, 7 Aug 2023 22:54:04 +0900 Subject: [PATCH 6/6] Reword image_exists? to use Rails.public_path --- spec/models/content_configuration_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/content_configuration_spec.rb b/spec/models/content_configuration_spec.rb index 2446ffdefd..07f8bcc18d 100644 --- a/spec/models/content_configuration_spec.rb +++ b/spec/models/content_configuration_spec.rb @@ -12,7 +12,7 @@ describe ContentConfiguration do end def image_exist?(default_url) - File.exist?(Rails.public_path.join(default_url).to_s) + Rails.public_path.join(*default_url.split("/")).exist? end end end