mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-09 03:20:21 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user