mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-09 12:56:21 +10:00
Merge pull request #28 from zhouguangming/bug_fixed
MissingArgsError should get a key_list // very nice!
This commit is contained in:
+5
-3
@@ -100,12 +100,14 @@ module Qiniu
|
||||
end
|
||||
|
||||
def upload_file opts = {}
|
||||
[:uptoken, :file, :bucket, :key].each do |opt|
|
||||
raise MissingArgsError, [opt] unless opts.has_key?(opt)
|
||||
end
|
||||
uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys
|
||||
raise MissingArgsError, uncontained_opts unless uncontained_opts.empty?
|
||||
|
||||
source_file = opts[:file]
|
||||
raise NoSuchFileError, source_file unless File.exist?(source_file)
|
||||
|
||||
opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)
|
||||
|
||||
if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
|
||||
code, data = UP.upload_with_token(opts[:uptoken],
|
||||
opts[:file],
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require 'digest/sha1'
|
||||
require 'spec_helper'
|
||||
require 'qiniu/rs'
|
||||
require 'qiniu/rs/exceptions'
|
||||
|
||||
module Qiniu
|
||||
describe RS do
|
||||
@@ -148,6 +149,29 @@ module Qiniu
|
||||
result.should_not be_false
|
||||
puts result.inspect
|
||||
end
|
||||
|
||||
it "should raise MissingArgsError" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||
:file => __FILE__,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
lambda { Qiniu::RS.upload_file(upload_opts) }.should raise_error(RS::MissingArgsError)
|
||||
end
|
||||
|
||||
it "should raise NoSuchFileError" do
|
||||
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||
upload_opts = {
|
||||
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||
:file => 'no_this_file',
|
||||
:bucket => @bucket,
|
||||
:key => @key,
|
||||
:enable_crc32_check => true
|
||||
}
|
||||
lambda { Qiniu::RS.upload_file(upload_opts) }.should raise_error(RS::NoSuchFileError)
|
||||
end
|
||||
end
|
||||
|
||||
context ".resumable_upload_file" do
|
||||
|
||||
Reference in New Issue
Block a user