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.
This commit is contained in:
Maikel Linke
2022-06-14 14:56:40 +10:00
parent 831aa3aae0
commit 6b733ad7e2

View File

@@ -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