carrierwave-upyun 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+ gem "rake"
3
+
4
+ group :test do
5
+ gem 'rails', '3.0.0'
6
+ gem 'sqlite3-ruby', :require => 'sqlite3'
7
+ gem 'carrierwave'
8
+ gem 'mini_magick'
9
+ gem 'rest-client'
10
+ gem 'rspec','~> 2.6.0'
11
+ gem 'mocha','0.10.0'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.0)
6
+ actionpack (= 3.0.0)
7
+ mail (~> 2.2.5)
8
+ actionpack (3.0.0)
9
+ activemodel (= 3.0.0)
10
+ activesupport (= 3.0.0)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4.1)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.12)
16
+ rack-test (~> 0.5.4)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.0)
19
+ activesupport (= 3.0.0)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4.1)
22
+ activerecord (3.0.0)
23
+ activemodel (= 3.0.0)
24
+ activesupport (= 3.0.0)
25
+ arel (~> 1.0.0)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ activesupport (3.0.0)
31
+ arel (1.0.1)
32
+ activesupport (~> 3.0.0)
33
+ builder (2.1.2)
34
+ carrierwave (0.5.7)
35
+ activesupport (~> 3.0)
36
+ diff-lcs (1.1.3)
37
+ erubis (2.6.6)
38
+ abstract (>= 1.0.0)
39
+ i18n (0.4.2)
40
+ mail (2.2.19)
41
+ activesupport (>= 2.3.6)
42
+ i18n (>= 0.4.0)
43
+ mime-types (~> 1.16)
44
+ treetop (~> 1.4.8)
45
+ metaclass (0.0.1)
46
+ mime-types (1.17.2)
47
+ mini_magick (3.3)
48
+ subexec (~> 0.1.0)
49
+ mocha (0.10.0)
50
+ metaclass (~> 0.0.1)
51
+ polyglot (0.3.3)
52
+ rack (1.2.4)
53
+ rack-mount (0.6.14)
54
+ rack (>= 1.0.0)
55
+ rack-test (0.5.7)
56
+ rack (>= 1.0)
57
+ rails (3.0.0)
58
+ actionmailer (= 3.0.0)
59
+ actionpack (= 3.0.0)
60
+ activerecord (= 3.0.0)
61
+ activeresource (= 3.0.0)
62
+ activesupport (= 3.0.0)
63
+ bundler (~> 1.0.0)
64
+ railties (= 3.0.0)
65
+ railties (3.0.0)
66
+ actionpack (= 3.0.0)
67
+ activesupport (= 3.0.0)
68
+ rake (>= 0.8.4)
69
+ thor (~> 0.14.0)
70
+ rake (0.9.2.2)
71
+ rest-client (1.6.7)
72
+ mime-types (>= 1.16)
73
+ rspec (2.6.0)
74
+ rspec-core (~> 2.6.0)
75
+ rspec-expectations (~> 2.6.0)
76
+ rspec-mocks (~> 2.6.0)
77
+ rspec-core (2.6.4)
78
+ rspec-expectations (2.6.0)
79
+ diff-lcs (~> 1.1.2)
80
+ rspec-mocks (2.6.0)
81
+ sqlite3 (1.3.4)
82
+ sqlite3-ruby (1.3.3)
83
+ sqlite3 (>= 1.3.3)
84
+ subexec (0.1.0)
85
+ thor (0.14.6)
86
+ treetop (1.4.10)
87
+ polyglot
88
+ polyglot (>= 0.3.1)
89
+ tzinfo (0.3.30)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ carrierwave
96
+ mini_magick
97
+ mocha (= 0.10.0)
98
+ rails (= 3.0.0)
99
+ rake
100
+ rest-client
101
+ rspec (~> 2.6.0)
102
+ sqlite3-ruby
data/README.md CHANGED
@@ -17,9 +17,10 @@ You'll need to configure the to use this in config/initializes/carrierwave.rb
17
17
 
18
18
  ```ruby
19
19
  CarrierWave.configure do |config|
20
- config.upyun_storage_username = "xxxxxx"
21
- config.upyun_storage_userpass = 'xxxxxx'
22
- config.upyun_storage_bucket = "my_bucket"
20
+ config.storage = :upyun
21
+ config.upyun_username = "xxxxxx"
22
+ config.upyun_password = 'xxxxxx'
23
+ config.upyun_bucket = "my_bucket"
23
24
  config.upyun_bucket_domain = "my_bucket.files.example.com"
24
25
  end
25
26
  ```
@@ -3,7 +3,7 @@ $:.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.1.1"
6
+ s.version = "0.1.2"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Nowa Zhu"]
9
9
  s.email = ["nowazhu@gmail.com"]
@@ -13,11 +13,11 @@ module CarrierWave
13
13
  ##
14
14
  #
15
15
  # CarrierWave.configure do |config|
16
- # config.upyun_storage_username = "xxxxxx"
17
- # config.upyun_storage_userpass = "xxxxxx"
18
- # config.upyun_storage_bucket = "my_bucket"
16
+ # config.upyun_username = "xxxxxx"
17
+ # config.upyun_password = "xxxxxx"
18
+ # config.upyun_bucket = "my_bucket"
19
19
  # config.upyun_bucket_domain = "https://my_bucket.files.example.com"
20
- # config.upyun_storage_api_host = "http://v0.api.upyun.com"
20
+ # config.upyun_api_host = "http://v0.api.upyun.com"
21
21
  # end
22
22
  #
23
23
  #
@@ -25,12 +25,12 @@ module CarrierWave
25
25
 
26
26
  class Connection
27
27
  def initialize(options={})
28
- @upyun_storage_username = options[:upyun_storage_username]
29
- @upyun_storage_userpass = options[:upyun_storage_userpass]
30
- @upyun_storage_bucket = options[:upyun_storage_bucket]
28
+ @upyun_username = options[:upyun_username]
29
+ @upyun_password = options[:upyun_password]
30
+ @upyun_bucket = options[:upyun_bucket]
31
31
  @connection_options = options[:connection_options] || {}
32
32
  @host = options[:api_host] || 'http://v0.api.upyun.com'
33
- @http = RestClient::Resource.new("#{@host}/#{@upyun_storage_bucket}", @upyun_storage_username, @upyun_storage_userpass)
33
+ @http = RestClient::Resource.new("#{@host}/#{@upyun_bucket}", @upyun_username, @upyun_password)
34
34
  end
35
35
 
36
36
  def put(path, payload, headers = {})
@@ -82,7 +82,7 @@ module CarrierWave
82
82
  #
83
83
  def read
84
84
  object = uy_connection.get(@path)
85
- object.data
85
+ object.net_http_res.read_body
86
86
  end
87
87
 
88
88
  ##
@@ -140,11 +140,11 @@ module CarrierWave
140
140
  if @uy_connection
141
141
  @uy_connection
142
142
  else
143
- config = {:upyun_storage_username => @uploader.upyun_storage_username,
144
- :upyun_storage_userpass => @uploader.upyun_storage_userpass,
145
- :upyun_storage_bucket => @uploader.upyun_storage_bucket
143
+ config = {:upyun_username => @uploader.upyun_username,
144
+ :upyun_password => @uploader.upyun_password,
145
+ :upyun_bucket => @uploader.upyun_bucket
146
146
  }
147
- config[:api_host] = @uploader.upyun_storage_api_host if @uploader.respond_to?(:upyun_storage_api_host)
147
+ config[:api_host] = @uploader.upyun_api_host if @uploader.respond_to?(:upyun_api_host)
148
148
  @uy_connection ||= CarrierWave::Storage::UpYun::Connection.new(config)
149
149
  end
150
150
  end
@@ -3,10 +3,10 @@ module CarrierWave
3
3
  module Configuration
4
4
  extend ActiveSupport::Concern
5
5
  included do
6
- add_config :upyun_storage_username
7
- add_config :upyun_storage_userpass
8
- add_config :upyun_storage_bucket
9
- add_config :upyun_storage_api_host
6
+ add_config :upyun_username
7
+ add_config :upyun_password
8
+ add_config :upyun_bucket
9
+ add_config :upyun_api_host
10
10
  add_config :upyun_bucket_domain
11
11
  end
12
12
  end
data/spec/.DS_Store ADDED
Binary file
data/spec/foo.gif ADDED
Binary file
data/spec/foo.jpg ADDED
Binary file
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'rspec/autorun'
4
+ require 'rails'
5
+ require 'active_record'
6
+ require "carrierwave"
7
+ require 'carrierwave/orm/activerecord'
8
+ require 'carrierwave/processing/mini_magick'
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+
13
+ require "carrierwave/upyun"
14
+
15
+
16
+ module Rails
17
+ class <<self
18
+ def root
19
+ [File.expand_path(__FILE__).split('/')[0..-3].join('/'),"spec"].join("/")
20
+ end
21
+ end
22
+ end
23
+
24
+ ActiveRecord::Migration.verbose = false
25
+
26
+ # 测试的时候需要修改这个地方
27
+ CarrierWave.configure do |config|
28
+ config.storage = :upyun
29
+ config.upyun_username = "rspec"
30
+ config.upyun_password = 'spec123'
31
+ config.upyun_bucket = "rspec"
32
+ config.upyun_bucket_domain = "rspec.b0.upaiyun.com"
33
+ end
34
+
35
+ def load_file(fname)
36
+ File.open([Rails.root,fname].join("/"))
37
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ require "open-uri"
4
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
5
+
6
+ describe "Upload" do
7
+ def setup_db
8
+ ActiveRecord::Schema.define(:version => 1) do
9
+ create_table :photos do |t|
10
+ t.column :image, :string
11
+ end
12
+ end
13
+ end
14
+
15
+ def drop_db
16
+ ActiveRecord::Base.connection.tables.each do |table|
17
+ ActiveRecord::Base.connection.drop_table(table)
18
+ end
19
+ end
20
+
21
+ class PhotoUploader < CarrierWave::Uploader::Base
22
+ include CarrierWave::MiniMagick
23
+
24
+ version :small do
25
+ process :resize_to_fill => [120, 120]
26
+ end
27
+
28
+ def store_dir
29
+ "photos"
30
+ end
31
+ end
32
+
33
+ class Photo < ActiveRecord::Base
34
+ mount_uploader :image, PhotoUploader
35
+ end
36
+
37
+
38
+ before :all do
39
+ setup_db
40
+ end
41
+
42
+ after :all do
43
+ drop_db
44
+ end
45
+
46
+ context "Upload Image" do
47
+ it "does upload image" do
48
+ f = load_file("foo.jpg")
49
+ photo = Photo.create(:image => f)
50
+ photo.errors.count.should == 0
51
+ open(photo.image.url).should_not == nil
52
+ open(photo.image.url).size.should == f.size
53
+ open(photo.image.small.url).should_not == nil
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nowa Zhu
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-11-03 00:00:00 +08:00
17
+ date: 2011-12-05 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -81,11 +81,19 @@ extensions: []
81
81
  extra_rdoc_files: []
82
82
 
83
83
  files:
84
+ - .rspec
85
+ - Gemfile
86
+ - Gemfile.lock
84
87
  - README.md
85
88
  - carrierwave-upyun.gemspec
86
89
  - lib/carrierwave/storage/upyun.rb
87
90
  - lib/carrierwave/upyun.rb
88
91
  - lib/carrierwave/upyun/configuration.rb
92
+ - spec/.DS_Store
93
+ - spec/foo.gif
94
+ - spec/foo.jpg
95
+ - spec/spec_helper.rb
96
+ - spec/upload_spec.rb
89
97
  has_rdoc: true
90
98
  homepage: https://github.com/nowa/carrierwave-upyun
91
99
  licenses: []
@@ -116,5 +124,8 @@ rubygems_version: 1.3.6
116
124
  signing_key:
117
125
  specification_version: 3
118
126
  summary: UpYun Storage support for CarrierWave
119
- test_files: []
120
-
127
+ test_files:
128
+ - spec/foo.gif
129
+ - spec/foo.jpg
130
+ - spec/spec_helper.rb
131
+ - spec/upload_spec.rb