Sha256: e7be3b43241399fa744d83a1f5a2724e6502bd29561087467a4ccd098bf3ccce
Contents?: true
Size: 1.86 KB
Versions: 3
Compression:
Stored size: 1.86 KB
Contents
require 'spec_helper' module Spree describe Spree::Api::V1::ImagesController do render_views let!(:product) { Factory(:product) } let!(:attributes) { [:id, :position, :attachment_content_type, :attachment_file_name, :type, :attachment_updated_at, :attachment_width, :attachment_height, :alt] } before do stub_authentication! end it "can upload a new image for a product" do product.images.count.should == 0 api_post :create, :product_id => product.to_param, :image => { :attachment => upload_image("thinking-cat.jpg") } response.status.should == 201 json_response.should have_attributes(attributes) product.images.count.should == 1 end it "can upload a new image for a variant" do product.master.images.count.should == 0 api_post :create, :variant_id => product.master.to_param, :image => { :attachment => upload_image("thinking-cat.jpg") } response.status.should == 201 json_response.should have_attributes(attributes) product.images.count.should == 1 end context "working with an existing image" do let!(:product_image) { product.master.images.create!(:attachment => image("thinking-cat.jpg")) } it "can update image data" do product_image.position.should == 1 api_post :update, :variant_id => product.master.to_param, :image => { :position => 2 }, :id => product_image.id response.status.should == 200 json_response.should have_attributes(attributes) product_image.reload.position.should == 2 end it "can delete an image" do api_delete :destroy, :variant_id => product.master.to_param, :id => product_image.id response.status.should == 200 lambda { product_image.reload }.should raise_error(ActiveRecord::RecordNotFound) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems