<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Rails Thoughts</title>
	
	<link>http://rails.anyware-technologies.com.br</link>
	<description>Anyware Rails Blog</description>
	<lastBuildDate>Wed, 07 Oct 2009 14:22:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/com/jRcm" /><feedburner:info uri="com/jrcm" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>“resource libraries” polemic!</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/7466BBcaWOA/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/10/07/resource-libraries-polemic/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 14:22:02 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Inherited Resources]]></category>
		<category><![CDATA[Resource Logic]]></category>
		<category><![CDATA[resource_controller]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=155</guid>
		<description><![CDATA[I&#8217;ve been off for a while but I&#8217;m planning to come back now that I resolved most of my personal and professional life issues that were not letting any time for me to write here.
I&#8217;ve been fond of Resource Libraries since I discovered resource_controller devolved by James Golick.
I&#8217;ve read some good stuff about ResourceLogic by [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been off for a while but I&#8217;m planning to come back now that I resolved most of my personal and professional life issues that were not letting any time for me to write here.</p>
<p>I&#8217;ve been fond of Resource Libraries since I discovered resource_controller devolved by James Golick.</p>
<p>I&#8217;ve read some good stuff about ResourceLogic by Ben Johnson (the creator of Authlogic).</p>
<p>More recently emerged Inherited Resources by José Valim that claims to resolve many issues that resource_controller and ResourceLogic had.</p>
<p>I did not have time to study Inherited Resources or even to use it yet, but I suggest that you read <a href="http://www.binarylogic.com/2009/10/06/discontinuing-resourcelogic/">the reasons why Ben Johnson decided to discontinue ResourceLogic development</a>.</p>
<p>My personal opinion is: I&#8217;ll still use Resource Libraries when it is appropriate. Like everything, you must always ask yourself if it is pertinent to use it for this particular task, piece of code, controller, application, plugin, gem&#8230;</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/7466BBcaWOA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/10/07/resource-libraries-polemic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/10/07/resource-libraries-polemic/</feedburner:origLink></item>
		<item>
		<title>TDD on Rails #4: RSpec, Authlogic, Factory_girl and resource_controller</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/S_J_5KjUmaA/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/21/tdd-on-rails-4-rspec-authlogic-factory_girl-and-resource_controller/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 01:09:10 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[factory_girl]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[resource_controller]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=99</guid>
		<description><![CDATA[So well, I decided to use RSpec, Authlogic, Factory_Girl and resource_controller on my new application! But I&#8217;ve encountered some problems making all these working together. I mean I did not find any good tutorial showing how to do it step by step, so there it is!

The setup:

rails 2.3.2
rubygems 1.3.2
ruby 1.8.6
Mac OS X Leopard
Textmate
rspec 1.2.4
rspec-rails 1.2.4
authlogic [...]]]></description>
			<content:encoded><![CDATA[<p>So well, I decided to use RSpec, Authlogic, Factory_Girl and resource_controller on my new application! But I&#8217;ve encountered some problems making all these working together. I mean I did not find any good tutorial showing how to do it step by step, so there it is!</p>
<p><span id="more-99"></span><br />
<strong>The setup:</strong></p>
<ul>
<li>rails 2.3.2</li>
<li>rubygems 1.3.2</li>
<li>ruby 1.8.6</li>
<li>Mac OS X Leopard</li>
<li>Textmate</li>
<li>rspec 1.2.4</li>
<li>rspec-rails 1.2.4</li>
<li>authlogic 2.0.9</li>
<li>factory_girl 1.2.1</li>
<li>giraffesoft-resource_controller 0.6.1</li>
</ul>
<p><!--more--><br />
<!--more--><br />
Let&#8217;s <strong>install</strong> all the things we need:</p>
<p><!--more--></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rails thoughts<br />
gem source -a http://gems.github.com<br />
sudo gem install  thoughtbot-factory_girl authlogic rspec rspec-rails giraffesoft-resource_controller</div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Let&#8217;s <strong>configure</strong> this in our new app. The environment.rb should look like this:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;authlogic&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&gt;= 2.0.9&quot;</span><br />
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;giraffesoft-resource_controller&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;resource_controller&quot;</span>, &nbsp;<span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&gt;= 0.6.1&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:source</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;git://github.com/giraffesoft/resource_controller.git&quot;</span><br />
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;rspec&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&gt;= 1.2.4&quot;</span> <br />
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;rspec-rails&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&gt;= 1.2.4&quot;</span> <br />
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;thoughtbot-factory_girl&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;factory_girl&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&gt;= 1.2.1&quot;</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<strong>Make sure you put the authlogic dependency before the resource_controller dependency</strong> because if you don&#8217;t, you&#8217;ll end up with the following error every first access to the app:<br />
<em>You must activate the Authlogic::Session::Base.controller with a controller object before creating objects</em><br />
<!--more--><br />
<!--more--><br />
<strong>Settin up Authlogic:</strong></p>
<p>For the authlogic part, I&#8217;ll basically follow <a href="http://github.com/binarylogic/authlogic_example/tree/master">the official tutorial</a> modifying a little so I get more generated testing code. Read the tutorial if you want to have more information about the following. I&#8217;ll put a <em>#TDD on Rails</em> comment on the like I changed from the official tutorial.<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color:#006600; font-weight:bold;">/</span>script<span style="color:#006600; font-weight:bold;">/</span>generate session user_session<br />
.<span style="color:#006600; font-weight:bold;">/</span>script<span style="color:#006600; font-weight:bold;">/</span>generate rspec_model user <span style="color:#008000; font-style:italic;">#TDD on rails</span><br />
.<span style="color:#006600; font-weight:bold;">/</span>script<span style="color:#006600; font-weight:bold;">/</span>generate rspec_controller user_sessions <span style="color:#008000; font-style:italic;">#TDD on rails</span><br />
.<span style="color:#006600; font-weight:bold;">/</span>script<span style="color:#006600; font-weight:bold;">/</span>generate rspec_controller users <span style="color:#008000; font-style:italic;">#TDD on rails</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Modify your user migration so it looks like this:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> CreateUsers <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span><br />
&nbsp; &nbsp; create_table <span style="color:#ff3333; font-weight:bold;">:users</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:login</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, you can use email instead, or both</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:email</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, you can use login instead, or both</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:crypted_password</span>, &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, see below</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:password_salt</span>, &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, but highly recommended</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:persistence_token</span>, &nbsp; <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># required</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:single_access_token</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::Params</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:perishable_token</span>, &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::Perishability</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">integer</span> &nbsp; <span style="color:#ff3333; font-weight:bold;">:login_count</span>, &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span> <span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">integer</span> &nbsp; <span style="color:#ff3333; font-weight:bold;">:failed_login_count</span>, &nbsp;<span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span> <span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#9900CC;">datetime</span> &nbsp;<span style="color:#ff3333; font-weight:bold;">:last_request_at</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#9900CC;">datetime</span> &nbsp;<span style="color:#ff3333; font-weight:bold;">:current_login_at</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#9900CC;">datetime</span> &nbsp;<span style="color:#ff3333; font-weight:bold;">:last_login_at</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:current_login_ip</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:last_login_ip</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># optional, see Authlogic::Session::MagicColumns</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#9900CC;">timestamps</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span><br />
&nbsp; &nbsp; drop_table <span style="color:#ff3333; font-weight:bold;">:users</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Modify your model:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
&nbsp; acts_as_authentic <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># c.my_config_option = my_value # for available options see documentation in: Authlogic::ActsAsAuthentic</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># block optional</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Modify the user_sessions_controller.rb:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> UserSessionsController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController<br />
&nbsp; before_filter <span style="color:#ff3333; font-weight:bold;">:require_no_user</span>, <span style="color:#ff3333; font-weight:bold;">:only</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:new</span>, <span style="color:#ff3333; font-weight:bold;">:create</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; before_filter <span style="color:#ff3333; font-weight:bold;">:require_user</span>, <span style="color:#ff3333; font-weight:bold;">:only</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:destroy</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> new<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user_session</span> = UserSession.<span style="color:#9900CC;">new</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> create<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user_session</span> = UserSession.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_session</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user_session</span>.<span style="color:#9900CC;">save</span><br />
&nbsp; &nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Login successful!&quot;</span><br />
&nbsp; &nbsp; &nbsp; redirect_back_or_default account_url<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:new</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> destroy<br />
&nbsp; &nbsp; current_user_session.<span style="color:#9900CC;">destroy</span><br />
&nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Logout successful!&quot;</span><br />
&nbsp; &nbsp; redirect_back_or_default new_user_session_url<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Create a /app/views/user_sessions/new.html.erb:</p>
<div class="codecolorer-container html4strict vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span>Login<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
&nbsp;<br />
<span style="color: #009900;">&lt;% form_for @user_session, :url <span style="color: #66cc66;">=</span>&gt;</span> user_session_path do |f| %&gt;<br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.error_messages %&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.<span style="color: #000066;">label</span> :login %&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.text_field :login %&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.<span style="color: #000066;">label</span> :password %&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.password_field :password %&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.check_box :remember_me %&gt;&lt;%<span style="color: #66cc66;">=</span> f.<span style="color: #000066;">label</span> :remember_me %&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> f.submit <span style="color: #ff0000;">&quot;Login&quot;</span> %&gt;</span><br />
<span style="color: #009900;">&lt;% end %&gt;</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Here is your users_controller:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> UsersController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController<br />
&nbsp; before_filter <span style="color:#ff3333; font-weight:bold;">:require_no_user</span>, <span style="color:#ff3333; font-weight:bold;">:only</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:new</span>, <span style="color:#ff3333; font-weight:bold;">:create</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; before_filter <span style="color:#ff3333; font-weight:bold;">:require_user</span>, <span style="color:#ff3333; font-weight:bold;">:only</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:show</span>, <span style="color:#ff3333; font-weight:bold;">:edit</span>, <span style="color:#ff3333; font-weight:bold;">:update</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> new<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">new</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> create<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">save</span><br />
&nbsp; &nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Account registered!&quot;</span><br />
&nbsp; &nbsp; &nbsp; redirect_back_or_default account_url<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:new</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user</span> = <span style="color:#0066ff; font-weight:bold;">@current_user</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp;<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> edit<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user</span> = <span style="color:#0066ff; font-weight:bold;">@current_user</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> update<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@user</span> = <span style="color:#0066ff; font-weight:bold;">@current_user</span> <span style="color:#008000; font-style:italic;"># makes our views &quot;cleaner&quot; and more consistent</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Account updated!&quot;</span><br />
&nbsp; &nbsp; &nbsp; redirect_to account_url<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:edit</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
Grab the users_controller views from the official tutorial: <a href="http://github.com/binarylogic/authlogic_example/tree/5819a13477797d758cb6871f475ed1c54bf8a3a7/app/views/users">users_controller view</a>.<br />
<!--more--><br />
<!--more--><br />
The application_controller.rb:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># Filters added to this controller apply to all controllers in the application.</span><br />
<span style="color:#008000; font-style:italic;"># Likewise, all the methods added will be available for all controllers.</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span><br />
&nbsp; helper <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#008000; font-style:italic;"># include all helpers, all the time</span><br />
&nbsp; protect_from_forgery <span style="color:#008000; font-style:italic;"># See ActionController::RequestForgeryProtection for details</span><br />
&nbsp; helper_method <span style="color:#ff3333; font-weight:bold;">:current_user_session</span>, <span style="color:#ff3333; font-weight:bold;">:current_user</span><br />
&nbsp; filter_parameter_logging <span style="color:#ff3333; font-weight:bold;">:password</span>, <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span><br />
&nbsp; <br />
&nbsp; private<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> current_user_session<br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0066ff; font-weight:bold;">@current_user_session</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>@current_user_session<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@current_user_session</span> = UserSession.<span style="color:#9900CC;">find</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> current_user<br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0066ff; font-weight:bold;">@current_user</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>@current_user<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@current_user</span> = current_user_session <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> current_user_session.<span style="color:#9900CC;">record</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> require_user<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">unless</span> current_user<br />
&nbsp; &nbsp; &nbsp; &nbsp; store_location<br />
&nbsp; &nbsp; &nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;You must be logged in to access this page&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; redirect_to new_user_session_url<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> require_no_user<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> current_user<br />
&nbsp; &nbsp; &nbsp; &nbsp; store_location<br />
&nbsp; &nbsp; &nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;You must be logged out to access this page&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; redirect_to account_url<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> store_location<br />
&nbsp; &nbsp; &nbsp; session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return_to</span><span style="color:#006600; font-weight:bold;">&#93;</span> = request.<span style="color:#9900CC;">request_uri</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> redirect_back_or_default<span style="color:#006600; font-weight:bold;">&#40;</span>default<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; redirect_to<span style="color:#006600; font-weight:bold;">&#40;</span>session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return_to</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> default<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:return_to</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">nil</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># Scrub sensitive parameters from your log</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># filter_parameter_logging :password</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
Now let&#8217;s configure the routes.rb:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">map.<span style="color:#9900CC;">resource</span> <span style="color:#ff3333; font-weight:bold;">:user_session</span><br />
map.<span style="color:#9900CC;">resource</span> <span style="color:#ff3333; font-weight:bold;">:account</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;users&quot;</span><br />
map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:users</span><br />
map.<span style="color:#9900CC;">root</span> <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;user_sessions&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;new&quot;</span> <span style="color:#008000; font-style:italic;"># optional, this just sets the root route</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
That should do it.<br />
<!--more--><br />
<!--more--><br />
<strong>Using RSepc:</strong><br />
<!--more--><br />
Obviously we did not do much more than the official tutorial did in the first place&#8230; We just generated the test code using the rspec generating scripts. So let&#8217;s get started with the testing part! First let&#8217;s configure the Rspec part and see if we already some test failing:<br />
<!--more--></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./script/generate rspec<br />
rake db:migrate RAILS_ENV=test<br />
spec spec</div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Yeah! we already have all the rspec/controller/model testing stuff created. And we even have 1 of the 5 tests failing! And that&#8217;s our user model because it need to have the right attributes and does not (rspec model generation script create test for an empty model).<br />
<!--more--><br />
Make the test pass modifying the /spec/models/user_spec.rb file like this:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../spec_helper'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
describe User <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@valid_attributes</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:login</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;NewUser&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;12345678&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;12345678&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;newuser@newuser.com&quot;</span>,<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; it <span style="color:#996600;">&quot;should create a new instance given valid attributes&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; User.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>@valid_attributes<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Sweet! But we did not use the factory_girl fixtures replacement yet.<br />
<!--more--><br />
<!--more--><br />
<strong>Factory_girl:</strong><br />
<!--more--><br />
<!--more--><br />
Let&#8217;s do: add <em>require &#8216;factory_girl&#8217;</em> in your /spec/spec_helper.rb. Delete the /spec/fixtures folder. And create the following file: /spec/factories/users.rb<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:valid_user</span> , :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> User <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; u.<span style="color:#9900CC;">login</span> <span style="color:#996600;">&quot;mathieu&quot;</span><br />
&nbsp; u.<span style="color:#9900CC;">password</span> <span style="color:#996600;">&quot;mathieu&quot;</span><br />
&nbsp; u.<span style="color:#9900CC;">password_confirmation</span> <span style="color:#996600;">&quot;mathieu&quot;</span><br />
&nbsp; u.<span style="color:#9900CC;">email</span> <span style="color:#996600;">&quot;mathieu.rousseau.31@gmail.com&quot;</span><br />
&nbsp; u.<span style="color:#9900CC;">single_access_token</span> <span style="color:#996600;">&quot;k3cFzLIQnZ4MHRmJvJzg&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:invalid_user</span> , :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> User <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Then create 2 new examples in  your /spec/models/user_spec.rb file:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">it <span style="color:#996600;">&quot;should succeed creating a new :valid_user from the Factory&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:valid_user</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
it <span style="color:#996600;">&quot;should invalid :invalid_user factory&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; Factory.<span style="color:#9900CC;">build</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:invalid_user</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> be_invalid<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Let&#8217;s see what we&#8217;ve done here: we created a new User object from the :valid_user object of the User factory and persisted it: Factory.create(:valid_user). And that&#8217;s just all we need to do as the create method automatically saves the user so that if it were invalid it would fail.<br />
Then we built another User object from a invalid user from the factory: the build method does not save the User it does not fail building the user. And we make sure that the example tests if the created user is indeed invalid!<br />
<!--more--><br />
<!--more--><br />
Simple isn&#8217;t it? So we tested the basic User part of the authlogic API but there is much more to do.<br />
<!--more--><br />
<!--more--><br />
<strong>The rest of the app: resource_controller and testing authenticated controllers with authlogic and Rspec:</strong><br />
<!--more--><br />
Let&#8217;s test the controller part, and that&#8217;s where I struggled a little. But before let&#8217;s create a little more stuff for our Thoughts app: Thought model and controller (using the resource_controller api) so it respect the following:<br />
- a User has many thoughts<br />
- a Thought belongs to 1 user<br />
- You need to be authenticated to be able to create or delete thoughts<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color:#006600; font-weight:bold;">/</span>script<span style="color:#006600; font-weight:bold;">/</span>generate scaffold_resource Thought title:<span style="color:#CC0066; font-weight:bold;">string</span> description:<span style="color:#CC0066; font-weight:bold;">string</span> user_id:<span style="color:#CC0066; font-weight:bold;">integer</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
Add <em>has_many :thoughts</em> to the user.rb model and <em>belongs_to :user</em> to the thought.rb model.<br />
<!--more--><br />
The title, description and user_id of the thoughts table cannot be null:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> CreateThoughts <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span><br />
&nbsp; &nbsp; create_table <span style="color:#ff3333; font-weight:bold;">:thoughts</span>, <span style="color:#ff3333; font-weight:bold;">:force</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:description</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
<br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#9900CC;">timestamps</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span><br />
&nbsp; &nbsp; drop_table <span style="color:#ff3333; font-weight:bold;">:thoughts</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
And the Thought model should reflect that:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Thought <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
&nbsp; belongs_to <span style="color:#ff3333; font-weight:bold;">:user</span><br />
&nbsp; validates_presence_of <span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#ff3333; font-weight:bold;">:on</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;can't be blank&quot;</span><br />
&nbsp; validates_presence_of <span style="color:#ff3333; font-weight:bold;">:description</span>, <span style="color:#ff3333; font-weight:bold;">:on</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;can't be blank&quot;</span><br />
&nbsp; validates_presence_of <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#ff3333; font-weight:bold;">:on</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;can't be blank&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
Here is the thought migration:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> CreateThoughts <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span><br />
&nbsp; &nbsp; create_table <span style="color:#ff3333; font-weight:bold;">:thoughts</span>, <span style="color:#ff3333; font-weight:bold;">:force</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:description</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
<br />
&nbsp; &nbsp; &nbsp; t.<span style="color:#9900CC;">timestamps</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span><br />
&nbsp; &nbsp; drop_table <span style="color:#ff3333; font-weight:bold;">:thoughts</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Now you should end up with 54 examples which one of them should be failing: the Thought model spec is complaining that User, Title and description should not be blank. Let&#8217;s fix the /spec/models/thought_spec.rb spec and the thoughts.rb factory:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#/spec/factories/thoughts.rb</span><br />
Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:valid_thought</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Thought <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; t.<span style="color:#9900CC;">title</span> <span style="color:#996600;">&quot;First thought&quot;</span><br />
&nbsp; t.<span style="color:#9900CC;">description</span> <span style="color:#996600;">&quot;First thought description&quot;</span><br />
&nbsp; t.<span style="color:#9900CC;">user</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span> u.<span style="color:#9900CC;">association</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:valid_user</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:invalid_thought</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Thought <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>!<span style="color:#006600; font-weight:bold;">--</span>more<span style="color:#006600; font-weight:bold;">--&gt;</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>!<span style="color:#006600; font-weight:bold;">--</span>more<span style="color:#006600; font-weight:bold;">--&gt;</span><br />
<span style="color:#008000; font-style:italic;">#/spec/models/thought_spec.rb</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../spec_helper'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
describe Thought <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@thought</span> = Factory.<span style="color:#9900CC;">build</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:valid_thought</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; it <span style="color:#996600;">&quot;should be valid&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@thought</span>.<span style="color:#9900CC;">should</span> be_valid<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@thought</span>.<span style="color:#9900CC;">save</span>!<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; it <span style="color:#996600;">&quot;should be invalid&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; Factory.<span style="color:#9900CC;">build</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:invalid_thought</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> be_invalid<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
Allright, now let&#8217;s see the thoughts_controller_spec.rb file: resource_controller created it and has not less than 28 examples. Nice but it all pass&#8230; and we should not be able to access the thought controller without being authenticated&#8230;<br />
<!--more--><br />
Let&#8217;s add the following to the /spec/controllers/thoughts_controller_spec.rb file:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">describe <span style="color:#996600;">&quot;shouble be authenticated&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; it <span style="color:#996600;">&quot;should fail if we are not authenticated&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; get <span style="color:#ff3333; font-weight:bold;">:index</span><br />
&nbsp; &nbsp; response.<span style="color:#9900CC;">should_not</span> be_success<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
This test is failing as expected, let&#8217;s force the authentication on our thoughts_controller adding the following: <em>before_filter :require_user</em>.<br />
<!--more--><br />
Now the test is passing but 27 other tests are failing. And that&#8217;s just what we wanted to do: non-authenticated test should not pass. Few things needs to be done:</p>
<ul>
<li>add <em>require &#8216;authlogic/test_case&#8217;</em> in our spec_helper.rb file</li>
<li>active authlogic in our spec</li>
<li>create a valid session before executing out examples</li>
</ul>
<p><!--more--><br />
To activate authlogic and create a new session for our test, we need to nest the resource_controller created tests inside the following:<br />
<!--more--></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">describe <span style="color:#996600;">&quot;Authenticated examples&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; activate_authlogic<br />
&nbsp; &nbsp; UserSession.<span style="color:#9900CC;">create</span> Factory.<span style="color:#9900CC;">build</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:valid_user</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;">#resource_controller generated tests</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><!--more--><br />
<!--more--><br />
When I first tried to make this work, I tried to activate authlogic and create the session in a before(:all) block. But as the controller is instantiated only before each example, the before(:all) block has no control over the controller and authlogic can not be activated nor can we create a UserSession. So we need to do this in the before(:each) block and don&#8217;t forget not to include the example we coded into this description because it is testing the opposite: we should be authenticated to access the thought controller.<br />
<!--more--><br />
<!--more--><br />
There is obviously much more work to be done on the &#8220;Thoughts&#8221; application: let one see only his thoughts and such. But I think I made my point and I&#8217;ll let you do the rest.<br />
<!--more--><br />
<!--more--><br />
<strong>Problems:</strong></p>
<p>I faced a very peculiar problem when the users in my User&#8217;s Factory were automatically created (and persisted) before running the test and made most of my tests fail&#8230; The only solution i found was to delete the /db/test.sqlite file.<br />
<!--more--><br />
<!--more--><br />
I&#8217;d love to have some feedback and suggestion about this article! :-)<br />
<!--more--><br />
<!--more--><br />
The application created here is available on my github account: <a href="http://github.com/anyware/thoughts/tree/master">http://github.com/anyware/thoughts/tree/master</a><br />
<!--more--><br />
To get the version as it is at the end of this post, just do:<br />
<!--more--></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">git clone git://github.com/anyware/thoughts.git<br />
git checkout 55fa648023d2f17d9dd7d5e76eee3e45d6e1c037</div></td></tr></tbody></table></div>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/S_J_5KjUmaA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/21/tdd-on-rails-4-rspec-authlogic-factory_girl-and-resource_controller/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/21/tdd-on-rails-4-rspec-authlogic-factory_girl-and-resource_controller/</feedburner:origLink></item>
		<item>
		<title>Pimp my test on Mac with Growl</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/UMIuk9y219M/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/15/pimp-my-test-on-mac-with-growl/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 02:30:04 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[ZenTest]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=97</guid>
		<description><![CDATA[Please see this very good tip on how to integrate ZenTest autotest with growl: Pimp You .autotest
Splendid!
]]></description>
			<content:encoded><![CDATA[<p>Please see this very good tip on how to integrate ZenTest autotest with growl: <a href="http://www.bitcetera.com/en/techblog/2009/04/09/pimp-your-autotest/">Pimp You .autotest</a></p>
<p>Splendid!</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/UMIuk9y219M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/15/pimp-my-test-on-mac-with-growl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/15/pimp-my-test-on-mac-with-growl/</feedburner:origLink></item>
		<item>
		<title>TDD on Rails #3 – Fixtures</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/u0ia4-LXm3Q/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/14/tdd-on-rails-3-fixtures/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 01:39:41 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[factory_girl]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=92</guid>
		<description><![CDATA[Yet a little post here&#8230; maybe I should gather more information and experience and write bigger post&#8230; But that will do for now&#8230; I think that in the end, I&#8217;ll try to find time to write a big article about TDD on rails, with my whole experience&#8230; I&#8217;ll just let it documented here.
Next step for [...]]]></description>
			<content:encoded><![CDATA[<p>Yet a little post here&#8230; maybe I should gather more information and experience and write bigger post&#8230; But that will do for now&#8230; I think that in the end, I&#8217;ll try to find time to write a big article about TDD on rails, with my whole experience&#8230; I&#8217;ll just let it documented here.</p>
<p>Next step for my TDD application: using fixtures. Fixtures permit you to populate you database before running some tests. For example, you want to see if your User.find_admin stuff works the way you want, then you&#8217;ll just populate your database with a couple of Admin users and check if your method retrieves them from the database correctly.</p>
<p>Rails ships with its out of the box fixtures solution called fixtures. But reading some articles, search through the github projects and learning how the default fixtures implementation works made me realize that it can be a pain&#8230; And there is some fixtures replacement, here is a non exhaustive list:<br />
- <a href="http://github.com/nakajima/fixjour/tree/master">fixjour</a><br />
- <a href="http://replacefixtures.rubyforge.org/">replacefixtures</a><br />
- <a href="http://github.com/notahat/machinist/tree/master">machinist<br />
</a>- <a href="http://github.com/flogic/object_daddy/tree/master">object_daddy</a><br />
- <a href="http://github.com/thoughtbot/factory_girl/tree/master">factory_girl</a><br />
- &#8230;</p>
<p>And much more. That disconcerting, so much options. I quickly read the github (if github hosted) readme file and even before reading this <a href="https://opensource.inklingmarkets.com/markets/18376">prediction </a>I choosed <strong>factory_girl</strong> because of its simplicity.</p>
<p>What do I mean with simplicity? INHO you should have a good idea of what the plugin/gem/code is doing giving a quick look at the github project home. Fixtures are something quite simple and the fixture replacement should quite simples too. And factory_girl caught my attention excatly because of this: clear, clean, easy to understand and to use.</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/u0ia4-LXm3Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/14/tdd-on-rails-3-fixtures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/14/tdd-on-rails-3-fixtures/</feedburner:origLink></item>
		<item>
		<title>TDD on Rails #2</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/F3FVFGbxJbI/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/12/tdd-on-rails-2/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 18:05:14 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=86</guid>
		<description><![CDATA[In my new app that started as a POC of TDD, I&#8217;m going to use Authlogic. And I followed the doc and some post here .
Again, I did lots of behavior thinking without TDD/BDD in mind&#8230;. The result was that I was with some controllers and my model created without any test related thing going on&#8230;
The thought [...]]]></description>
			<content:encoded><![CDATA[<p>In my new app that started as a POC of TDD, I&#8217;m going to use <a title="Restful authentication. The right way..." href="http://github.com/binarylogic/authlogic/tree/master">Authlogic</a>. And I followed the doc and some post <a title="Authlogic basic setup" href="http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup">here</a> .</p>
<p>Again, I did lots of behavior thinking without TDD/BDD in mind&#8230;. The result was that I was with some controllers and my model created without any test related thing going on&#8230;</p>
<p>The thought of the day is: never user ./script/generate [model|controller|...] anymore&#8230; <strong>use ./script/generate [rspec_controller|rspec_model|...]</strong></p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/F3FVFGbxJbI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/12/tdd-on-rails-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/12/tdd-on-rails-2/</feedburner:origLink></item>
		<item>
		<title>Install passenger on Debian</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/4l2NQyO42RY/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/09/install-passenger-on-debian/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 17:41:05 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=82</guid>
		<description><![CDATA[Need packages to be able to install Passenger on Debian sid:
- ruby1.8-dev
- make
]]></description>
			<content:encoded><![CDATA[<p>Need packages to be able to install Passenger on Debian sid:</p>
<p>- ruby1.8-dev<br />
- make</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/4l2NQyO42RY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/09/install-passenger-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/09/install-passenger-on-debian/</feedburner:origLink></item>
		<item>
		<title>Rails 2.3 on Debian</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/Lg72AUrZJD0/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/09/rails-23-on-debian/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 16:04:14 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=77</guid>
		<description><![CDATA[I decided to install a new Rails environment in a VM using Debian (testing) to be able to code when I don&#8217;t have my Macbook.
This is my experience. Read the whole article before running any command you find in here.
I thought that it would be as easy as:
12345debian~:# aptitude install ruby rubygems
debian~:# gem install rails
debian~:# [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to install a new Rails environment in a VM using Debian (testing) to be able to code when I don&#8217;t have my Macbook.</p>
<p>This is my experience. Read the whole article before running any command you find in here.</p>
<p>I thought that it would be as easy as:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">debian~:# aptitude install ruby rubygems<br />
debian~:# gem install rails<br />
debian~:# rails myapp<br />
debian~:# cd myapp<br />
debian~:# ./script/server</div></td></tr></tbody></table></div>
<p>But the result was not as expected:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Rails requires RubyGems &amp;gt;= 1.3.1 (you have 1.2.0). Please `gem update --system` and try again.</div></td></tr></tbody></table></div>
<p>Well, let&#8217;s do as told:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">debian:~/myapp# gem update --system<br />
ERROR:  While executing gem ... (RuntimeError)<br />
gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get.</div></td></tr></tbody></table></div>
<p>No good&#8230; What now? Let&#8217;s google it. Yeah there is a gem that allows you to update rubygems to the latest version:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">debian:~/myapp# gem install rubygems-update<br />
debian:~/myapp# update_rubygems<br />
debian:~/myapp# gem install rails<br />
debian:~/myapp# ./script/server</div></td></tr></tbody></table></div>
<p>Voila!  (almost)<br />
Did we need to reinstall the Rails gem? Well, yeah&#8230; Debian&#8217;s version of rubygems stores his stuff in the /var/lig/gems folder while this new updated version stores in /usr/lib/ruby(&#8230;).<br />
A good thing with this rubygems installation is that we do not need to edit the path anymore as the bin (rails&#8230;) are now in the /usr/bin folder.</p>
<p>Now that we have solved the rubygems version problem, let see what problem is showing now:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">debian:~/myapp# ./script/server<br />
=&amp;gt; Booting WEBrick<br />
=&amp;gt; Rails 2.3.2 application starting on http://0.0.0.0:3000<br />
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:269:in `require_frameworks': no such file to load -- net/https (RuntimeError)<br />
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:134:in `process'<br />
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `send'<br />
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `run'<br />
from /root/myapp/config/environment.rb:9<br />
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'<br />
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'<br />
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'<br />
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'<br />
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'<br />
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84<br />
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'<br />
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'<br />
from ./script/server:3</div></td></tr></tbody></table></div>
<p>net/http??? Google, my friend, what&#8217;s going on? After finding articles about recompiling ssl, i found this solution, much more convinient:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">debian:~myapp/# aptitude install libopenssl-ruby1.8<br />
debian:~/myapp# ./script/server</div></td></tr></tbody></table></div>
<p>Voilà!!! It&#8217;s working at last! I must admit that I am a little desapointed. I thought it would be much easier to have rails 2.3 running on debian.</p>
<p>My next step is to have Vim configured so it would be very close to using Textmate!</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/Lg72AUrZJD0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/09/rails-23-on-debian/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/09/rails-23-on-debian/</feedburner:origLink></item>
		<item>
		<title>TDD on Rails #1</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/XbM8HZ2MpkI/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/07/tdd-on-rails-1/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 02:39:14 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=75</guid>
		<description><![CDATA[Back here, talking about my journey learning Ruby and Rails.
What would be Rails without TDD? And what is TDD? BDD? Test Driven Development and Behaviour Driven Development&#8230; Well, I won&#8217;t explain these 2 concept here, there is Pliny of articles about it: http://en.wikipedia.org/wiki/Test-driven_development
So I began learning about TDD and BDD and what is the common [...]]]></description>
			<content:encoded><![CDATA[<p>Back here, talking about my journey learning Ruby and Rails.</p>
<p>What would be Rails without TDD? And what is TDD? BDD? Test Driven Development and Behaviour Driven Development&#8230; Well, I won&#8217;t explain these 2 concept here, there is Pliny of articles about it: <a href="http://en.wikipedia.org/wiki/Test-driven_development">http://en.wikipedia.org/wiki/Test-driven_development</a></p>
<p>So I began learning about TDD and BDD and what is the common way to do this in Rails&#8230; <a href="http://rspec.info/">RSpec</a> is the answer!</p>
<p>As I&#8217;ve been working with traditional Java/J2EE/RUP way of life, when I first read: write your test first, I thought: what the fuck? And my first steps (beside learning how works RSpec) were:</p>
<p>- Create a test! Done! It fails! Great!!<br />
- Write some code (a rails model)! Done! The test succeeded! Great!!!<br />
- Think about what must be the behaviour of the model! Great!!<br />
- Write the code before the test! <strong>DAMN!!!! </strong></p>
<p>So It&#8217;s gonna be hard&#8230; Bad habits.. But This is the way to go, trust me!</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/XbM8HZ2MpkI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/07/tdd-on-rails-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/07/tdd-on-rails-1/</feedburner:origLink></item>
		<item>
		<title>Ruby Enumerable#every</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/Rl3-KTzgcqQ/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/04/01/ruby-enumerableevery/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 14:40:07 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[enumerable]]></category>
		<category><![CDATA[every]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=69</guid>
		<description><![CDATA[Martin Aumont created a gem that add an every method to enumerable: see his post.
The result is quite nice:

12enum = &#91;1.4, 2.4 ,3.4&#93;
enum.every.floor &#160; &#160; &#160; &#160;# [1, 2, 3]

]]></description>
			<content:encoded><![CDATA[<p>Martin Aumont created a gem that add an <strong><em>every</em></strong> method to enumerable: see <a href="http://mynyml.com/15-enumerableevery/">his post</a>.</p>
<p>The result is quite nice:</p>
<pre>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">enum = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1.4</span>, <span style="color:#006666;">2.4</span> ,<span style="color:#006666;">3.4</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
enum.<span style="color:#9900CC;">every</span>.<span style="color:#9900CC;">floor</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># [1, 2, 3]</span></div></td></tr></tbody></table></div>
</pre>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/Rl3-KTzgcqQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/04/01/ruby-enumerableevery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/04/01/ruby-enumerableevery/</feedburner:origLink></item>
		<item>
		<title>Browsers performance and benchmark</title>
		<link>http://feedproxy.google.com/~r/com/jRcm/~3/I71WnuGXOz8/</link>
		<comments>http://rails.anyware-technologies.com.br/2009/03/29/browsers-performance-and-benchmark/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 16:30:20 +0000</pubDate>
		<dc:creator>Mathieu</dc:creator>
				<category><![CDATA[Off-Topic]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://rails.anyware-technologies.com.br/?p=67</guid>
		<description><![CDATA[Here I am, reading this post&#62; Safari 4 Beta vs Firefox 3.1 Beta. Another benchmark that does not (as pointed out) represent real life. Real life browsing experience is impossible to reproduce, and I did not find a good benchmark that got nearly close to it.
I don&#8217;t really care if a single page opens 200ms [...]]]></description>
			<content:encoded><![CDATA[<p>Here I am, reading this post&gt; <a href="http://clearspace.openqa.org/community/selenium/blog/2009/03/13/browser-performance-firefox-31-beta-3-vs-safari-4-beta">Safari 4 Beta vs Firefox 3.1 Beta</a>. Another benchmark that does not (as pointed out) represent real life. Real life browsing experience is impossible to reproduce, and I did not find a good benchmark that got nearly close to it.</p>
<p>I don&#8217;t really care if a single page opens 200ms faster in safari or chrome. What I and my wife really care is how the browser behave after few hours of browsing. How it handles many many opened tabs.<br />
As my wife business has nothing to do with TI, we have a completely different experience about browsing.</p>
<p>I usually browse TI and games oriented site. Few ads, few flash&#8230; My wife mainly browse sites that overuse Flash and that are full of Ads&#8230;</p>
<p>It is common for me to have over 30 opened tabs, things that I want to read later, things that I am currently reading, and &#8220;sticky&#8221; tabs like gmail, google-reader, Rails api, etc&#8230; Depending of the browser and the opened sites, I end up with my browser consuming 200-400MB and using 5-30% of my Dual Core cpu&#8230;</p>
<p>My wife usually have the same number of tabs opened, but her experience is quite different, she ends ups with her browser using up to 1GB, and rarely less than 400MB. She mainly use firefox, and even if there were great improvements in the 3.x version, closing tabs does not free all the memory, she need to restart the browser once in a while (that will open all the tabs that was opened before and go back eating up memory and cpu). Of course the browser frequently gets to his limit point and become unresponsive, only restarting it fixes it.</p>
<p>This was completely off-topic, sorry about that! ;-)</p>
<img src="http://feeds.feedburner.com/~r/com/jRcm/~4/I71WnuGXOz8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rails.anyware-technologies.com.br/2009/03/29/browsers-performance-and-benchmark/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://rails.anyware-technologies.com.br/2009/03/29/browsers-performance-and-benchmark/</feedburner:origLink></item>
	</channel>
</rss>
