Permalink
Browse files

validate shop storage before kindeditor upload, #388.

  • Loading branch information...
saberma committed Feb 2, 2012
1 parent 86246c6 commit 5e53ac83f2d3d3b2a91233e12bdde664cba42eef
Showing with 22 additions and 2 deletions.
  1. +2 −2 app/controllers/admin/kindeditor_controller.rb
  2. +1 −0 app/models/kindeditor.rb
  3. +19 −0 spec/models/kindeditor_spec.rb
@@ -6,9 +6,9 @@ class Admin::KindeditorController < Admin::AppController
def upload_image
@image = shop.kindeditors.build(kindeditor_image: params[:imgFile])
if @image.save
- render :text => {"error" => 0, "url" => @image.kindeditor_image.url}.to_json
+ render text: {error: 0, url: @image.kindeditor_image.url}.to_json
else
- render :text => {"error" => 1}
+ render text: {error: 1, message: @image.errors.full_messages.join(',')}.to_json
end
end
View
@@ -9,6 +9,7 @@ class Kindeditor < ActiveRecord::Base
end
validates_size_of :kindeditor_image, maximum: 8000.kilobytes
+ validates_with StorageValidator
validates_property :mime_type, of: :kindeditor_image, in: %w(image/jpeg image/jpg image/png image/gif), message: "格式不正确"
end
@@ -1,4 +1,23 @@
require 'spec_helper'
describe Kindeditor do
+
+ let(:shop) { Factory(:user).shop }
+
+ context '#create' do
+
+ context 'shop storage is not idle' do # 容量已经用完
+
+ it "should be fail" do
+ photo = shop.kindeditors.build
+ photo.kindeditor_image = Rails.root.join('spec/factories/data/products/iphone4.jpg')
+ photo.shop.stub!(:storage_idle?) { false }
+ photo.save
+ photo.errors.full_messages.join(',').should_not be_blank
+ end
+
+ end
+
+ end
+
end

0 comments on commit 5e53ac8

Please sign in to comment.