carrierwave-qiniu 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1283fa0bce68604381eb4205a7f8822d8c3d4cec
4
- data.tar.gz: 5c4bf47715f08955f616054a6953858360fa2678
3
+ metadata.gz: 2f480f9beeba0f2721902bff9075edcc12929ea8
4
+ data.tar.gz: 59992dcd0be07822fd1f0584f7cd793df52b36f4
5
5
  SHA512:
6
- metadata.gz: b56cbc02bdea0362f2c922724bda4c295a4d893d59a643272ab31150986c1de26d54be141c0057fdfab9737c1257cfea0c8eab941126b7775d7e3004dfe5c4c8
7
- data.tar.gz: 41935e2de0415de62d26d06834bdfe41cdc768c4701746dbb2d57ac9e7956bcb358dfed967add495d5844e59cdc03705a97b9e2acf0ac35bfacc4038ce139bf1
6
+ metadata.gz: b237b492ab50e519611d23b1e70b6322c0c52587ec8a53e8be2bfaea9bcf814558b0694497129bc2db2deb2570ff71d818bc15f79f0042e4c05f34090c48a33f
7
+ data.tar.gz: 572cca06fbeb64d780f4c90e4c776ca94dad3e1ce67c371af9f2e7278fee244c76838080a02896940190c5b4a17bf4b4f733903fbbff610a39aa0281f403b7f1
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
  ## CHANGE LOG
3
3
 
4
+ ### v0.2.4
5
+
6
+ - Add test for upload failed
7
+ https://github.com/huobazi/carrierwave-qiniu/pull/57
8
+
4
9
  ### v0.2.3
5
10
 
6
11
  - Add extension method
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  #source 'https://rubygems.org'
2
- source 'https://ruby.taobao.org'
2
+ source 'https://gems.ruby-china.org'
3
3
 
4
4
  # Specify your gem's dependencies in carrierwave-qiniu.gemspec
5
5
  gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Carrierwave::Qiniu
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?0.2.0)](http://badge.fury.io/rb/carrierwave-qiniu)
3
+ [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?0.2.3)](http://badge.fury.io/rb/carrierwave-qiniu)
4
4
 
5
5
  This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
6
6
  example: https://github.com/huobazi/carrierwave-qiniu-example
@@ -78,7 +78,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
78
78
 
79
79
  end
80
80
  ```
81
- You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example
81
+ You can see a example project on: https://github.com/huobazi/carrierwave-qiniu-example
82
+
82
83
  or see the spec test on https://github.com/huobazi/carrierwave-qiniu/blob/master/spec/upload_spec.rb
83
84
 
84
85
  ## Contributing
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
6
- end
6
+ end
@@ -42,12 +42,16 @@ module CarrierWave
42
42
  put_policy.callback_body = @qiniu_callback_body if @qiniu_callback_body.present?
43
43
  put_policy.persistent_notify_url = @qiniu_persistent_notify_url if @qiniu_persistent_notify_url.present?
44
44
 
45
- ::Qiniu::Storage.upload_with_put_policy(
46
- put_policy,
47
- file.path,
48
- key
49
- )
50
-
45
+ resp_code, resp_body, resp_headers =
46
+ ::Qiniu::Storage.upload_with_put_policy(
47
+ put_policy,
48
+ file.path,
49
+ key
50
+ )
51
+
52
+ if resp_code < 200 or resp_code >= 300
53
+ raise ::CarrierWave::UploadError, "Upload failed, status code: #{resp_code}, response: #{resp_body}"
54
+ end
51
55
  end
52
56
 
53
57
  #
@@ -58,7 +62,9 @@ module CarrierWave
58
62
  #
59
63
  def copy(origin, target)
60
64
  code, result, _ = ::Qiniu::Storage.copy(@qiniu_bucket, origin, @qiniu_bucket, target)
61
- code == 200 ? result : nil
65
+ if resp_code < 200 or resp_code >= 300
66
+ raise ::CarrierWave::IntegrityError, "Copy failed, status code: #{resp_code}, response: #{resp_body}"
67
+ end
62
68
  end
63
69
 
64
70
  def delete(key)
@@ -204,7 +210,7 @@ module CarrierWave
204
210
 
205
211
  def store!(file)
206
212
  f = ::CarrierWave::Storage::Qiniu::File.new(uploader, uploader.store_path(uploader.filename))
207
- if file && file.copy_from_path
213
+ if file && file.respond_to?(:copy_from_path) and file.copy_from_path
208
214
  f.copy_from file.copy_from_path
209
215
  else
210
216
  f.store(file)
data/spec/upload_spec.rb CHANGED
@@ -72,6 +72,25 @@ require 'carrierwave/processing/mini_magick'
72
72
  end
73
73
 
74
74
  context "Upload Image" do
75
+ it "should save failed" do
76
+ class WrongUploader < PhotoUploader
77
+ self.qiniu_bucket = 'not_exists'
78
+ end
79
+
80
+ class Photo < ActiveRecord::Base
81
+ mount_uploader :image, WrongUploader
82
+ end
83
+
84
+ f = load_file("mm.jpg")
85
+ photo = Photo.new(:image => f)
86
+ photo.save
87
+ expect(photo).to_not be_valid
88
+
89
+ expect {
90
+ photo.save!
91
+ }.to raise_error
92
+ end
93
+
75
94
  it "does upload image" do
76
95
  f = load_file("mm.jpg")
77
96
  photo = Photo.new(:image => f)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marble Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave