Skip to content

Commit

Permalink
Implement file uploading for :rack
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Jun 25, 2009
1 parent f2882ef commit 3760867
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/webrat/core/elements/field.rb
Expand Up @@ -366,6 +366,8 @@ def test_uploaded_file
when :merb
# TODO: support content_type
File.new(@value)
when :rack
Rack::Test::UploadedFile.new(@value, content_type)
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/integration/rack/app.rb
Expand Up @@ -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__
Expand Down Expand Up @@ -71,3 +79,11 @@ class RackApp < Sinatra::Base
@@ 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>
11 changes: 11 additions & 0 deletions spec/integration/rack/test/webrat_rack_test.rb
Expand Up @@ -42,6 +42,17 @@ def test_absolute_url_redirect
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
Expand Down

0 comments on commit 3760867

Please sign in to comment.