sr (owner)

Revisions

  • b2364d sr Thu Jun 25 14:19:50 -0700 2009
gist: 136174 Download_button fork
public
Public Clone URL: git://gist.github.com/136174.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb
index 49c042c..8d8afc2 100644
--- a/lib/webrat/core/elements/field.rb
+++ b/lib/webrat/core/elements/field.rb
@@ -366,6 +366,8 @@ module Webrat
       when :merb
         # TODO: support content_type
         File.new(@value)
+ when :rack
+ Rack::Test::UploadedFile.new(@value, content_type)
       end
     end
 
diff --git a/spec/integration/rack/app.rb b/spec/integration/rack/app.rb
index 61ab332..88907dc 100644
--- a/spec/integration/rack/app.rb
+++ b/spec/integration/rack/app.rb
@@ -33,6 +33,14 @@ class RackApp < Sinatra::Base
     @email = params[:email]
     erb :hello
   end
+
+ get "/upload" do
+ erb :uploader
+ end
+
+ post "/upload" do
+ params[:uploaded_file][:filename]
+ end
 end
 
 __END__
@@ -71,3 +79,11 @@ __END__
 @@ hello
 <p>Hello, <%= @user %></p>
 <p>Your email is: <%= @email %></p>
+
+@@ uploader
+<form action="/upload" method="post">
+ <label>
+ File <input type="file" name="uploaded_file" />
+ </label>
+ <input type="submit" value="Upload">
+</form>
diff --git a/spec/integration/rack/test/webrat_rack_test.rb b/spec/integration/rack/test/webrat_rack_test.rb
index e3d760d..51611b2 100644
--- a/spec/integration/rack/test/webrat_rack_test.rb
+++ b/spec/integration/rack/test/webrat_rack_test.rb
@@ -42,6 +42,14 @@ class WebratRackTest < Test::Unit::TestCase
     visit "/absolute_redirect"
     assert_contain "spam"
   end
+
+ def test_upload_file
+ visit "/upload"
+ attach_file "File", __FILE__
+ click_button "Upload"
+
+ assert_equal "webrat_rack_test.rb", response_body
+ end
 end
 
 class WebratRackSetupTest < Test::Unit::TestCase