From dd639435f1a4e53bdab1a7c1415be4ff1b84c9c6 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 8 Jan 2024 10:58:27 +1100 Subject: [PATCH] Remove unnecessary image file helper --- spec/controllers/api/v0/products_controller_spec.rb | 6 ++++-- .../fixtures => fixtures/files}/thinking-cat.jpg | Bin spec/support/api_helper.rb | 4 ---- spec/system/admin/products_spec.rb | 8 +++----- 4 files changed, 7 insertions(+), 11 deletions(-) rename spec/{support/fixtures => fixtures/files}/thinking-cat.jpg (100%) diff --git a/spec/controllers/api/v0/products_controller_spec.rb b/spec/controllers/api/v0/products_controller_spec.rb index c31e323896..b96081a57e 100644 --- a/spec/controllers/api/v0/products_controller_spec.rb +++ b/spec/controllers/api/v0/products_controller_spec.rb @@ -25,15 +25,17 @@ describe Api::V0::ProductsController, type: :controller do end context "as a normal user" do + let(:attachment) { fixture_file_upload("thinking-cat.jpg") } + before do allow(current_api_user) .to receive(:has_spree_role?).with("admin").and_return(false) end it "gets a single product" do - product.create_image!(attachment: image("thinking-cat.jpg")) + product.create_image!(attachment:) product.variants.create!(unit_value: "1", unit_description: "thing", price: 1) - product.variants.first.images.create!(attachment: image("thinking-cat.jpg")) + product.variants.first.images.create!(attachment:) product.set_property("spree", "rocks") api_get :show, id: product.to_param diff --git a/spec/support/fixtures/thinking-cat.jpg b/spec/fixtures/files/thinking-cat.jpg similarity index 100% rename from spec/support/fixtures/thinking-cat.jpg rename to spec/fixtures/files/thinking-cat.jpg diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb index a0f8e10105..b9546b25e6 100644 --- a/spec/support/api_helper.rb +++ b/spec/support/api_helper.rb @@ -26,9 +26,5 @@ module OpenFoodNetwork expect(json_response).to eq("error" => "You are not authorized to perform that action.") expect(response.status).to eq 401 end - - def image(filename) - fixture_file_upload(Rails.root + "spec/support/fixtures" + filename) - end end end diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index 47a5e58cef..0a83938ce0 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -340,6 +340,7 @@ describe ' context "as an enterprise user" do let!(:tax_category) { create(:tax_category) } let(:filter) { { producerFilter: 2 } } + let(:image_file_path) { Rails.root.join(file_fixture_path, "thinking-cat.jpg") } before do @new_user = create(:user) @@ -627,14 +628,13 @@ describe ' end it "upload a new product image including url filters" do - file_path = Rails.root + "spec/support/fixtures/thinking-cat.jpg" product = create(:simple_product, supplier: @supplier2) visit spree.admin_product_images_path(product, filter) page.find('a#new_image_link').click - attach_file('image_attachment', file_path) + attach_file('image_attachment', image_file_path) click_button "Create" uri = URI.parse(current_url) @@ -680,13 +680,11 @@ describe ' viewable_type: 'Spree::Product', alt: "position 1", attachment: image, position: 1) - file_path = Rails.root + "spec/support/fixtures/thinking-cat.jpg" - visit spree.admin_product_images_path(product, filter) page.find("a.icon-edit").click - attach_file('image_attachment', file_path) + attach_file('image_attachment', image_file_path) click_button "Update" uri = URI.parse(current_url)