From 6327f46733f38994209689b1809a307ebb91ea3f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Nov 2023 12:20:51 +1100 Subject: [PATCH] Use fixture_file_upload helper where possible We can't use it in factories but in other places it's a nice shortcut. --- spec/controllers/api/v0/product_images_controller_spec.rb | 2 +- .../api/v0/terms_and_conditions_controller_spec.rb | 2 +- spec/models/terms_of_service_file_spec.rb | 2 +- spec/support/api_helper.rb | 2 +- spec/system/admin/tos_banner_spec.rb | 2 +- spec/system/consumer/checkout/summary_spec.rb | 4 ++-- spec/system/consumer/shopping/checkout_spec.rb | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb index a85db7771c..a19ef98c00 100644 --- a/spec/controllers/api/v0/product_images_controller_spec.rb +++ b/spec/controllers/api/v0/product_images_controller_spec.rb @@ -9,7 +9,7 @@ describe Api::V0::ProductImagesController, type: :controller do describe "uploading an image" do let(:image) { black_logo_file } - let(:pdf) { Rack::Test::UploadedFile.new(pdf_path, 'application/pdf') } + let(:pdf) { fixture_file_upload(pdf_path, 'application/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) } 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 89d0b6fc08..ed8978cd7f 100644 --- a/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb +++ b/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb @@ -14,7 +14,7 @@ module Api describe "removing terms and conditions file" do 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") + fixture_file_upload(terms_file_path, "application/pdf") } let(:enterprise) { create(:enterprise, owner: enterprise_owner) } diff --git a/spec/models/terms_of_service_file_spec.rb b/spec/models/terms_of_service_file_spec.rb index 21718a0e9b..d702a66365 100644 --- a/spec/models/terms_of_service_file_spec.rb +++ b/spec/models/terms_of_service_file_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe TermsOfServiceFile do let(:pdf) { File.open(Rails.public_path.join('Terms-of-service.pdf')) } - let(:upload) { Rack::Test::UploadedFile.new(pdf, "application/pdf") } + let(:upload) { fixture_file_upload(pdf, "application/pdf") } describe ".current" do it "returns nil" do diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index 7632c90c86..a0f8e10105 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -28,7 +28,7 @@ module OpenFoodNetwork end def image(filename) - Rack::Test::UploadedFile.new(Rails.root + "spec/support/fixtures" + filename) + fixture_file_upload(Rails.root + "spec/support/fixtures" + filename) end end end diff --git a/spec/system/admin/tos_banner_spec.rb b/spec/system/admin/tos_banner_spec.rb index 48808896f3..853c18384a 100644 --- a/spec/system/admin/tos_banner_spec.rb +++ b/spec/system/admin/tos_banner_spec.rb @@ -8,7 +8,7 @@ describe 'Terms of Service banner' do let(:admin_user) { create(:admin_user, terms_of_service_accepted_at: nil) } let(:test_file) { "Terms-of-service.pdf" } let(:pdf_upload) do - Rack::Test::UploadedFile.new(Rails.public_path.join(test_file), "application/pdf") + fixture_file_upload(Rails.public_path.join(test_file), "application/pdf") end before do diff --git a/spec/system/consumer/checkout/summary_spec.rb b/spec/system/consumer/checkout/summary_spec.rb index 2f2767d7dd..408acbbbfb 100644 --- a/spec/system/consumer/checkout/summary_spec.rb +++ b/spec/system/consumer/checkout/summary_spec.rb @@ -126,10 +126,10 @@ describe "As a consumer, I want to checkout my order" do 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") + fixture_file_upload(system_terms_path, "application/pdf") } let(:shop_terms) { - Rack::Test::UploadedFile.new(shop_terms_path, "application/pdf") + fixture_file_upload(shop_terms_path, "application/pdf") } context "when none are required" do diff --git a/spec/system/consumer/shopping/checkout_spec.rb b/spec/system/consumer/shopping/checkout_spec.rb index 8b39be28f5..33332d8819 100644 --- a/spec/system/consumer/shopping/checkout_spec.rb +++ b/spec/system/consumer/shopping/checkout_spec.rb @@ -90,7 +90,7 @@ describe "As a consumer I want to check out my cart" do pending 'login in as user' do let(:user) { create(:user) } let(:pdf_upload) { - Rack::Test::UploadedFile.new( + fixture_file_upload( Rails.public_path.join('Terms-of-service.pdf'), "application/pdf" )