<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Talk Like A Duck: Rails Integration Test File Upload Plugin</title>
    <link>http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>In Ruby, it's not the dog, it's the tricks!</description>
    <item>
      <title>Rails Integration Test File Upload Plugin</title>
      <description>&lt;p&gt;Some time ago, I wrote a rails patch which allows http file uploading in integration tests.&lt;/p&gt;


You just use the same TestUploadedFile class used in functional tests or controller specs if you&amp;#8217;re an RSpec&amp;#8217;er.  So you can do something like.
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;    post '/upload' :file =&amp;gt; TestUploadedFile(&amp;quot;/path/to/blah.txt&amp;quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The patch detects a TestUploaded file amongst the parameters, and converts the request into a proper multi-part request.&lt;/p&gt;


	&lt;p&gt;It will work for both posts and updates.&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re running edge rails you&amp;#8217;ve already got this. But many have asked for a version for earlier rails versions.  At work, I&amp;#8217;ve been working on an RSpec story which requires file uploading, and we&amp;#8217;re using the 2.0.2 gem version of Rails for deployment purposes, so I whipped up a little plugin which patches 2.0.2 Rails with the changes from &lt;a href="http://dev.rubyonrails.org/changeset/8978"&gt;Rails changeset 8978&lt;/a&gt;.  The plugin checks the rails version and throws an exception if it&amp;#8217;s anything other than &amp;#8220;2.0.2&amp;#8221; since I haven&amp;#8217;t tried this with anything earlier, and it&amp;#8217;s not necessary for anything newer.&lt;/p&gt;


	&lt;p&gt;You can get it from git hub at &lt;a href="git://github.com/rubyredrick/integration_upload_plugin.git"&gt;git://github.com/rubyredrick/integration_upload_plugin.git&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;This also marks the first time I&amp;#8217;ve used git for anything but gitting Rubinius.&lt;/p&gt;</description>
      <pubDate>Fri, 18 Apr 2008 18:07:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:7bc970c8-4f95-4be1-aa4a-14e69a6015a4</guid>
      <author>Rick DeNatale</author>
      <link>http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin</link>
      <category>rails</category>
      <category>integration_upload_plugin</category>
      <category>open_source_contributions</category>
      <trackback:ping>http://talklikeaduck.denhaven2.com/articles/trackback/493</trackback:ping>
    </item>
  </channel>
</rss>
