spec/upload_spec.rb in carrierwave-aliyun-0.1.1 vs spec/upload_spec.rb in carrierwave-aliyun-0.1.2
- old
+ new
@@ -7,10 +7,14 @@
def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :photos do |t|
t.column :image, :string
end
+
+ create_table :attachments do |t|
+ t.column :file, :string
+ end
end
end
def drop_db
ActiveRecord::Base.connection.tables.each do |table|
@@ -27,16 +31,28 @@
def store_dir
"photos"
end
end
+
+ class AttachUploader < CarrierWave::Uploader::Base
+ include CarrierWave::MiniMagick
+ def store_dir
+ "attachs"
+ end
+ end
+
class Photo < ActiveRecord::Base
mount_uploader :image, PhotoUploader
end
+ class Attachment < ActiveRecord::Base
+ mount_uploader :file, AttachUploader
+ end
+
before :all do
setup_db
end
after :all do
@@ -66,8 +82,25 @@
it "sholud get small version uploaded file" do
open(@photo.image.small.url).should_not == nil
open(@photo1.image.small.url).should_not == nil
end
+ end
+
+ context "should update zip" do
+ before(:all) do
+ @file = load_file("foo.zip")
+ @attachment = Attachment.new(:file => @file)
+ end
+
+ it "should upload file" do
+ @attachment.save.should be_true
+ end
+
+ it "should get uploaded file" do
+ attach = open(@attachment.file.url)
+ attach.size.should == @file.size
+ end
+
end
end
end
\ No newline at end of file