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