Skip to content

Commit

Permalink
Integration tests for Merb file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarver committed Apr 24, 2009
1 parent 0950902 commit 26edfbc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/integration/merb/app/controllers/testing.rb
Expand Up @@ -4,6 +4,15 @@ def show_form
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

Expand Down
9 changes: 9 additions & 0 deletions spec/integration/merb/app/views/testing/upload.html.erb
@@ -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>
1 change: 1 addition & 0 deletions spec/integration/merb/config/router.rb
Expand Up @@ -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
7 changes: 7 additions & 0 deletions spec/integration/merb/spec/webrat_spec.rb
Expand Up @@ -29,4 +29,11 @@
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

0 comments on commit 26edfbc

Please sign in to comment.