diff --git a/app/controllers/api/product_images_controller.rb b/app/controllers/api/product_images_controller.rb index adcf978c51..a8706f6458 100644 --- a/app/controllers/api/product_images_controller.rb +++ b/app/controllers/api/product_images_controller.rb @@ -1,5 +1,5 @@ module Api - class ProductImagesController < Spree::Api::BaseController + class ProductImagesController < BaseController respond_to :json def update_product_image @@ -8,11 +8,11 @@ module Api if @product.images.first.nil? @image = Spree::Image.create(attachment: params[:file], viewable_id: @product.master.id, viewable_type: 'Spree::Variant') - respond_with(@image, status: 201) + render json: @image, serializer: ImageSerializer, status: :created else @image = @product.images.first @image.update_attributes(attachment: params[:file]) - respond_with(@image, status: 200) + render json: @image, serializer: ImageSerializer, status: :ok end end end diff --git a/app/serializers/api/image_serializer.rb b/app/serializers/api/image_serializer.rb index 3c787d2f7a..70c62b397a 100644 --- a/app/serializers/api/image_serializer.rb +++ b/app/serializers/api/image_serializer.rb @@ -1,10 +1,18 @@ class Api::ImageSerializer < ActiveModel::Serializer - attributes :id, :alt, :small_url, :large_url + attributes :id, :alt, :thumb_url, :small_url, :image_url, :large_url + + def thumb_url + object.attachment.url(:mini, false) + end def small_url object.attachment.url(:small, false) end + def image_url + object.attachment.url(:product, false) + end + def large_url object.attachment.url(:large, false) end diff --git a/app/views/api/product_images/update_product_image.v1.rabl b/app/views/api/product_images/update_product_image.v1.rabl deleted file mode 100644 index c9e62475dc..0000000000 --- a/app/views/api/product_images/update_product_image.v1.rabl +++ /dev/null @@ -1,5 +0,0 @@ -object @image -attributes(*image_attributes) -attributes :viewable_type, :viewable_id -node( :thumb_url ) { @product.images.first.attachment.url(:mini) } -node( :image_url ) { @product.images.first.attachment.url(:product) } diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 715e551668..8050858460 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -742,7 +742,7 @@ feature ' end end - describe "Updating product image with new upload interface" do + describe "Updating product image" do let!(:product) { create(:simple_product, name: "Carrots") } it "displays product images and image upload modal" do @@ -755,6 +755,7 @@ feature ' # Shows default image when no image set expect(page).to have_css "img[src='/assets/noimage/mini.png']" + @old_thumb_src = page.find("a.image-modal img")['src'] # Click image page.find("a.image-modal").click @@ -780,7 +781,7 @@ feature ' within "table#listing_products tr#p_#{product.id}" do # New thumbnail is shown in image column @new_thumb_src = page.find("a.image-modal img")['src'] - expect(@old_thumb_src) != @new_thumb_src + expect(@old_thumb_src).not_to eq @new_thumb_src page.find("a.image-modal").click end