Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename config attributes.

Add test.
  • Loading branch information...
commit 670f0187d02c7f039aec9d085e702501b25d3c67 1 parent d439c1a
Jason Lee huacnlee authored
2  .rspec
View
@@ -0,0 +1,2 @@
+--colour
+--format nested
12 Gemfile
View
@@ -0,0 +1,12 @@
+source :rubygems
+gem "rake"
+
+group :test do
+ gem 'rails', '3.0.0'
+ gem 'sqlite3-ruby', :require => 'sqlite3'
+ gem 'carrierwave'
+ gem 'mini_magick'
+ gem 'rest-client'
+ gem 'rspec','~> 2.6.0'
+ gem 'mocha','0.10.0'
+end
102 Gemfile.lock
View
@@ -0,0 +1,102 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0)
+ actionpack (= 3.0.0)
+ mail (~> 2.2.5)
+ actionpack (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.12)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ arel (~> 1.0.0)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ activesupport (3.0.0)
+ arel (1.0.1)
+ activesupport (~> 3.0.0)
+ builder (2.1.2)
+ carrierwave (0.5.7)
+ activesupport (~> 3.0)
+ diff-lcs (1.1.3)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.2)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ metaclass (0.0.1)
+ mime-types (1.17.2)
+ mini_magick (3.3)
+ subexec (~> 0.1.0)
+ mocha (0.10.0)
+ metaclass (~> 0.0.1)
+ polyglot (0.3.3)
+ rack (1.2.4)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.0)
+ actionmailer (= 3.0.0)
+ actionpack (= 3.0.0)
+ activerecord (= 3.0.0)
+ activeresource (= 3.0.0)
+ activesupport (= 3.0.0)
+ bundler (~> 1.0.0)
+ railties (= 3.0.0)
+ railties (3.0.0)
+ actionpack (= 3.0.0)
+ activesupport (= 3.0.0)
+ rake (>= 0.8.4)
+ thor (~> 0.14.0)
+ rake (0.9.2.2)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ sqlite3 (1.3.4)
+ sqlite3-ruby (1.3.3)
+ sqlite3 (>= 1.3.3)
+ subexec (0.1.0)
+ thor (0.14.6)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.30)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ carrierwave
+ mini_magick
+ mocha (= 0.10.0)
+ rails (= 3.0.0)
+ rake
+ rest-client
+ rspec (~> 2.6.0)
+ sqlite3-ruby
7 README.md
View
@@ -17,9 +17,10 @@ You'll need to configure the to use this in config/initializes/carrierwave.rb
```ruby
CarrierWave.configure do |config|
- config.upyun_storage_username = "xxxxxx"
- config.upyun_storage_userpass = 'xxxxxx'
- config.upyun_storage_bucket = "my_bucket"
+ config.storage = :upyun
+ config.upyun_username = "xxxxxx"
+ config.upyun_password = 'xxxxxx'
+ config.upyun_bucket = "my_bucket"
config.upyun_bucket_domain = "my_bucket.files.example.com"
end
```
24 lib/carrierwave/storage/upyun.rb
View
@@ -13,11 +13,11 @@ module Storage
##
#
# CarrierWave.configure do |config|
- # config.upyun_storage_username = "xxxxxx"
- # config.upyun_storage_userpass = "xxxxxx"
- # config.upyun_storage_bucket = "my_bucket"
+ # config.upyun_username = "xxxxxx"
+ # config.upyun_password = "xxxxxx"
+ # config.upyun_bucket = "my_bucket"
# config.upyun_bucket_domain = "https://my_bucket.files.example.com"
- # config.upyun_storage_api_host = "http://v0.api.upyun.com"
+ # config.upyun_api_host = "http://v0.api.upyun.com"
# end
#
#
@@ -25,12 +25,12 @@ class UpYun < Abstract
class Connection
def initialize(options={})
- @upyun_storage_username = options[:upyun_storage_username]
- @upyun_storage_userpass = options[:upyun_storage_userpass]
- @upyun_storage_bucket = options[:upyun_storage_bucket]
+ @upyun_username = options[:upyun_username]
+ @upyun_password = options[:upyun_password]
+ @upyun_bucket = options[:upyun_bucket]
@connection_options = options[:connection_options] || {}
@host = options[:api_host] || 'http://v0.api.upyun.com'
- @http = RestClient::Resource.new("#{@host}/#{@upyun_storage_bucket}", @upyun_storage_username, @upyun_storage_userpass)
+ @http = RestClient::Resource.new("#{@host}/#{@upyun_bucket}", @upyun_username, @upyun_password)
end
def put(path, payload, headers = {})
@@ -140,11 +140,11 @@ def uy_connection
if @uy_connection
@uy_connection
else
- config = {:upyun_storage_username => @uploader.upyun_storage_username,
- :upyun_storage_userpass => @uploader.upyun_storage_userpass,
- :upyun_storage_bucket => @uploader.upyun_storage_bucket
+ config = {:upyun_username => @uploader.upyun_username,
+ :upyun_password => @uploader.upyun_password,
+ :upyun_bucket => @uploader.upyun_bucket
}
- config[:api_host] = @uploader.upyun_storage_api_host if @uploader.respond_to?(:upyun_storage_api_host)
+ config[:api_host] = @uploader.upyun_api_host if @uploader.respond_to?(:upyun_api_host)
@uy_connection ||= CarrierWave::Storage::UpYun::Connection.new(config)
end
end
8 lib/carrierwave/upyun/configuration.rb
View
@@ -3,10 +3,10 @@ module UpYun
module Configuration
extend ActiveSupport::Concern
included do
- add_config :upyun_storage_username
- add_config :upyun_storage_userpass
- add_config :upyun_storage_bucket
- add_config :upyun_storage_api_host
+ add_config :upyun_username
+ add_config :upyun_password
+ add_config :upyun_bucket
+ add_config :upyun_api_host
add_config :upyun_bucket_domain
end
end
BIN  spec/.DS_Store
View
Binary file not shown
BIN  spec/foo.gif
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  spec/foo.jpg
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 spec/spec_helper.rb
View
@@ -0,0 +1,36 @@
+require 'rubygems'
+require 'rspec'
+require 'rspec/autorun'
+require 'rails'
+require 'active_record'
+require "carrierwave"
+require 'carrierwave/orm/activerecord'
+require 'carrierwave/processing/mini_magick'
+
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require "carrierwave/upyun"
+
+
+module Rails
+ class <<self
+ def root
+ [File.expand_path(__FILE__).split('/')[0..-3].join('/'),"spec"].join("/")
+ end
+ end
+end
+
+ActiveRecord::Migration.verbose = false
+
+CarrierWave.configure do |config|
+ config.storage = :upyun
+ config.upyun_username = "rspec"
+ config.upyun_password = 'spec123'
+ config.upyun_bucket = "rspec"
+ config.upyun_bucket_domain = "rspec.b0.upaiyun.com"
+end
+
+def load_file(fname)
+ File.open([Rails.root,fname].join("/"))
+end
53 spec/upload_spec.rb
View
@@ -0,0 +1,53 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+require "open-uri"
+ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
+
+describe "Upload" do
+ def setup_db
+ ActiveRecord::Schema.define(:version => 1) do
+ create_table :photos do |t|
+ t.column :image, :string
+ end
+ end
+ end
+
+ def drop_db
+ ActiveRecord::Base.connection.tables.each do |table|
+ ActiveRecord::Base.connection.drop_table(table)
+ end
+ end
+
+ class PhotoUploader < CarrierWave::Uploader::Base
+ include CarrierWave::MiniMagick
+
+
+
+ def store_dir
+ "photos"
+ end
+ end
+
+ class Photo < ActiveRecord::Base
+ mount_uploader :image, PhotoUploader
+ end
+
+
+ before :all do
+ setup_db
+ end
+
+ after :all do
+ drop_db
+ end
+
+ context "Upload Image" do
+ it "does can upload jpg image" do
+ f = load_file("foo.jpg")
+ photo = Photo.create(:image => f)
+ photo.errors.count.should == 0
+ photo.image.url.should == "http://rspec.b0.upaiyun.com/photos/foo.jpg"
+ open(photo.image.url).size.should == f.size
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.