<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SmartLogic Solutions Blog &#187; integration</title>
	<atom:link href="http://blog.smartlogicsolutions.com/tag/integration/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Properly Setting HTTP_REFERER in a Rails Integration Test for a File Upload</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 00:38:01 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=495</guid>
		<description><![CDATA[This one had me frustrated for the past hour. I&#8217;ve been writing integration tests for a Rails project and got stuck on an error when I was trying to test that a file upload worked successfully and asserted a redirection was occuring correctly, but ran into the following error: Expected response to be a &#60;:redirect&#62;, [...]]]></description>
			<content:encoded><![CDATA[<p>This one had me frustrated for the past hour.  I&#8217;ve been writing integration tests for a Rails project and got stuck on an error when I was trying to test that a file upload worked successfully and asserted a redirection was occuring correctly, but ran into the following error:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">Expected response to be a <span style="color:#006600; font-weight:bold;">&lt;</span>:redirect<span style="color:#006600; font-weight:bold;">&gt;</span>, but was <span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#006666;">500</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#996600;">&quot;No HTTP_REFERER was set in the request to this action, so
redirect_to :back could not be called successfully. If this
is a test, make sure to specify
request.env[<span style="color:#000099;">\&quot;</span>HTTP_REFERER<span style="color:#000099;">\&quot;</span>].&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>

<p>What a lovely error message to send me on a goose chase trying to set HTTP_REFERER directly on the @request as instructed.</p>
<h4>Did Not Work</h4>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@request</span>.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;HTTP_REFERER&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'/'</span>
post upload_path, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> fixture_file_upload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;worddoc.docx&quot;</span>, <span style="color:#996600;">&quot;application/msword&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
  <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:multipart <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
assert_redirected_to <span style="color:#996600;">'/'</span>, <span style="color:#996600;">'index'</span></pre></div></div>

<p>This continued to spit out the same error.  I finally stumbled across <a href="http://redsquirrel.com/cgi-bin/dave/2006/08/index.html">a post back from 2006</a> that held the answer.  The HTTP_REFERER is not set the same way in an integration test:</p>
<h4>Success!</h4>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">post upload_path, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> fixture_file_upload<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;worddoc.docx&quot;</span>, <span style="color:#996600;">&quot;application/msword&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
  <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:multipart <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:referer</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
assert_redirected_to <span style="color:#996600;">'/'</span>, <span style="color:#996600;">'index'</span></pre></div></div>

<p>Hope that saves anyone else some time if you encounter this error.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2007/06/12/struts-11-problems-with-logiciterate-tags-and-cannot-find-bean-xxx-under-any-scope/" rel="bookmark" class="crp_title">Struts 1.1: Problems with logic:iterate tags and &#8220;Cannot find bean XXX under any scope&#8221;</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/08/using-active-x-and-javascript-to-scan-from-your-web-app/" rel="bookmark" class="crp_title">using active x and javascript to scan from your web app</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/23/dont-abuse-the-session/" rel="bookmark" class="crp_title">Don&#8217;t Abuse the Session</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/" rel="bookmark" class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/15/automating-flex-compilation-using-ant/" rel="bookmark" class="crp_title">Automating Flex Compilation Using ANT</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

