public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
Update to file upload testing [#101 state:resolved]
dsutedja (author)
Mon Aug 18 05:31:41 -0700 2008
commit  c48498d7606d3484506fc0d9ef5382c561d421c5
tree    944118836ae8dd7764696c9df7f938753312cfe5
parent  afc26c3570fb97c4509caf7c25ef923d8a46f8d0
...
 
1
2
3
...
1
2
3
4
0
@@ -1,3 +1,4 @@
0
+* [#101] Update to file upload testing (build_file -> file_for_upload, and multipart support in put)
0
 * [#96] Distributed Views module now uses file cache
0
 * [#92] Removed deprecated app_config.orm code.
0
 * [#91] Fixed Mack blowing up if there is no config/initializers/gems.rb file.
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 require 'base64'
0
 module Mack
0
   module Testing
0
-    class FileWrapper
0
+    class FileWrapper # :nodoc:
0
       
0
       attr_reader :path
0
       attr_reader :file_name
...
80
81
82
83
 
 
 
 
 
 
84
85
86
 
 
87
88
89
...
80
81
82
 
83
84
85
86
87
88
89
90
 
91
92
93
94
95
0
@@ -80,10 +80,16 @@ module Mack
0
     
0
       # Performs a 'put' request for the specified uri.
0
       def put(uri, options = {})
0
-        build_response(request.put(uri, build_request_options({:input => options.to_params})))
0
+        if options[:multipart]
0
+          form_input = build_multipart_data(options)
0
+          build_response(request.post(uri, build_request_options({"CONTENT_TYPE" => "multipart/form-data, boundary=Mack-boundary", "CONTENT_LENGTH" => form_input.size, :input => form_input})))
0
+        else
0
+          build_response(request.put(uri, build_request_options({:input => options.to_params})))
0
+        end
0
       end
0
       
0
-      def build_file(path)
0
+      # create a wrapper object for file upload testing.
0
+      def file_for_upload(path)
0
         return Mack::Testing::FileWrapper.new(path)
0
       end
0
           
...
3
4
5
6
 
7
8
9
...
11
12
13
14
 
15
16
17
...
3
4
5
 
6
7
8
9
...
11
12
13
 
14
15
16
17
0
@@ -3,7 +3,7 @@ require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
 
0
 describe "File Upload Request" do
0
   it "should generate proper multipart content" do
0
-    post upload_file_url, :multipart => true, :file0 => build_file(File.join(File.dirname(__FILE__), "images", "homer_brain.jpg")), :album => 'simpsons'
0
+    post upload_file_url, :multipart => true, :file0 => file_for_upload(File.join(File.dirname(__FILE__), "images", "homer_brain.jpg")), :album => 'simpsons'
0
     assigns(:saved_file_name).should_not be_nil
0
     assigns(:saved_file_name).should == "homer_brain.jpg"
0
     assigns(:album).should_not be_nil
0
@@ -11,7 +11,7 @@ describe "File Upload Request" do
0
   end
0
   
0
   it "should be able to upload multiple files" do  
0
-    post upload_multiple_url, :multipart => true, :file0 => build_file(File.join(File.dirname(__FILE__), "images", "homer_brain.jpg")), :file1 => build_file(File.join(File.dirname(__FILE__), "images", "homer_brain2.jpg"))
0
+    post upload_multiple_url, :multipart => true, :file0 => file_for_upload(File.join(File.dirname(__FILE__), "images", "homer_brain.jpg")), :file1 => file_for_upload(File.join(File.dirname(__FILE__), "images", "homer_brain2.jpg"))
0
     assigns(:saved_file1).should_not be_nil
0
     assigns(:saved_file2).should_not be_nil
0
     assigns(:saved_file1).should == "homer_brain.jpg"

Comments