diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb index a19ef98c00..2c0a380bee 100644 --- a/spec/controllers/api/v0/product_images_controller_spec.rb +++ b/spec/controllers/api/v0/product_images_controller_spec.rb @@ -9,8 +9,7 @@ describe Api::V0::ProductImagesController, type: :controller do describe "uploading an image" do let(:image) { black_logo_file } - let(:pdf) { fixture_file_upload(pdf_path, 'application/pdf') } - let(:pdf_path) { Rails.public_path.join('Terms-of-service.pdf') } + let(:pdf) { terms_pdf_file } 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 ed8978cd7f..d5e7f511f8 100644 --- a/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb +++ b/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb @@ -12,10 +12,7 @@ module Api let(:enterprise_manager) { create(:user, enterprises: [enterprise]) } describe "removing terms and conditions file" do - let(:terms_file_path) { Rails.public_path.join('Terms-of-service.pdf') } - let(:terms_and_conditions_file) { - fixture_file_upload(terms_file_path, "application/pdf") - } + let(:terms_and_conditions_file) { terms_pdf_file } let(:enterprise) { create(:enterprise, owner: enterprise_owner) } before do diff --git a/spec/models/terms_of_service_file_spec.rb b/spec/models/terms_of_service_file_spec.rb index d702a66365..19d9fb183d 100644 --- a/spec/models/terms_of_service_file_spec.rb +++ b/spec/models/terms_of_service_file_spec.rb @@ -3,8 +3,9 @@ require 'spec_helper' describe TermsOfServiceFile do - let(:pdf) { File.open(Rails.public_path.join('Terms-of-service.pdf')) } - let(:upload) { fixture_file_upload(pdf, "application/pdf") } + include FileHelper + + let(:upload) { terms_pdf_file } describe ".current" do it "returns nil" do diff --git a/spec/support/file_helper.rb b/spec/support/file_helper.rb index 4ab44257d7..3e2feb2233 100644 --- a/spec/support/file_helper.rb +++ b/spec/support/file_helper.rb @@ -16,4 +16,9 @@ module FileHelper def white_logo_path Rails.root.join('app/webpacker/images/logo-white.png') end + + def terms_pdf_file + file_path = Rails.public_path.join("Terms-of-service.pdf") + fixture_file_upload(file_path, "application/pdf") + end end diff --git a/spec/system/admin/tos_banner_spec.rb b/spec/system/admin/tos_banner_spec.rb index 853c18384a..902d11071f 100644 --- a/spec/system/admin/tos_banner_spec.rb +++ b/spec/system/admin/tos_banner_spec.rb @@ -4,12 +4,10 @@ require 'system_helper' describe 'Terms of Service banner' do include AuthenticationHelper + include FileHelper let(:admin_user) { create(:admin_user, terms_of_service_accepted_at: nil) } - let(:test_file) { "Terms-of-service.pdf" } - let(:pdf_upload) do - fixture_file_upload(Rails.public_path.join(test_file), "application/pdf") - end + let(:pdf_upload) { terms_pdf_file } before do Spree::Config.enterprises_require_tos = true @@ -43,7 +41,7 @@ describe 'Terms of Service banner' do # Upload new ToS visit admin_terms_of_service_files_path - attach_file "Attachment", Rails.public_path.join(test_file) + attach_file "Attachment", pdf_upload.path click_button "Create Terms of service file" # check it has been uploaded diff --git a/spec/system/consumer/checkout/summary_spec.rb b/spec/system/consumer/checkout/summary_spec.rb index 408acbbbfb..f36dfa5f22 100644 --- a/spec/system/consumer/checkout/summary_spec.rb +++ b/spec/system/consumer/checkout/summary_spec.rb @@ -123,14 +123,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:) } let(:tos_url) { "https://example.org/tos" } - 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) { - fixture_file_upload(system_terms_path, "application/pdf") - } - let(:shop_terms) { - fixture_file_upload(shop_terms_path, "application/pdf") - } + let(:system_terms) { terms_pdf_file } + let(:shop_terms) { terms_pdf_file } context "when none are required" do it "doesn't show checkbox or links" do @@ -152,7 +146,7 @@ describe "As a consumer, I want to checkout my order" do describe "when customer has not accepted T&Cs before" do it "shows a link to the T&Cs and disables checkout button until terms are accepted" do visit checkout_step_path(:summary) - expect(page).to have_link "Terms and Conditions", href: /#{shop_terms_path.basename}$/ + expect(page).to have_link "Terms and Conditions", href: /Terms-of-service\.pdf/ expect(page).to have_field "order_accept_terms", checked: false end end @@ -243,8 +237,8 @@ describe "As a consumer, I want to checkout my order" do it "shows links to both terms and all need accepting" do visit checkout_step_path(:summary) - expect(page).to have_link "Terms and Conditions", href: /#{shop_terms_path.basename}$/ - expect(page).to have_link("Terms of service", href: /Terms-of-service.pdf/, count: 2) + expect(page).to have_link "Terms and Conditions", href: /Terms-of-service\.pdf/ + expect(page).to have_link("Terms of service", href: /Terms-of-service\.pdf/, count: 2) expect(page).to have_field "order_accept_terms", checked: false end end diff --git a/spec/system/consumer/shopping/checkout_spec.rb b/spec/system/consumer/shopping/checkout_spec.rb index 33332d8819..b897468232 100644 --- a/spec/system/consumer/shopping/checkout_spec.rb +++ b/spec/system/consumer/shopping/checkout_spec.rb @@ -89,12 +89,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) { - fixture_file_upload( - Rails.public_path.join('Terms-of-service.pdf'), - "application/pdf" - ) - } + let(:pdf_upload) { terms_pdf_file } before do login_as(user)