From 58b43c7bc936e8477d10ae1c216cf1c5c467f2fc Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 24 Jul 2019 09:23:51 +0100 Subject: [PATCH 1/4] Remove update_product_image.v1.rabl and switch controller from respond_with to render json to switch from rabl to AMS --- app/controllers/api/product_images_controller.rb | 4 ++-- app/views/api/product_images/update_product_image.v1.rabl | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 app/views/api/product_images/update_product_image.v1.rabl diff --git a/app/controllers/api/product_images_controller.rb b/app/controllers/api/product_images_controller.rb index adcf978c51..71fc9a5164 100644 --- a/app/controllers/api/product_images_controller.rb +++ b/app/controllers/api/product_images_controller.rb @@ -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/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) } From 11a77043eb66f6b0e6548924a5472fffff4d0ca2 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 30 Jul 2019 12:15:13 +0100 Subject: [PATCH 2/4] Switch from Spree::Api::BaseController to Api::BaseController so that AMS is activated --- app/controllers/api/product_images_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/product_images_controller.rb b/app/controllers/api/product_images_controller.rb index 71fc9a5164..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 From 6ebfb02d0e3ad0964734bb320a849aa14939192e Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 30 Jul 2019 20:14:19 +0100 Subject: [PATCH 3/4] Update ImageSerializer with missing image size urls: mini/thumb_url, product/image_url that is used in the product image modal --- app/serializers/api/image_serializer.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 From 9400516b5670970e233b564f7fda46075ebae5e2 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 30 Jul 2019 20:37:26 +0100 Subject: [PATCH 4/4] Fix broken (was always green) bulk_product_update_spec updating image spec where the old src url was not stored and the expect command was wrong with != --- spec/features/admin/bulk_product_update_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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