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..0e863a4 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].to_yaml + end end __END__ @@ -71,3 +79,11 @@ __END__ @@ hello
Hello, <%= @user %>
Your email is: <%= @email %>
+ +@@ uploader + diff --git a/spec/integration/rack/test/webrat_rack_test.rb b/spec/integration/rack/test/webrat_rack_test.rb index ebe2d3f..ec82973 100644 --- a/spec/integration/rack/test/webrat_rack_test.rb +++ b/spec/integration/rack/test/webrat_rack_test.rb @@ -46,6 +46,17 @@ class WebratRackTest < Test::Unit::TestCase visit "/absolute_redirect" assert_contain "spam" end + + def test_upload_file + visit "/upload" + attach_file "File", __FILE__, "text/ruby" + click_button "Upload" + + upload = YAML.load(response_body) + assert_equal "text/ruby", upload[:type] + assert_equal "webrat_rack_test.rb", upload[:filename] + assert upload[:tempfile].respond_to?(:read) + end end class WebratRackSetupTest < Test::Unit::TestCase