Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge remote branch 'trevorturk/nil_store_dir'

  • Loading branch information...
commit 649d338a6379945edaa63eac9eeafdcba6b24475 2 parents 8c4e478 + cc12d37
Jonas Nicklas jnicklas authored
1  README.rdoc
Source Rendered
@@ -107,6 +107,7 @@ method:
107 107 end
108 108
109 109 This works for the file storage as well as Amazon S3 and Rackspace Cloud Files.
  110 +Define +store_dir+ as +nil+ if you'd like to store files at the root level.
110 111
111 112 == Securing uploads
112 113
4 lib/carrierwave/storage/right_s3.rb
@@ -93,9 +93,9 @@ def delete
93 93 #
94 94 def url
95 95 if @uploader.s3_cnamed
96   - ["http://", @uploader.s3_bucket, @path].compact.join('/')
  96 + ["http://", @uploader.s3_bucket, "/", @path].compact.join
97 97 else
98   - ["http://#{@uploader.s3_bucket}.s3.amazonaws.com", @path].compact.join('/')
  98 + ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
99 99 end
100 100 end
101 101
2  lib/carrierwave/storage/s3.rb
@@ -112,7 +112,7 @@ def url
112 112 if @uploader.s3_cnamed
113 113 ["http://", @uploader.s3_bucket, "/", @path].compact.join
114 114 else
115   - ["http://s3.amazonaws.com", @uploader.s3_bucket, @path].compact.join('/')
  115 + ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
116 116 end
117 117 end
118 118
2  lib/carrierwave/uploader/store.rb
@@ -40,7 +40,7 @@ def filename
40 40 # [String] the store path
41 41 #
42 42 def store_path(for_file=filename)
43   - File.join(store_dir, full_filename(for_file))
  43 + File.join([store_dir, full_filename(for_file)].compact)
44 44 end
45 45
46 46 ##
10 spec/storage/right_s3_spec.rb
@@ -39,7 +39,15 @@
39 39 it "should have an Amazon URL" do
40 40 @s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
41 41 end
42   -
  42 +
  43 + context "with cnamed bucket" do
  44 + it "should have a CNAMED URL" do
  45 + @uploader.stub!(:s3_cnamed).and_return(true)
  46 + @uploader.stub!(:s3_bucket).and_return('foo.bar')
  47 + @s3_file.url.should == 'http://foo.bar/uploads/bar.txt'
  48 + end
  49 + end
  50 +
43 51 it "should be deletable" do
44 52 @s3_file.delete
45 53 lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
16 spec/uploader/store_spec.rb
@@ -169,6 +169,22 @@ def filename; "foo.jpg"; end
169 169 end
170 170 end
171 171
  172 + describe 'without a store dir' do
  173 + before do
  174 + @uploader_class.class_eval do
  175 + def store_dir; nil; end
  176 + end
  177 + end
  178 +
  179 + it "should create a new file with a valid path and url" do
  180 + @file = File.open(file_path('test.jpg'))
  181 + @uploader.store!(@file)
  182 + @path = ::File.expand_path(@uploader.store_path, @uploader.root)
  183 + File.exist?(@path).should be_true
  184 + @uploader.url.should == '/test.jpg'
  185 + end
  186 + end
  187 +
172 188 describe 'with an overridden, reversing, filename' do
173 189 before do
174 190 @uploader_class.class_eval do

0 comments on commit 649d338

Please sign in to comment.
Something went wrong with that request. Please try again.