Merge pull request #4073 from luisramos0/kill_more_rabl

Replace update_prod_image.rabl with ImageSerializer in api/product_image_controller
This commit is contained in:
Maikel
2019-08-06 15:00:33 +10:00
committed by GitHub
4 changed files with 15 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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