From 6b733ad7e2e3ba8909d164b826dc3205bfd3b6e4 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 14 Jun 2022 14:56:40 +1000 Subject: [PATCH] Increase readability of image controller spec Best viewed without whitespace changes. - Decrease indent. - Move `let` to top like in other specs. - Avoid `let!` to speed up the specs. --- .../api/v0/product_images_controller_spec.rb | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb index cf658afc1e..d4b5f93fba 100644 --- a/spec/controllers/api/v0/product_images_controller_spec.rb +++ b/spec/controllers/api/v0/product_images_controller_spec.rb @@ -2,37 +2,37 @@ require 'spec_helper' -module Api - describe V0::ProductImagesController, type: :controller do - include AuthenticationHelper - include FileHelper - render_views +describe Api::V0::ProductImagesController, type: :controller do + include AuthenticationHelper + include FileHelper + render_views - describe "uploading an image" do - before do - allow(controller).to receive(:spree_current_user) { current_api_user } - end + describe "uploading an image" do + let(:image) { Rack::Test::UploadedFile.new(black_logo_file, 'image/png') } + let(:product_without_image) { create(:product) } + let(:product_with_image) { create(:product_with_image) } + let(:current_api_user) { create(:admin_user) } - let(:image) { Rack::Test::UploadedFile.new(black_logo_file, 'image/png') } - let!(:product_without_image) { create(:product) } - let!(:product_with_image) { create(:product_with_image) } - let(:current_api_user) { create(:admin_user) } + before do + allow(controller).to receive(:spree_current_user) { current_api_user } + end - it "saves a new image when none is present" do - post :update_product_image, xhr: true, - params: { product_id: product_without_image.id, file: image, use_route: :product_images } + it "saves a new image when none is present" do + post :update_product_image, xhr: true, params: { + product_id: product_without_image.id, file: image, use_route: :product_images + } - expect(response.status).to eq 201 - expect(product_without_image.images.first.id).to eq json_response['id'] - end + expect(response.status).to eq 201 + expect(product_without_image.images.first.id).to eq json_response['id'] + end - it "updates an existing product image" do - post :update_product_image, xhr: true, - params: { product_id: product_with_image.id, file: image, use_route: :product_images } + it "updates an existing product image" do + post :update_product_image, xhr: true, params: { + product_id: product_with_image.id, file: image, use_route: :product_images + } - expect(response.status).to eq 200 - expect(product_with_image.images.first.id).to eq json_response['id'] - end + expect(response.status).to eq 200 + expect(product_with_image.images.first.id).to eq json_response['id'] end end end