Integration tests for Merb file uploads

This commit is contained in:
Ryan Carver 2009-04-24 14:11:49 -07:00
parent 09509025c3
commit 26edfbc7cb
4 changed files with 26 additions and 0 deletions

View File

@ -4,6 +4,15 @@ class Testing < Application
render
end
def upload
case request.method
when :get then render
when :post then
uploaded_file = params[:uploaded_file]
render [uploaded_file[:filename], uploaded_file[:tempfile].class.name].inspect
end
end
def submit_form
end

View File

@ -0,0 +1,9 @@
<h1>Webrat Form</h1>
<form action="/upload" method="post">
<label>
File
<input type="file" name="uploaded_file" />
</label>
<input type="submit" value="Upload">
</form>

View File

@ -28,6 +28,7 @@
Merb.logger.info("Compiling routes...")
Merb::Router.prepare do
match("/").to(:controller => "testing", :action => "show_form")
match("/upload").to(:controller => "testing", :action => "upload")
match("/internal_redirect").to(:controller => "testing", :action => "internal_redirect")
match("/external_redirect").to(:controller => "testing", :action => "external_redirect")
end

View File

@ -29,4 +29,11 @@ describe "Webrat" do
response = visit "/external_redirect"
response.status.should == 302
end
it "should upload files" do
visit "/upload"
attach_file "File", __FILE__
response = click_button "Upload"
response.should contain(%(["webrat_spec.rb", "Tempfile"]))
end
end