carrierwave-upyun 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.rspec +0 -1
- data/CHANGELOGS.md +19 -0
- data/Gemfile +6 -8
- data/Gemfile.lock +111 -90
- data/README.md +6 -7
- data/carrierwave-upyun.gemspec +5 -6
- data/lib/carrierwave-upyun.rb +2 -1
- data/lib/carrierwave/storage/upyun.rb +40 -99
- data/lib/carrierwave/upyun/configuration.rb +0 -1
- data/spec/spec_helper.rb +4 -5
- data/spec/upload_spec.rb +18 -28
- metadata +18 -28
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NWYxNzY1NmI1MTUyMzE3YTgzMzRkMzU1MzdhYWM5NzZkYjg2ZTgyNw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9db3fc705cd4eb65b80033ced7aafbd986729516
|
4
|
+
data.tar.gz: fdd02b351fed04bc6d893ec8634a04fa11cdc22f
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTI2ZGEzN2M5YWIyZjI1ZWQ0YzE3OTMwMTMzOWI1NjQ3ZmE0M2IzMjIyMzEw
|
11
|
-
YzQyMGYyNzczYTU2MzYzNWNlN2U4MzcwOTQ2YTYzNTBmZTg3NTA=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmU4ZTI5OWE4N2JmNmZlMTE5NzIyN2JkZDFiODFlNThkYTVjZmNlMTRiNzYz
|
14
|
-
ZGFiOGE5YzdmMWI5NTc2YWFhMzMxZDBlMjJlYTQ4MTUyOGNiNmU5YmRjNmM5
|
15
|
-
MDNhZTM4NzAwODU3MjIxNjE3YjNmY2FkZjY4M2Q5NzZmZDljMDI=
|
6
|
+
metadata.gz: 21fb21a5f762f4364cd5e7216d73321ab5cc5c2f830fd572f78ca9e50702709561bd2194937764f3ed23245bb4303ae7552645bf441ab017594004d5b42c8d78
|
7
|
+
data.tar.gz: b480edd42e648e5029c53a1c4279eb7b9a14602ac9249c91951c453e87320882017464a8a445bbd06a6f72d863337a1796c848e34dba780e35f75bf3105ea571
|
data/.rspec
CHANGED
data/CHANGELOGS.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
|
3
|
+
- 改用 Faraday 代替 rest-client,来发送 HTTP 请求;
|
4
|
+
- 精简代码;
|
5
|
+
- 移除 `upyun_bucket_domain` 配置信息,请用 `upyun_bucket_host` 代替;
|
6
|
+
|
7
|
+
## 0.1.8
|
8
|
+
|
9
|
+
- 修复 upyun_bucket_domain 选项处理错误;
|
10
|
+
- 修复不含 'http://' 前缀的值处理出错的问题;
|
11
|
+
|
12
|
+
## 0.1.7
|
13
|
+
|
14
|
+
- SSL Host 配置支持;
|
15
|
+
- Fix issue 16 并减少连接; #18
|
16
|
+
|
17
|
+
## 0.1.6
|
18
|
+
|
19
|
+
- 改进 Upyun 初始化,将少连接的过程;
|
data/Gemfile
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
gem 'rspec','~> 2.6.0'
|
10
|
-
end
|
4
|
+
gem "rake"
|
5
|
+
gem 'rails', '4.2.0'
|
6
|
+
gem 'sqlite3'
|
7
|
+
gem 'mini_magick'
|
8
|
+
gem 'rspec'
|
data/Gemfile.lock
CHANGED
@@ -1,108 +1,128 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
carrierwave-upyun (0.
|
4
|
+
carrierwave-upyun (0.2.0)
|
5
5
|
carrierwave (>= 0.5.7)
|
6
|
-
|
6
|
+
faraday (>= 0.8.0)
|
7
7
|
|
8
8
|
GEM
|
9
|
-
remote:
|
9
|
+
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (
|
12
|
-
actionpack (=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
actionmailer (4.2.0)
|
12
|
+
actionpack (= 4.2.0)
|
13
|
+
actionview (= 4.2.0)
|
14
|
+
activejob (= 4.2.0)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
17
|
+
actionpack (4.2.0)
|
18
|
+
actionview (= 4.2.0)
|
19
|
+
activesupport (= 4.2.0)
|
20
|
+
rack (~> 1.6.0)
|
21
|
+
rack-test (~> 0.6.2)
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
24
|
+
actionview (4.2.0)
|
25
|
+
activesupport (= 4.2.0)
|
26
|
+
builder (~> 3.1)
|
18
27
|
erubis (~> 2.7.0)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
activemodel (
|
25
|
-
activesupport (=
|
26
|
-
builder (~> 3.
|
27
|
-
activerecord (
|
28
|
-
activemodel (=
|
29
|
-
activesupport (=
|
30
|
-
arel (~>
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
carrierwave (0.8.0)
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
30
|
+
activejob (4.2.0)
|
31
|
+
activesupport (= 4.2.0)
|
32
|
+
globalid (>= 0.3.0)
|
33
|
+
activemodel (4.2.0)
|
34
|
+
activesupport (= 4.2.0)
|
35
|
+
builder (~> 3.1)
|
36
|
+
activerecord (4.2.0)
|
37
|
+
activemodel (= 4.2.0)
|
38
|
+
activesupport (= 4.2.0)
|
39
|
+
arel (~> 6.0)
|
40
|
+
activesupport (4.2.0)
|
41
|
+
i18n (~> 0.7)
|
42
|
+
json (~> 1.7, >= 1.7.7)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
45
|
+
tzinfo (~> 1.1)
|
46
|
+
arel (6.0.0)
|
47
|
+
builder (3.2.2)
|
48
|
+
carrierwave (0.10.0)
|
41
49
|
activemodel (>= 3.2.0)
|
42
50
|
activesupport (>= 3.2.0)
|
43
|
-
|
51
|
+
json (>= 1.7)
|
52
|
+
mime-types (>= 1.16)
|
53
|
+
diff-lcs (1.2.5)
|
44
54
|
erubis (2.7.0)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
55
|
+
faraday (0.9.1)
|
56
|
+
multipart-post (>= 1.2, < 3)
|
57
|
+
globalid (0.3.5)
|
58
|
+
activesupport (>= 4.1.0)
|
59
|
+
i18n (0.7.0)
|
60
|
+
json (1.8.2)
|
61
|
+
loofah (2.0.1)
|
62
|
+
nokogiri (>= 1.5.9)
|
63
|
+
mail (2.6.3)
|
64
|
+
mime-types (>= 1.16, < 3)
|
65
|
+
mime-types (2.5)
|
54
66
|
mini_magick (3.3)
|
55
67
|
subexec (~> 0.1.0)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
rack
|
62
|
-
|
63
|
-
rack-test (0.6.2)
|
68
|
+
mini_portile (0.6.2)
|
69
|
+
minitest (5.6.1)
|
70
|
+
multipart-post (2.0.0)
|
71
|
+
nokogiri (1.6.6.2)
|
72
|
+
mini_portile (~> 0.6.0)
|
73
|
+
rack (1.6.0)
|
74
|
+
rack-test (0.6.3)
|
64
75
|
rack (>= 1.0)
|
65
|
-
rails (
|
66
|
-
actionmailer (=
|
67
|
-
actionpack (=
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
76
|
+
rails (4.2.0)
|
77
|
+
actionmailer (= 4.2.0)
|
78
|
+
actionpack (= 4.2.0)
|
79
|
+
actionview (= 4.2.0)
|
80
|
+
activejob (= 4.2.0)
|
81
|
+
activemodel (= 4.2.0)
|
82
|
+
activerecord (= 4.2.0)
|
83
|
+
activesupport (= 4.2.0)
|
84
|
+
bundler (>= 1.3.0, < 2.0)
|
85
|
+
railties (= 4.2.0)
|
86
|
+
sprockets-rails
|
87
|
+
rails-deprecated_sanitizer (1.0.3)
|
88
|
+
activesupport (>= 4.2.0.alpha)
|
89
|
+
rails-dom-testing (1.0.6)
|
90
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
91
|
+
nokogiri (~> 1.6.0)
|
92
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
93
|
+
rails-html-sanitizer (1.0.2)
|
94
|
+
loofah (~> 2.0)
|
95
|
+
railties (4.2.0)
|
96
|
+
actionpack (= 4.2.0)
|
97
|
+
activesupport (= 4.2.0)
|
77
98
|
rake (>= 0.8.7)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
rspec-
|
89
|
-
rspec-
|
90
|
-
|
91
|
-
|
92
|
-
rspec-
|
93
|
-
sprockets (
|
94
|
-
hike (~> 1.2)
|
95
|
-
multi_json (~> 1.0)
|
99
|
+
thor (>= 0.18.1, < 2.0)
|
100
|
+
rake (0.9.2.2)
|
101
|
+
rspec (3.2.0)
|
102
|
+
rspec-core (~> 3.2.0)
|
103
|
+
rspec-expectations (~> 3.2.0)
|
104
|
+
rspec-mocks (~> 3.2.0)
|
105
|
+
rspec-core (3.2.3)
|
106
|
+
rspec-support (~> 3.2.0)
|
107
|
+
rspec-expectations (3.2.1)
|
108
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
109
|
+
rspec-support (~> 3.2.0)
|
110
|
+
rspec-mocks (3.2.1)
|
111
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
112
|
+
rspec-support (~> 3.2.0)
|
113
|
+
rspec-support (3.2.2)
|
114
|
+
sprockets (3.0.3)
|
96
115
|
rack (~> 1.0)
|
97
|
-
|
98
|
-
|
116
|
+
sprockets-rails (2.2.4)
|
117
|
+
actionpack (>= 3.0)
|
118
|
+
activesupport (>= 3.0)
|
119
|
+
sprockets (>= 2.8, < 4.0)
|
120
|
+
sqlite3 (1.3.10)
|
99
121
|
subexec (0.1.0)
|
100
|
-
thor (0.
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
polyglot (>= 0.3.1)
|
105
|
-
tzinfo (0.3.37)
|
122
|
+
thor (0.19.1)
|
123
|
+
thread_safe (0.3.5)
|
124
|
+
tzinfo (1.2.2)
|
125
|
+
thread_safe (~> 0.1)
|
106
126
|
|
107
127
|
PLATFORMS
|
108
128
|
ruby
|
@@ -110,6 +130,7 @@ PLATFORMS
|
|
110
130
|
DEPENDENCIES
|
111
131
|
carrierwave-upyun!
|
112
132
|
mini_magick
|
113
|
-
rails (
|
114
|
-
|
133
|
+
rails (= 4.2.0)
|
134
|
+
rake
|
135
|
+
rspec
|
115
136
|
sqlite3
|
data/README.md
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
# CarrierWave for [
|
1
|
+
# CarrierWave for [UpYun (又拍云存储)](http://upyun.com)
|
2
2
|
|
3
3
|
This gem adds support for [Upyun.com](http://www.upyun.com) to [CarrierWave](https://github.com/jnicklas/carrierwave/)
|
4
4
|
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
gem install carrierwave-upyun
|
8
5
|
|
9
|
-
##
|
6
|
+
## Installation
|
10
7
|
|
11
|
-
|
12
|
-
|
8
|
+
```ruby
|
9
|
+
gem 'carrierwave'
|
10
|
+
gem 'carrierwave-upyun'
|
11
|
+
```
|
13
12
|
|
14
13
|
## Configuration
|
15
14
|
|
data/carrierwave-upyun.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "carrierwave-upyun"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.2.0"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = ["Nowa Zhu"]
|
9
|
-
s.email = ["nowazhu@gmail.com"]
|
8
|
+
s.authors = ["Nowa Zhu", "Jason Lee"]
|
9
|
+
s.email = ["nowazhu@gmail.com", "huacnlee@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/nowa/carrierwave-upyun"
|
11
11
|
s.summary = %q{UpYun Storage support for CarrierWave}
|
12
12
|
s.description = %q{UpYun Storage support for CarrierWave}
|
@@ -16,6 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
18
|
s.add_dependency "carrierwave", [">= 0.5.7"]
|
19
|
-
s.add_dependency "
|
20
|
-
s.add_development_dependency "rspec", ["~> 2.6"]
|
19
|
+
s.add_dependency "faraday", [">= 0.8.0"]
|
21
20
|
end
|
data/lib/carrierwave-upyun.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "carrierwave/storage/upyun"
|
2
2
|
require "carrierwave/upyun/configuration"
|
3
|
+
|
3
4
|
CarrierWave.configure do |config|
|
4
|
-
config.storage_engines.merge!({:
|
5
|
+
config.storage_engines.merge!({upyun: "CarrierWave::Storage::UpYun"})
|
5
6
|
end
|
6
7
|
|
7
8
|
CarrierWave::Uploader::Base.send(:include, CarrierWave::UpYun::Configuration)
|
@@ -1,16 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rest_client'
|
6
|
-
RestClient.log = nil
|
7
|
-
rescue LoadError
|
8
|
-
raise "You don't have the 'rest_client' gem installed"
|
9
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
require "faraday"
|
10
3
|
|
11
4
|
module CarrierWave
|
12
5
|
module Storage
|
13
|
-
|
14
6
|
##
|
15
7
|
#
|
16
8
|
# CarrierWave.configure do |config|
|
@@ -23,51 +15,9 @@ module CarrierWave
|
|
23
15
|
#
|
24
16
|
#
|
25
17
|
class UpYun < Abstract
|
26
|
-
|
27
|
-
|
28
|
-
cattr_reader :shared_connections
|
29
|
-
@@shared_connections = {}
|
30
|
-
|
31
|
-
def self.find_or_initialize(bucket, options)
|
32
|
-
@@shared_connections[bucket.to_sym] ||= new(bucket, options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(bucket, options = {})
|
36
|
-
@upyun_bucket = bucket
|
37
|
-
@upyun_username = options[:upyun_username]
|
38
|
-
@upyun_password = options[:upyun_password]
|
39
|
-
|
40
|
-
@host = options[:api_host] || 'http://v0.api.upyun.com'
|
41
|
-
end
|
42
|
-
private_class_method :new
|
43
|
-
|
44
|
-
def rest_client
|
45
|
-
@rest_client ||= RestClient::Resource.new("#{@host}/#{@upyun_bucket}", :user => @upyun_username, :password => @upyun_password)
|
46
|
-
end
|
47
|
-
|
48
|
-
def put(path, payload, headers = {})
|
49
|
-
rest_client[escaped(path)].put(payload, headers)
|
50
|
-
end
|
51
|
-
|
52
|
-
def get(path, headers = {})
|
53
|
-
rest_client[escaped(path)].get(headers)
|
54
|
-
end
|
55
|
-
|
56
|
-
def delete(path, headers = {})
|
57
|
-
rest_client[escaped(path)].delete(headers)
|
58
|
-
end
|
59
|
-
|
60
|
-
def post(path, payload, headers = {})
|
61
|
-
rest_client[escaped(path)].post(payload, headers)
|
62
|
-
end
|
63
|
-
|
64
|
-
def escaped(path)
|
65
|
-
CGI.escape(path)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
18
|
+
DEFAULT_API_URL = 'http://v0.api.upyun.com'
|
19
|
+
|
69
20
|
class File
|
70
|
-
|
71
21
|
def initialize(uploader, base, path)
|
72
22
|
@uploader = uploader
|
73
23
|
@path = path
|
@@ -84,6 +34,10 @@ module CarrierWave
|
|
84
34
|
def path
|
85
35
|
@path
|
86
36
|
end
|
37
|
+
|
38
|
+
def escaped_path
|
39
|
+
@escaped_path ||= CGI.escape(@path)
|
40
|
+
end
|
87
41
|
|
88
42
|
def content_type
|
89
43
|
@content_type || ""
|
@@ -101,9 +55,9 @@ module CarrierWave
|
|
101
55
|
# [String] contents of the file
|
102
56
|
#
|
103
57
|
def read
|
104
|
-
|
105
|
-
@headers =
|
106
|
-
|
58
|
+
res = conn.get(escaped_path)
|
59
|
+
@headers = res.headers
|
60
|
+
res.body
|
107
61
|
end
|
108
62
|
|
109
63
|
##
|
@@ -111,10 +65,10 @@ module CarrierWave
|
|
111
65
|
#
|
112
66
|
def delete
|
113
67
|
begin
|
114
|
-
|
68
|
+
conn.delete(escaped_path)
|
115
69
|
true
|
116
|
-
rescue
|
117
|
-
|
70
|
+
rescue => e
|
71
|
+
puts "carrierwave-upyun delete failed: #{e.inspect}"
|
118
72
|
nil
|
119
73
|
end
|
120
74
|
end
|
@@ -128,16 +82,8 @@ module CarrierWave
|
|
128
82
|
# [String] file's url
|
129
83
|
#
|
130
84
|
def url
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
return nil unless @uploader.upyun_bucket_domain
|
136
|
-
puts "DEPRECATION: upyun_bucket_domain config is deprecated, please use upyun_bucket_host to insead."
|
137
|
-
|
138
|
-
bucket_host = @uploader.upyun_bucket_domain
|
139
|
-
bucket_host.prepend('http://') unless bucket_host.match(/^http/)
|
140
|
-
[bucket_host, @path].join("/")
|
85
|
+
return nil unless @uploader.upyun_bucket_host
|
86
|
+
[@uploader.upyun_bucket_host, @path].join("/")
|
141
87
|
end
|
142
88
|
|
143
89
|
def content_type
|
@@ -155,36 +101,32 @@ module CarrierWave
|
|
155
101
|
#
|
156
102
|
# boolean
|
157
103
|
#
|
158
|
-
def store(data,headers={})
|
159
|
-
|
104
|
+
def store(data, headers = {})
|
105
|
+
conn.put(escaped_path, data) do |req|
|
106
|
+
req.headers = {'Expect' => '', 'Mkdir' => 'true'}.merge(headers)
|
107
|
+
end
|
160
108
|
true
|
161
109
|
end
|
162
110
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
rescue Excon::Errors::NotFound # Don't die, just return no headers
|
169
|
-
{}
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def connection
|
174
|
-
@base.connection
|
111
|
+
def headers
|
112
|
+
@headers ||= begin
|
113
|
+
conn.get(@path).headers
|
114
|
+
rescue Faraday::ClientError
|
115
|
+
{}
|
175
116
|
end
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
117
|
+
end
|
118
|
+
|
119
|
+
def conn
|
120
|
+
return @conn if defined?(@conn)
|
121
|
+
|
122
|
+
api_host = @uploader.upyun_api_host || DEFAULT_API_URL
|
123
|
+
@conn = Faraday.new(url: "#{api_host}/#{@uploader.upyun_bucket}") do |req|
|
124
|
+
req.request :basic_auth, @uploader.upyun_username, @uploader.upyun_password
|
125
|
+
req.request :url_encoded
|
126
|
+
req.adapter Faraday.default_adapter
|
186
127
|
end
|
187
|
-
|
128
|
+
end
|
129
|
+
end # File
|
188
130
|
|
189
131
|
##
|
190
132
|
# Store the file on UpYun
|
@@ -198,9 +140,8 @@ module CarrierWave
|
|
198
140
|
# [CarrierWave::Storage::UpYun::File] the stored file
|
199
141
|
#
|
200
142
|
def store!(file)
|
201
|
-
|
202
|
-
f
|
203
|
-
f.store(file.read,cloud_files_options)
|
143
|
+
f = File.new(uploader, self, uploader.store_path)
|
144
|
+
f.store(file.read, 'Content-Type' => file.content_type)
|
204
145
|
f
|
205
146
|
end
|
206
147
|
|
@@ -215,7 +156,7 @@ module CarrierWave
|
|
215
156
|
# [CarrierWave::Storage::UpYun::File] the stored file
|
216
157
|
#
|
217
158
|
def retrieve!(identifier)
|
218
|
-
|
159
|
+
File.new(uploader, self, uploader.store_path(identifier))
|
219
160
|
end
|
220
161
|
|
221
162
|
end # CloudFiles
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rspec'
|
3
|
-
require 'rspec/autorun'
|
4
3
|
require 'rails'
|
5
4
|
require 'active_record'
|
6
5
|
require "carrierwave"
|
@@ -25,10 +24,10 @@ ActiveRecord::Migration.verbose = false
|
|
25
24
|
# 测试的时候需要修改这个地方
|
26
25
|
CarrierWave.configure do |config|
|
27
26
|
config.storage = :upyun
|
28
|
-
config.upyun_username = ENV['upyun_username'] || "
|
29
|
-
config.upyun_password = ENV['upyun_password'] || '
|
30
|
-
config.upyun_bucket = ENV['upyun_bucket'] || "
|
31
|
-
config.
|
27
|
+
config.upyun_username = ENV['upyun_username'] || "test"
|
28
|
+
config.upyun_password = ENV['upyun_password'] || '123123'
|
29
|
+
config.upyun_bucket = ENV['upyun_bucket'] || "ruby-china-files-dev"
|
30
|
+
config.upyun_bucket_host = ENV['upyun_bucket_host'] || "http://ruby-china-files-dev.b0.upaiyun.com"
|
32
31
|
end
|
33
32
|
|
34
33
|
def load_file(fname)
|
data/spec/upload_spec.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
require "open-uri"
|
4
|
-
|
5
|
-
|
6
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
4
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
5
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
7
6
|
|
8
7
|
describe "Upload" do
|
9
8
|
def setup_db
|
@@ -49,32 +48,23 @@ describe "Upload" do
|
|
49
48
|
it "does upload image" do
|
50
49
|
f = load_file("foo.jpg")
|
51
50
|
puts Benchmark.measure {
|
52
|
-
@photo = Photo.create(:
|
51
|
+
@photo = Photo.create(image: f)
|
53
52
|
}
|
54
|
-
@photo.errors.count.
|
55
|
-
|
56
|
-
|
57
|
-
open(@photo.image.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
expect
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
it "create only one instance for same buckets" do
|
71
|
-
CarrierWave::Storage::UpYun::Connection.find_or_initialize 'bucket999', :upyun_username => "foo"
|
72
|
-
CarrierWave::Storage::UpYun::Connection.find_or_initialize 'bucket999', :upyun_username => "foo"
|
73
|
-
instances = []
|
74
|
-
ObjectSpace.each_object(CarrierWave::Storage::UpYun::Connection) do |conn|
|
75
|
-
instances << conn if conn.upyun_bucket == 'bucket999'
|
76
|
-
end
|
77
|
-
instances.should have(1).item
|
53
|
+
expect(@photo.errors.count).to eq 0
|
54
|
+
puts "Uploaded: #{@photo.image.url}"
|
55
|
+
|
56
|
+
res = open(@photo.image.url)
|
57
|
+
|
58
|
+
expect(res).not_to be_nil
|
59
|
+
expect(res.size).to eq f.size
|
60
|
+
|
61
|
+
small_res = open(@photo.image.small.url)
|
62
|
+
expect(small_res).not_to be_nil
|
63
|
+
|
64
|
+
f1 = load_file("foo.gif")
|
65
|
+
p1 = Photo.create(image: f1)
|
66
|
+
res = open(p1.image.url)
|
67
|
+
expect(res.size).to eq f1.size
|
78
68
|
end
|
79
69
|
end
|
80
70
|
end
|
metadata
CHANGED
@@ -1,66 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-upyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nowa Zhu
|
8
|
+
- Jason Lee
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: carrierwave
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: 0.5.7
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: 0.5.7
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: faraday
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- -
|
32
|
+
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
+
version: 0.8.0
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- -
|
39
|
+
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.6'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.6'
|
41
|
+
version: 0.8.0
|
55
42
|
description: UpYun Storage support for CarrierWave
|
56
43
|
email:
|
57
44
|
- nowazhu@gmail.com
|
45
|
+
- huacnlee@gmail.com
|
58
46
|
executables: []
|
59
47
|
extensions: []
|
60
48
|
extra_rdoc_files: []
|
61
49
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
50
|
+
- ".gitignore"
|
51
|
+
- ".rspec"
|
52
|
+
- CHANGELOGS.md
|
64
53
|
- Gemfile
|
65
54
|
- Gemfile.lock
|
66
55
|
- README.md
|
@@ -81,17 +70,17 @@ require_paths:
|
|
81
70
|
- lib
|
82
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
72
|
requirements:
|
84
|
-
- -
|
73
|
+
- - ">="
|
85
74
|
- !ruby/object:Gem::Version
|
86
75
|
version: '0'
|
87
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
77
|
requirements:
|
89
|
-
- -
|
78
|
+
- - ">="
|
90
79
|
- !ruby/object:Gem::Version
|
91
80
|
version: '0'
|
92
81
|
requirements: []
|
93
82
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.4.7
|
95
84
|
signing_key:
|
96
85
|
specification_version: 4
|
97
86
|
summary: UpYun Storage support for CarrierWave
|
@@ -100,3 +89,4 @@ test_files:
|
|
100
89
|
- spec/foo.jpg
|
101
90
|
- spec/spec_helper.rb
|
102
91
|
- spec/upload_spec.rb
|
92
|
+
has_rdoc:
|