Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow nil store_dir

  • Loading branch information...
commit 6c8197e36252476ee3d1358c644ec1926e95aba4 1 parent 552aca2
Trevor Turk authored February 08, 2010
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
 
2  lib/carrierwave/uploader/store.rb
@@ -39,7 +39,7 @@ def filename
39 39
       # [String] the store path
40 40
       #
41 41
       def store_path(for_file=filename)
42  
-        File.join(store_dir, full_filename(for_file))
  42
+        File.join([store_dir, full_filename(for_file)].compact)
43 43
       end
44 44
 
45 45
       ##
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 notes on commit 6c8197e

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