Skip to content
This repository
Browse code

delegate to the @tempfile instance variable

  • Loading branch information...
commit c4528deec12d738f537745ff1622756db497cb05 1 parent 1e50fae
Aaron Patterson authored
18  actionpack/lib/action_dispatch/http/upload.rb
@@ -2,27 +2,19 @@
2 2
 
3 3
 module ActionDispatch
4 4
   module Http
5  
-    class UploadedFile < Tempfile
  5
+    class UploadedFile
6 6
       attr_accessor :original_filename, :content_type, :tempfile, :headers
7 7
 
8 8
       def initialize(hash)
9 9
         @original_filename = hash[:filename]
10 10
         @content_type      = hash[:type]
11 11
         @headers           = hash[:head]
12  
-
13  
-        # To the untrained eye, this may appear as insanity. Given the alternatives,
14  
-        # such as busting the method cache on every request or breaking backwards
15  
-        # compatibility with is_a?(Tempfile), this solution is the best available
16  
-        # option.
17  
-        #
18  
-        # TODO: Deprecate is_a?(Tempfile) and define a real API for this parameter
19  
-        tempfile = hash[:tempfile]
20  
-        tempfile.instance_variables.each do |ivar|
21  
-          instance_variable_set(ivar, tempfile.instance_variable_get(ivar))
22  
-        end
  12
+        @tempfile          = hash[:tempfile]
23 13
       end
24 14
 
25  
-      alias local_path path
  15
+      def method_missing(name, *args, &block)
  16
+        @tempfile.send(name, *args, &block)
  17
+      end
26 18
     end
27 19
 
28 20
     module Upload
18  actionpack/test/dispatch/uploaded_file_test.rb
@@ -21,5 +21,23 @@ def test_tempfile
21 21
       uf = Http::UploadedFile.new(:tempfile => 'foo')
22 22
       assert_equal 'foo', uf.tempfile
23 23
     end
  24
+
  25
+    def test_delegates_to_tempfile
  26
+      tf = Class.new { def tenderlove; 'thunderhorse' end }
  27
+      uf = Http::UploadedFile.new(:tempfile => tf.new)
  28
+      assert_equal 'thunderhorse', uf.tenderlove
  29
+    end
  30
+
  31
+    def test_delegates_to_tempfile_with_params
  32
+      tf = Class.new { def tenderlove *args; args end }
  33
+      uf = Http::UploadedFile.new(:tempfile => tf.new)
  34
+      assert_equal %w{ thunder horse }, uf.tenderlove(*%w{ thunder horse })
  35
+    end
  36
+
  37
+    def test_delegates_to_tempfile_with_block
  38
+      tf = Class.new { def tenderlove; yield end }
  39
+      uf = Http::UploadedFile.new(:tempfile => tf.new)
  40
+      assert_equal('thunderhorse', uf.tenderlove { 'thunderhorse' })
  41
+    end
24 42
   end
25 43
 end

0 notes on commit c4528de

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