<?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>Nutsmuggling &#187; rubyonrails</title>
	<atom:link href="http://davidebenini.it/category/rubyonrails/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidebenini.it</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 29 Apr 2010 10:34:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Faking an IP with Webrat</title>
		<link>http://davidebenini.it/2009/08/29/faking-an-ip-with-webrat/</link>
		<comments>http://davidebenini.it/2009/08/29/faking-an-ip-with-webrat/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 10:42:37 +0000</pubDate>
		<dc:creator>Davide</dc:creator>
				<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[remote_ip]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://davidebenini.it/?p=520</guid>
		<description><![CDATA[Lately I have been diving into TDD, and more specifically BDD, thanks to the wonderful Cucumber testing framework.
Today I have had to test a specifical IP based feature. Simply put, I get the user IP and store it into the database. 
The simple rails way to get a visitor IP address is
request.remote_ip

If you do this [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I have been diving into <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a>, and more specifically <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">BDD</a>, thanks to the wonderful <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">Cucumber</a> testing framework.</p>
<p>Today I have had to test a specifical IP based feature. Simply put, I get the user IP and store it into the database. </p>
<p>The simple rails way to get a visitor IP address is</p>
<pre><code>request.remote_ip
</code></pre>
<p>If you do this while developing you&#8217;ll usually get a predictable</p>
<pre><code>127.0.0.1
</code></pre>
<p>How do I test that my controller puts a correct IP in the database?<br />
At first I thought about creating a mock request object. But this way I would be testing only the saving portion of the method, not the part detecting the IP. In other words, I needed to simulate an IP address at a lower layer.</p>
<p>Webrat to the rescue! Thanks to the nice folks at the webrat irc channel I got an answer. Simply:</p>
<pre><code>header('REMOTE_ADDR', ip_address)
</code></pre>
<p>The Webrat <code>header</code>method lets you set all the header variable of you session. Handy, isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://davidebenini.it/2009/08/29/faking-an-ip-with-webrat/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails 2.3.3 + Ruby 1.8.7 + Gmail SMTP settings</title>
		<link>http://davidebenini.it/2009/06/25/rails-233-ruby-187-gmail-smtp-settings/</link>
		<comments>http://davidebenini.it/2009/06/25/rails-233-ruby-187-gmail-smtp-settings/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 07:11:45 +0000</pubDate>
		<dc:creator>Davide</dc:creator>
				<category><![CDATA[Technolalia]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[1.8.7]]></category>
		<category><![CDATA[2.3.2]]></category>
		<category><![CDATA[actionmailer]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://davidebenini.it/?p=506</guid>
		<description><![CDATA[How to setup Rails to use you gmail smtp without installing any plugin]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not rocket science, but since I took a while to figure this out I thought I&#8217;d share:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:enable_starttls_auto</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
  <span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;smtp.gmail.com&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">587</span>,
  <span style="color:#ff3333; font-weight:bold;">:domain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;your-google-apps-domain&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:plain</span>,
  <span style="color:#ff3333; font-weight:bold;">:user_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;username&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;password&quot;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>The most important line is <code>enable_starttls_auto =&gt; true</code>.</p>
<p>Unlike pre 2.2 Rails, no plugin is required. Not sure this setup works with Rails 2.2 though, never tried it.</p>
<p>Via <a href="http://www.railsforum.com/viewtopic.php?id=28480">this forum discussion</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidebenini.it/2009/06/25/rails-233-ruby-187-gmail-smtp-settings/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Patches for the easy-fckeditor rails plugin</title>
		<link>http://davidebenini.it/2009/03/23/patches-for-the-easy-fckeditor-rails-plugin/</link>
		<comments>http://davidebenini.it/2009/03/23/patches-for-the-easy-fckeditor-rails-plugin/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 17:58:13 +0000</pubDate>
		<dc:creator>Davide</dc:creator>
				<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[easy-fckeditor]]></category>
		<category><![CDATA[fckeditor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[safe_erb]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://davidebenini.it/?p=383</guid>
		<description><![CDATA[A couple of days ago I discovered the wonderful easy-fckeditor Rails plugin. It&#8217;s a fork of the main fckeditor plugin, integrating the EasyUpload plugin. With this marvellous piece of software you can integrate a visual text editor in no time; what is more, file attachments are included out of the box, with no need to [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I discovered the wonderful <a href="http://agilewebdevelopment.com/plugins/easy_fckeditor">easy-fckeditor</a> Rails plugin. It&#8217;s a fork of the main fckeditor plugin, integrating the <a href="http://martinezdelizarrondo.com/easyupload/">EasyUpload</a> plugin. With this marvellous piece of software you can integrate a visual text editor in no time; what is more, file attachments are included out of the box, with no need to implement your own server-side upload actions.</p>
<p>The plugin is fantastic, but there was a small glitch with Rails 2.2, which forbade to upload files. Files upload is an ajaxed action, so you won&#8217;t see any error, unless you use firebug, which revealed this problem:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">undefined method <span style="color:#996600;">'relative_url_root'</span></pre></div></div>

<p>After some googling I found <a href="">this patch</a> which anyway is for the fckeditor plugin. So I tweaked it a bit and here&#8217;s the working patch for easy-fckeditor:</p>
<p><code>app/controllers/fckeditor_controller.rb</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>198
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">uploaded = request.<span style="color:#9900CC;">relative_url_root</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;#{UPLOAD_FOLDER}/#{params[:Type]}&quot;</span></pre></td></tr></table></div>

<p>becomes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>198
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">uploaded = <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">relative_url_root</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;#{UPLOAD_FOLDER}/#{params[:Type]}&quot;</span></pre></td></tr></table></div>

<p><code>lib/fckeditor.rb</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>38
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">js_path = <span style="color:#996600;">&quot;#{controller.relative_url_root}/javascripts&quot;</span></pre></td></tr></table></div>

<p>becomes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>38
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">js_path = <span style="color:#996600;">&quot;#{ActionController::Base.relative_url_root}/javascripts&quot;</span></pre></td></tr></table></div>

<p>There was another small glitch, due to the interaction with <a href="http://github.com/emk/safe_erb/tree/master">safe_erb</a>.<br />
<strong>safe_erb</strong> is a super useful plugin which raises an error whenever unsanitized output is printed. This way you never risk forgetting to sanitize your stuff. The problem here is that html text is necessarily not sanitized, otherwise all the html tags would be lost. The trick here is to tell ruby that he can trust those strings. It&#8217;s not the most secure solution, but I guess it&#8217;s better to have everything but the html text sanitized than nothing&#8230;</p>
<p><code>libfckeditor.rb</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">value = value.<span style="color:#0000FF; font-weight:bold;">nil</span>? ? <span style="color:#996600;">&quot;&quot;</span> : value</pre></td></tr></table></div>

<p>becomes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">value = value.<span style="color:#0000FF; font-weight:bold;">nil</span>? ? <span style="color:#996600;">&quot;&quot;</span> : value.<span style="color:#9900CC;">untaint</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>I sent this patches to Gaston Ramos, the plugin maintainer, but you can follow my code if you stumble into this issues before the patches integration.</p>
<p>Davide</p>
]]></content:encoded>
			<wfw:commentRss>http://davidebenini.it/2009/03/23/patches-for-the-easy-fckeditor-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
