Browse files

Merge remote branch 'trevorturk/nil_store_dir'

  • Loading branch information...
2 parents 8c4e478 + cc12d37 commit 649d338a6379945edaa63eac9eeafdcba6b24475 @jnicklas jnicklas committed Feb 8, 2010
View
1 README.rdoc
@@ -107,6 +107,7 @@ method:
end
This works for the file storage as well as Amazon S3 and Rackspace Cloud Files.
+Define +store_dir+ as +nil+ if you'd like to store files at the root level.
== Securing uploads
View
4 lib/carrierwave/storage/right_s3.rb
@@ -93,9 +93,9 @@ def delete
#
def url
if @uploader.s3_cnamed
- ["http://", @uploader.s3_bucket, @path].compact.join('/')
+ ["http://", @uploader.s3_bucket, "/", @path].compact.join
else
- ["http://#{@uploader.s3_bucket}.s3.amazonaws.com", @path].compact.join('/')
+ ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
end
end
View
2 lib/carrierwave/storage/s3.rb
@@ -112,7 +112,7 @@ def url
if @uploader.s3_cnamed
["http://", @uploader.s3_bucket, "/", @path].compact.join
else
- ["http://s3.amazonaws.com", @uploader.s3_bucket, @path].compact.join('/')
+ ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
end
end
View
2 lib/carrierwave/uploader/store.rb
@@ -40,7 +40,7 @@ def filename
# [String] the store path
#
def store_path(for_file=filename)
- File.join(store_dir, full_filename(for_file))
+ File.join([store_dir, full_filename(for_file)].compact)
end
##
View
10 spec/storage/right_s3_spec.rb
@@ -39,7 +39,15 @@
it "should have an Amazon URL" do
@s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
end
-
+
+ context "with cnamed bucket" do
+ it "should have a CNAMED URL" do
+ @uploader.stub!(:s3_cnamed).and_return(true)
+ @uploader.stub!(:s3_bucket).and_return('foo.bar')
+ @s3_file.url.should == 'http://foo.bar/uploads/bar.txt'
+ end
+ end
+
it "should be deletable" do
@s3_file.delete
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
View
16 spec/uploader/store_spec.rb
@@ -169,6 +169,22 @@ def filename; "foo.jpg"; end
end
end
+ describe 'without a store dir' do
+ before do
+ @uploader_class.class_eval do
+ def store_dir; nil; end
+ end
+ end
+
+ it "should create a new file with a valid path and url" do
+ @file = File.open(file_path('test.jpg'))
+ @uploader.store!(@file)
+ @path = ::File.expand_path(@uploader.store_path, @uploader.root)
+ File.exist?(@path).should be_true
+ @uploader.url.should == '/test.jpg'
+ end
+ end
+
describe 'with an overridden, reversing, filename' do
before do
@uploader_class.class_eval do

0 comments on commit 649d338

Please sign in to comment.