Add controller specs

This commit is contained in:
Matt-Yorkley
2018-02-14 15:25:22 +00:00
parent 8a11dc3c33
commit fdc14ab44e
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
require 'spec_helper'
require 'spree/api/testing_support/helpers'
module Api
describe ProductImagesController, type: :controller do
include AuthenticationWorkflow
render_views
describe "uploading an image" do
before do
allow(controller).to receive(:spree_current_user) { current_api_user }
end
image_path = File.open(Rails.root.join('app', 'assets', 'images', 'logo-black.png'))
let(:image) { Rack::Test::UploadedFile.new(image_path, 'image/png') }
let!(:product_without_image) { create(:product) }
let!(:product_with_image) { create(:product_with_image) }
sign_in_as_admin!
it "saves a new image when none is present" do
xhr :post, :update_product_image, 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
it "updates an existing product image" do
xhr :post, :update_product_image, 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
end
end
end

View File

@@ -425,6 +425,13 @@ FactoryGirl.define do
stripe_user_id "abc123"
stripe_publishable_key "xyz456"
end
factory :product_with_image, parent: :product do
after(:create) do |product|
image = File.open(Rails.root.join('app', 'assets', 'images', 'logo-white.png'))
Spree::Image.create(attachment: image, viewable_id: product.master.id, viewable_type: 'Spree::Variant')
end
end
end