paperclip-storage-aliyun 0.1.0 → 0.1.1

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: d8531e6601564efe368735f05147b68f4401c495
4
- data.tar.gz: e2317360addbbce35acd8bf2947a532cdf11f8c2
3
+ metadata.gz: fc88eeef9e399e74817562b2fbb525257e0240cf
4
+ data.tar.gz: 680b18f58b81bace15aa4e63e59fe7d862e6128d
5
5
  SHA512:
6
- metadata.gz: 1f7ce3fda9227a3937a1d04e7acce987c60028187496261c493176f87e016fcaba3083fc7a9977b28af313ac9a92b0ffef6af5ba092a052f40baaac65f7b52e6
7
- data.tar.gz: abef51e1bbeb91ac622f74ed61f17bde84026d91eba1ebf423b11833ff770b2a4912d385ec09de6728d16f4d5d0bfafb44517696f0b43e268d4cc6cd3b10753d
6
+ metadata.gz: 540eb2053d03facff5b05791eaee3e829296bd1cd6f149326598369530c425307ac5d2fa407dd13ab5479855b8063d1b38268a9fc53a3de912e9e7c52ea4fa44
7
+ data.tar.gz: 24098248c2e5786d0e091c10bd9e5f7eecd70cb930a789fcfa1ebc0b2334388ee71236d2927f07f085dd871bc7a66fb97663d1565bb4e42bae28c7e7703318ef
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://ruby.taobao.org'
1
+ source 'https://gems.ruby-china.org'
2
2
 
3
3
  gemspec
4
4
 
data/README.md CHANGED
@@ -45,3 +45,19 @@ Similar to Paperclip::Storage::S3, there are four options for the url by now:
45
45
  - `:aliyun_alias_url` : the alias url based on the `host_alias` you give, typically used together with CDN
46
46
 
47
47
  Please note the values above are all strings, not symbols. You could still make your own url if only you know what you are doing.
48
+
49
+ #### Test
50
+ 1. Update connection settings in `spec/spec_helper.rb`:
51
+
52
+ ```ruby
53
+ # Aliyun defaults
54
+ OSS_CONNECTION_OPTIONS = {
55
+ access_id: 'your_access_key_id',
56
+ access_key: 'your_access_key_secret',
57
+ bucket: 'your_bucket',
58
+ data_center: 'your_data_center',
59
+ internal: false
60
+ }
61
+ ```
62
+
63
+ 2. Run `bundle exec rspec spec`.
@@ -93,7 +93,7 @@ module Aliyun
93
93
  'Host' => @aliyun_upload_host,
94
94
  'Expect' => '100-Continue'
95
95
  }
96
- response = RestClient.put(URI.encode(url), file, headers)
96
+ response = RestClient.put(url, file, headers)
97
97
  response.code == 200 ? path_to_url(path) : nil
98
98
  end
99
99
 
@@ -113,7 +113,7 @@ module Aliyun
113
113
  'Authorization' => sign('DELETE', bucket_path, '', '', date)
114
114
  }
115
115
  url = path_to_url(path)
116
- response = RestClient.delete(URI.encode(url), headers)
116
+ response = RestClient.delete(url, headers)
117
117
  response.code == 204 ? url : nil
118
118
  end
119
119
 
@@ -132,7 +132,7 @@ module Aliyun
132
132
  'Authorization' => sign('GET', bucket_path, '', '', date)
133
133
  }
134
134
  url = path_to_url(path)
135
- response = RestClient.get(URI.encode(url), headers)
135
+ response = RestClient.get(url, headers)
136
136
  response.body
137
137
  end
138
138
 
@@ -176,7 +176,7 @@ module Aliyun
176
176
  # @param path [String] the path to retrieve the file on remote storage
177
177
  # @return [String] the expected full path, e.g. "http://martin-test.oss-cn-hangzhou.aliyuncs.com/oss-api.pdf"
178
178
  def path_to_url(path)
179
- path =~ %r{^https?://} ? path : "http://#{aliyun_upload_host}/#{path}"
179
+ URI.encode(path =~ %r{^https?://} ? path : "http://#{aliyun_upload_host}/#{path}")
180
180
  end
181
181
 
182
182
  private
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.require_path = 'lib'
5
5
  s.summary = 'Extend a Aliyun OSS storage for paperclip'
6
6
  s.description = 'Extend a Aliyun OSS storage for paperclip'
7
- s.version = '0.1.0'
7
+ s.version = '0.1.1'
8
8
  s.files = `git ls-files`.split("\n")
9
9
  s.authors = ['Martin Hong', 'Aidi Stan']
10
10
  s.email = 'hongzeqin@gmail.com'
@@ -40,11 +40,23 @@ describe Aliyun::Connection do
40
40
  response_code = Net::HTTP.get_response(URI.parse(url)).code
41
41
  expect(response_code).to eq('404')
42
42
  end
43
+
44
+ describe "delete attachment with Chinese name" do
45
+ it "delete the attachment" do
46
+ path = "a/美女.jpg"
47
+ @connection.put path, load_attachment('美女.jpg')
48
+ url = @connection.delete path
49
+ response_code = Net::HTTP.get_response(URI.parse(url)).code
50
+ expect(response_code).to eq('404')
51
+ end
52
+ end
43
53
  end
44
54
 
45
55
  describe '#exists?' do
46
56
  before :all do
47
57
  @connection.put @path, load_attachment('girl.jpg')
58
+ @path_include_chinese = "美女.jpg"
59
+ @connection.put @path_include_chinese, load_attachment("美女.jpg")
48
60
  end
49
61
 
50
62
  it 'return true if the file has been uploaded' do
@@ -55,5 +67,11 @@ describe Aliyun::Connection do
55
67
  @connection.delete @path
56
68
  expect(@connection.exists?(@path)).to be_falsey
57
69
  end
70
+
71
+ it "also return true for existed file with path include chinese characters" do
72
+ expect(@connection.exists?(@path_include_chinese)).to be_truthy
73
+ url = "http://#{@connection.aliyun_upload_host}/#{@path_include_chinese}"
74
+ expect(@connection.exists?(url)).to be_truthy
75
+ end
58
76
  end
59
77
  end
@@ -69,5 +69,19 @@ describe Paperclip::Storage::Aliyun do
69
69
  response_code = Net::HTTP.get_response(URI.parse(attachment_url)).code
70
70
  expect(response_code).to eq('404')
71
71
  end
72
+
73
+ context "work with path include Chinese characters" do
74
+ before do
75
+ @file_with_chinese_char_name = load_attachment("美女.jpg")
76
+ @post_with_chinese_char_name_file = Post.create attachment: @file_with_chinese_char_name
77
+ end
78
+
79
+ it "deletes the attachment from Aliyun" do
80
+ attachment_url = @post_with_chinese_char_name_file.attachment.url
81
+ @post_with_chinese_char_name_file.destroy
82
+ response_code = Net::HTTP.get_response(URI.parse(attachment_url)).code
83
+ expect(response_code).to eq('404')
84
+ end
85
+ end
72
86
  end
73
87
  end
@@ -7,8 +7,8 @@ Dir[Bundler.root.join('spec/support/**/*.rb')].each(&method(:require))
7
7
 
8
8
  # Aliyun defaults
9
9
  OSS_CONNECTION_OPTIONS = {
10
- access_id: '3VL9XMho8iCuslj8',
11
- access_key: 'VAUI2q7Tc6yTf1jr3kBsEUzZ84gEa2',
10
+ access_id: '4adTRa4dWto3vxiq',
11
+ access_key: 'hzEWBDWlt3N0SPPj6EfYAr4ISdaizW',
12
12
  bucket: 'martin-test',
13
13
  data_center: 'hangzhou',
14
14
  internal: false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-storage-aliyun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Hong
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-01 00:00:00.000000000 Z
12
+ date: 2016-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip
@@ -60,6 +60,7 @@ files:
60
60
  - spec/aliyun_spec.rb
61
61
  - spec/attachments/girl.jpg
62
62
  - spec/attachments/masu.pdf
63
+ - spec/attachments/美女.jpg
63
64
  - spec/fixtures/schema.rb
64
65
  - spec/lib/paperclip/storage/aliyun_spec.rb
65
66
  - spec/spec_helper.rb
@@ -90,4 +91,3 @@ signing_key:
90
91
  specification_version: 4
91
92
  summary: Extend a Aliyun OSS storage for paperclip
92
93
  test_files: []
93
- has_rdoc: