Merge commit 'sr/rack-upload'
This commit is contained in:
commit
74d470ff10
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
<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>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue