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

<channel>
	<title>Blog &#124; Rubyyot &#187; Uncategorized</title>
	<atom:link href="http://blog.rubyyot.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rubyyot.com</link>
	<description>Programming, Pragmatism and Getting By in the World</description>
	<lastBuildDate>Wed, 24 Mar 2010 00:14:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making Technorati Happy</title>
		<link>http://blog.rubyyot.com/2009/06/making-technorati-happy/</link>
		<comments>http://blog.rubyyot.com/2009/06/making-technorati-happy/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 05:15:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/2009/06/making-technorati-happy/</guid>
		<description><![CDATA[My Technorati Profile.  I&#8217;m taking it back.
]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://technorati.com/claim/ra9exmky3e" rel="me">Technorati Profile</a>.  I&#8217;m taking it back.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/06/making-technorati-happy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listing of cucumber&#039;s out-of-the-box webrat steps</title>
		<link>http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/</link>
		<comments>http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 18:09:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cucumber]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/</guid>
		<description><![CDATA[Commonly used webrat steps found in cucumber
(replace words in [brackets] with the approprate word.)
Given

Given I am on [page_name]

When

When I go to [page_name]
When I press "[button]"
When I follow "[link]"
When I fill in "[field]" with "[value]"
When I select "[value]" from "[field]"
When I select "[time]" as the date and time				#datetime_select
When I select "[datetime]" as the "[datetime_label]" date and [...]]]></description>
			<content:encoded><![CDATA[<p>Commonly used <a href="http://github.com/brynary/webrat">webrat</a> steps found in <a href="http://github.com/brynary/cucumber">cucumber</a></p>
<p>(replace words in [brackets] with the approprate word.)</p>
<h3>Given</h3>
<pre>
Given I am on [page_name]
</pre>
<h3>When</h3>
<pre>
When I go to [page_name]
When I press "[button]"
When I follow "[link]"
When I fill in "[field]" with "[value]"
When I select "[value]" from "[field]"
When I select "[time]" as the date and time				#datetime_select
When I select "[datetime]" as the "[datetime_label]" date and time	#specific datetime_select
When I select "[time]" as the time			#time select
When I select "[time]" as the "[time_label]" time	#specific time select
When I select "[date]" as the date			#date_select
When I select "[date]" as the "[date_label]" date	#specific date_select
When I check "[field]"
When I uncheck "[field]"
When I choose "[field]"
When I attach the file at "[path]" to "[field]"
</pre>
<h3>Then</h3>
<pre>
Then I should see "[text]"
Then I should not see "[text]"
Then the "[field]" field should contain "[value]"
Then the "[field]" field should not contain "[value]"
Then the "[label]" checkbox should be checked
Then I should be on [page_name]
</pre>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=d61ef58d-41df-8e0a-a2e5-73f18ab347ca" /></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/04/listing-of-cucumbers-out-of-the-box-webrat-steps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rubyyot.com is dead; Long live Rubyyot.com</title>
		<link>http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/</link>
		<comments>http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 03:42:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rubyyot]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/</guid>
		<description><![CDATA[I have pulled the plug on Rubyyot.com, the task management site.  It was an enjoyable learning experience, but I was no longer using it and I don&#8217;t think anyone else was either.  I&#8217;ve removed it to make way for new development projects.  That is if I can ever concentrate enough on any [...]]]></description>
			<content:encoded><![CDATA[<p>I have pulled the plug on Rubyyot.com, the task management site.  It was an enjoyable learning experience, but I was no longer using it and I don&#8217;t think anyone else was either.  I&#8217;ve removed it to make way for new development projects.  That is if I can ever concentrate enough on any one of my projects to actually complete it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/03/rubyyotcom-is-dead-long-live-rubyyotcom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chores: a test driven website &#8211; Part 8 (this time it&#039;s personal)</title>
		<link>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-8-this-time-its-personal/</link>
		<comments>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-8-this-time-its-personal/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 19:55:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Chores]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=231</guid>
		<description><![CDATA[This is part of the Chores series of posts.
I&#8217;m now attacking the Idenitity model.  My idea for this is a model that contains a single field.  That field is a valid, properly formatted, immutable OpenID.  Because I&#8217;m going to need to validate OpenIDs I&#8217;m going to install the Open ID Plugin as [...]]]></description>
			<content:encoded><![CDATA[<p>This is part of the <a href="http://blog.rubyyot.com/chores-a-test-driven-website/ ">Chores series of posts</a>.</p>
<p>I&#8217;m now attacking the Idenitity model.  My idea for this is a model that contains a single field.  That field is a valid, properly formatted, immutable OpenID.  Because I&#8217;m going to need to validate OpenIDs I&#8217;m going to install the <a href="http://agilewebdevelopment.com/plugins/openidauthentication">Open ID Plugin</a> as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ ruby script<span style="color:#006600; font-weight:bold;">/</span>plugin install git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>open_id_authentication.<span style="color:#9900CC;">git</span>
Initialized empty Git repository <span style="color:#9966CC; font-weight:bold;">in</span> c:<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>chores<span style="color:#006600; font-weight:bold;">/</span>vendor<span style="color:#006600; font-weight:bold;">/</span>plugins<span style="color:#006600; font-weight:bold;">/</span>open_id_authentication<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">git</span><span style="color:#006600; font-weight:bold;">/</span>
remote: Counting objects: <span style="color:#006666;">35</span>, done.←<span style="color:#006600; font-weight:bold;">&#91;</span>K
remote: Compressing objects: <span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">31</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">31</span><span style="color:#006600; font-weight:bold;">&#41;</span>, done.←<span style="color:#006600; font-weight:bold;">&#91;</span>K
remote: Total <span style="color:#006666;">35</span> <span style="color:#006600; font-weight:bold;">&#40;</span>delta <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>, reused <span style="color:#006666;">21</span> <span style="color:#006600; font-weight:bold;">&#40;</span>delta <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>←<span style="color:#006600; font-weight:bold;">&#91;</span>K
Unpacking objects: <span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">35</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">35</span><span style="color:#006600; font-weight:bold;">&#41;</span>, done.
<span style="color:#9900CC;">From</span> git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>open_id_authentication
 <span style="color:#006600; font-weight:bold;">*</span> branch            HEAD       <span style="color:#006600; font-weight:bold;">-&gt;</span> FETCH_HEAD</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ rake open_id_authentication:db:create
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">in</span> c:<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>chores<span style="color:#006600; font-weight:bold;">&#41;</span>
      exists  db<span style="color:#006600; font-weight:bold;">/</span>migrate
      create  db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20090125184610</span>_add_open_id_authentication_tables.<span style="color:#9900CC;">rb</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ rake db:migrate
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">in</span> c:<span style="color:#006600; font-weight:bold;">/</span>rails<span style="color:#006600; font-weight:bold;">/</span>chores<span style="color:#006600; font-weight:bold;">&#41;</span>
==  AddOpenIdAuthenticationTables: migrating ==================================
<span style="color:#006600; font-weight:bold;">--</span> create_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:open_id_authentication_associations</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:force<span style="color:#006600; font-weight:bold;">=&gt;</span>true<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0310s
<span style="color:#006600; font-weight:bold;">--</span> create_table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:open_id_authentication_nonces</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:force<span style="color:#006600; font-weight:bold;">=&gt;</span>true<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#006600; font-weight:bold;">-&gt;</span> 0.0160s
==  AddOpenIdAuthenticationTables: migrated <span style="color:#006600; font-weight:bold;">&#40;</span>0.0470s<span style="color:#006600; font-weight:bold;">&#41;</span> =========================</pre></div></div>

<p>Here is my test for the Identity model</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test_helper'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> IdentityShouldBeValidatedTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  specify <span style="color:#996600;">&quot;that an open ID is required on create&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span>
    invalid identity
    identity.<span style="color:#9900CC;">open_id</span> = <span style="color:#996600;">&quot;test.example.com&quot;</span>
    valid identity
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;message for an overly long identifier&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> hundred_and_one_character_identifier
    validation_message_for identity, <span style="color:#ff3333; font-weight:bold;">:identifier</span>, <span style="color:#996600;">&quot;is too long.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;message for a null identifier&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span>
    validation_message_for identity, <span style="color:#ff3333; font-weight:bold;">:identifier</span>, <span style="color:#996600;">&quot;can not be blank.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;message for a poorly formatted&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> invalid_open_id
    validation_message_for identity, <span style="color:#ff3333; font-weight:bold;">:identifier</span>, <span style="color:#996600;">&quot;is not a valid Open ID.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;message for a duplicate identifier&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    Identity.<span style="color:#9900CC;">make</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> valid_identifier
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> valid_identifier
    validation_message_for identity, <span style="color:#ff3333; font-weight:bold;">:identifier</span>, <span style="color:#996600;">&quot;is already in use, please use another.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that 100 character identifier is valid&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> hundred_character_identifier
    valid identity
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that identifier is unique&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    Identity.<span style="color:#9900CC;">make</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> valid_identifier
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>  valid_identifier
    invalid identity
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that open_id must have the correct format&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span>
    identity.<span style="color:#9900CC;">open_id</span> = invalid_open_id
    invalid identity
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that open_id uniqueness extends to identifier when validated&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    Identity.<span style="color:#9900CC;">make</span>  <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> valid_identifier
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:open_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;test.example.com&quot;</span>
    invalid identity
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  protected
    <span style="color:#9966CC; font-weight:bold;">def</span> hundred_character_identifier
      <span style="color:#996600;">&quot;http://This.is.a.hundred.character.description.one.hundred.chatacters.is.not.too.long.but.it.of.com/&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> hundred_and_one_character_identifier
      <span style="color:#996600;">&quot;http://This.is.a.hundred1.character.description.one.hundred.chatacters.is.not.too.long.but.it.of.com/&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> invalid_open_id
      <span style="color:#996600;">&quot;bad_id&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> IdentityOpenIdShouldSetIdentifierTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  specify <span style="color:#996600;">&quot;that open_id sets identifier&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span>
    assert_nil identity.<span style="color:#9900CC;">identifier</span>
    identity.<span style="color:#9900CC;">open_id</span> = <span style="color:#996600;">&quot;test.example.com&quot;</span>
    assert_not_nil identity.<span style="color:#9900CC;">identifier</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that identifier sets open_id&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span>
    assert_nil identity.<span style="color:#9900CC;">open_id</span>
    identity.<span style="color:#9900CC;">identifier</span> = <span style="color:#996600;">&quot;http://test.example.com/&quot;</span>
    assert_not_nil identity.<span style="color:#9900CC;">open_id</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that open_id is nicely formatted for display&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://test.example.com/&quot;</span>
    assert_equal valid_open_id, identity.<span style="color:#9900CC;">open_id</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> IdentityShouldBeImmutableTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  specify <span style="color:#996600;">&quot;that open_id is immutable&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">make</span>
    assert_raise <span style="color:#CC00FF; font-weight:bold;">RuntimeError</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      identity.<span style="color:#9900CC;">open_id</span> = <span style="color:#996600;">&quot;monkey.example.com&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that identifier is immutable&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">make</span>
    assert_raise <span style="color:#CC00FF; font-weight:bold;">RuntimeError</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      identity.<span style="color:#9900CC;">identifier</span> = <span style="color:#996600;">&quot;http://monkey.example.com/&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> IdentityShouldBeFoundByOpenID <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  specify <span style="color:#996600;">&quot;that open_id can be used to find a record&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">make</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> valid_identifier
    identity_from_db = Identity.<span style="color:#9900CC;">find_by_open_id</span> valid_open_id
    assert_equal identity.<span style="color:#9900CC;">identifier</span>, identity.<span style="color:#9900CC;">identifier</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  specify <span style="color:#996600;">&quot;that display formatted open_id can be used to find a record&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    identity = Identity.<span style="color:#9900CC;">make</span> <span style="color:#ff3333; font-weight:bold;">:identifier</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> valid_identifier
    identity_from_db = Identity.<span style="color:#9900CC;">find_by_open_id</span> valid_identifier
    assert_equal identity.<span style="color:#9900CC;">identifier</span>, identity.<span style="color:#9900CC;">identifier</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Here is the code that passes the test<br />
<em>./test/test_helper.rb</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;RAILS_ENV&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;test&quot;</span>
<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;">&quot;/../config/environment&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<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;">&quot;/blueprints&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test_help'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'faker'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">use_transactional_fixtures</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">use_instantiated_fixtures</span>  = <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> invalid model
    assert !model.<span style="color:#9900CC;">valid</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> valid model
    assert model.<span style="color:#9900CC;">valid</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> validation_message_for model, column, message
    invalid model
    assert_equal message, model.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">on</span><span style="color:#006600; font-weight:bold;">&#40;</span>column<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> valid_identifier
    <span style="color:#996600;">&quot;http://test.example.com/&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> valid_open_id
    <span style="color:#996600;">&quot;test.example.com&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> specify <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block
  test<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><em>./app/models/identity.rb</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Identity <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> OpenIdAuthentication
&nbsp;
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:identifier</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 not be blank.&quot;</span>
&nbsp;
  validates_uniqueness_of <span style="color:#ff3333; font-weight:bold;">:identifier</span>,      <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;is already in use, please use another.&quot;</span>
&nbsp;
  validates_length_of <span style="color:#ff3333; font-weight:bold;">:identifier</span>,          <span style="color:#ff3333; font-weight:bold;">:maximum</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">100</span>,
                                            <span style="color:#ff3333; font-weight:bold;">:allow_nil</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
                                            <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;is too long.&quot;</span>
&nbsp;
  validate_on_create <span style="color:#ff3333; font-weight:bold;">:valid_id</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> open_id
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">identifier</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">identifier</span><span style="color:#006600; font-weight:bold;">&#91;</span>7..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> identifier= identifier
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Cannot update identifier.&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> new_record?
    set_identifier identifier
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> open_id= open_id
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Cannot update open_id.&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> new_record?
    set_identifier open_id
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> valid_id
    errors.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:identifier</span>, <span style="color:#996600;">&quot;is not a valid Open ID.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@invalid_id</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">find_by_open_id</span> open_id
    id = OpenIdAuthentication::normalize_identifier<span style="color:#006600; font-weight:bold;">&#40;</span>open_id<span style="color:#006600; font-weight:bold;">&#41;</span>
    find_by_identifier open_id
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  protected
  <span style="color:#9966CC; font-weight:bold;">def</span> normalize_id id
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      identifier = normalize_identifier<span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">OpenIdAuthentication::InvalidOpenId</span>
      identifier = id
      <span style="color:#0066ff; font-weight:bold;">@invalid_id</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    identifier
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> set_identifier id
    write_attribute<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:identifier</span>, normalize_id<span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><em>./test/blueprints.rb</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'machinist'</span>  <span style="color:#008000; font-style:italic;"># if you installed machinist from gem</span>
&nbsp;
Chore.<span style="color:#9900CC;">blueprint</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  description <span style="color:#996600;">&quot;Put the dirty clothes in the hamper&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Identity.<span style="color:#9900CC;">blueprint</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  identifier <span style="color:#996600;">&quot;http://#{Faker::Name.first_name}.#{Faker::Internet.domain_name}/&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Child.<span style="color:#9900CC;">blueprint</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  child <span style="color:#006600; font-weight:bold;">&#123;</span> Identity.<span style="color:#9900CC;">make</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  parent <span style="color:#006600; font-weight:bold;">&#123;</span> Identity.<span style="color:#9900CC;">make</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>This one took a little work to do and I&#8217;m going to revisit it in a little while to see if it needs any refactoring.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-8-this-time-its-personal/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>The end of a butt sucking era</title>
		<link>http://blog.rubyyot.com/2009/01/the-end-of-a-butt-sucking-era/</link>
		<comments>http://blog.rubyyot.com/2009/01/the-end-of-a-butt-sucking-era/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 05:16:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[quit smoking]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/2009/01/the-end-of-a-butt-sucking-era/</guid>
		<description><![CDATA[I quit smoking yesterday.  I had my last cigarette yesterday at aroung 4:00 pm.  It&#8217;s been over 24 hours now.  I&#8217;ve managed to keep myself distracted for the most part.  I find that makes it easier.
]]></description>
			<content:encoded><![CDATA[<p>I quit smoking yesterday.  I had my last cigarette yesterday at aroung 4:00 pm.  It&#8217;s been over 24 hours now.  I&#8217;ve managed to keep myself distracted for the most part.  I find that makes it easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/the-end-of-a-butt-sucking-era/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chores:  A test driven website, part 2</title>
		<link>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-2/</link>
		<comments>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-2/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 13:25:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chores]]></category>
		<category><![CDATA[Introspection]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.rubyyot.com/?p=53</guid>
		<description><![CDATA[This is part of the Chores series of posts
In which I continue to build the chores website and demonstating how simple it is to use a test first methodology. To follow along, please see my previous post.
Doh!  I forgot to commit!
When I left off, I had come to a natural stopping point.  A [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is part of <a href="http://blog.rubyyot.com/chores-a-test-driven-website/">the Chores series of posts</a></em></p>
<p>In which I continue to build the chores website and demonstating how simple it is to use a test first methodology. To follow along, please <a href="http://blog.rubyyot.com/2009/01/chores-a-test-driven-website/" rel="me">see my previous post.</a></p>
<h2>Doh!  I forgot to commit!</h2>
<p>When I left off, I had come to a natural stopping point.  A place where I was shifting focus from features to unit testing.  I like to make my commits when my tests are all passing, however if I&#8217;m implementing a new feature, I don&#8217;t apply this hueristic since completing a feature will span multiple units of work. So let&#8217;s commit this.  First let&#8217;s see where I am:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;"># Untracked files:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#       features/</span>
<span style="color: #666666; font-style: italic;">#       lib/</span>
<span style="color: #666666; font-style: italic;">#       script/cucumber</span>
nothing added to commit but untracked files present <span style="color: #7a0874; font-weight: bold;">&#40;</span>use <span style="color: #ff0000;">&quot;git add&quot;</span> to track<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ok, git sees that I&#8217;ve added cucumber to my rails app and that I have added a feature.  Let&#8217;s add these changes to our commit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git add .</pre></div></div>

<p>and commit them</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;added feature to create chores&quot;</span></pre></div></div>

<p>and finally push a copy out to the repository I set up on my shared host.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git push origin master</pre></div></div>

<p>there all set.</p>
<h2>Routing to home</h2>
<p>At this point I&#8217;m a little confused as to how to proceed test first.  We have a failing feature.  When I have a failing feature I like to start by making a test to simulate the same error.  However in this case, that is difficult at best, and the failing feature has already told me what I need to do, which is create a home_controller</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate controller Home
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>home
      exists  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>home_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>home_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>home_helper.rb</pre></div></div>

<p>.. and map a route to it.  To do that I open up my ./config/routes.rb file and add the following route.  I like to get rid of the legacy routes so I&#8217;ll replace the entire text of the file with the following</p>
<p>[sourcecode language="ruby"]<br />
ActionController::Routing::Routes.draw do |map|<br />
  map.root :controller => &#8216;home&#8217;<br />
end
</pre>
<h2>So what are these controllers and routes?</h2>
<p>If you are new to Rails, you are probably wondering what we just did.  The controller is the C in the MVC pattern that Rails uses.  It's role is to handle web serving of the application.  It's kind of like an office assistant for your application.  It be able to handle frequent requests and delegate them to the proper subject matter expert.  When a request comes in for a list of Widgets, it will go to the Widget model and ask it for a list of widgets and then pass that off to the user interface (view) to display in the browser.  When the user interface passes it a bag of information and asks it to save the information, the controller will create an instance of the appropriate model from the bag of information and then tell the model it should save the information.</p>
<p>Controllers really shouldn't become too involved in the details, but should delegate well to the objects that know what they are doing.  Rails have a nice script to generate controllers, which we used above.  In this case we generated a home controller which we will use to handle requests for the application's home page or root.</p>
<p>The second thing we did is define a route.  Routes are related to controllers, in that they show the framework how to translate a request such as http://www.exmaple.com/sprocket/new into a method call on a controller.  In the case of the above url, it would call the method new on the sprocket controller.  You can find your routes in config/routes.rb and view all of your current routes with the rake task</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake routes</pre></div></div>

<h2>On with the show!</h2>
<p>Now let's go back to cucumber and see where we are.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore       <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage    <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      No action responded to index. Actions:  <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionController::UnknownAction<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ok, our route is now wired up nicely to the controller, but the home controller does not respond to index.  Lets add this to the controller</p>
<p>[sourcecode language="ruby"]<br />
class HomeController < ApplicationController<br />
  def index</p>
<p>  end<br />
end
</pre>
<p>and try cucumber again</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore     <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage   <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      Missing template home<span style="color: #000000; font-weight: bold;">/</span>index.erb <span style="color: #000000; font-weight: bold;">in</span> view path c:<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>chores<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views: <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionView::MissingTemplate<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ah ha!  We are making progress.  Our request has passed through the controller and is now looking for a view to render. One thing that I would like to point out is that doing the development in this way really lays out how the pieces of Rails all fit together.  Something that we wouldn't have seen if we had chosen to generate a scaffold or we built it piecemeal without the tests metering our pace.</p>
<h2></h2>
<h2>Views</h2>
<p>Views are what end up being displayed in the web browser, they are a sort of template.  By default, erb will process the template in the context of your request and output the dynamic content.  Pretty cool stuff, and it gives you great control over your output.</p>
<p>Well what are we waiting for, let's make a view.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">touch</span> app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>index.html.erb</pre></div></div>

<p>In windows you can use your IDE or folder browser to create the file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
Story:  Define chores
As a parent
I want to define chores
So that I can assign them to my children
&nbsp;
  Scenario: Creating a chore                          <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage                        <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:6</span>
    When I follow <span style="color: #ff0000;">&quot;Add Chore&quot;</span>                         <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:18</span>
      Could not <span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #c20cb9; font-weight: bold;">link</span> with text or title or <span style="color: #c20cb9; font-weight: bold;">id</span> <span style="color: #ff0000;">&quot;Add Chore&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Webrat::NotFoundError<span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">eval</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:<span style="color: #000000;">2</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'/^I follow &quot;([^&quot;]*)&quot;$/'</span>
      features<span style="color: #000000; font-weight: bold;">/</span>define_chores.feature:<span style="color: #000000;">8</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">'When I follow &quot;Add Chore&quot;'</span>
    And I fill <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;chore[name]&quot;</span> with <span style="color: #ff0000;">&quot;My first chore&quot;</span> <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:22</span>
    And I press <span style="color: #ff0000;">&quot;Add&quot;</span>                                 <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:14</span>
    Then I should see <span style="color: #ff0000;">&quot;Chore added.&quot;</span>                  <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:93</span>
    And I should see <span style="color: #ff0000;">&quot;My first chore&quot;</span>                 <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:93</span>
&nbsp;
<span style="color: #000000;">1</span> scenario
<span style="color: #000000;">1</span> failed step
<span style="color: #000000;">4</span> skipped steps
<span style="color: #000000;">1</span> passed step
rake aborted<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>Hey look! Our first step has passed!  Let's give ourselves a pat on the back.  We have a website with a dynamic (albeit blank) homepage, that is tested.</p>
<h2>Not all quotes are equal</h2>
<p>I had an issue with my feature where the double quotes in my feature were translated automatically to open and closed style quotes.  This was causing my steps not to match.  If you find that you have a bunch of steps that are undefined at this point, that may be the issue.</p>
<h2>Catch the passing step fever</h2>
<p>The next step is one that is generated by webrat.  It is looking for a link to follow called "Add Chore".  The problem is that we didn't actually add the link, or anything else to the view. So let's update the view to read</p>
<p>[sourcecode language="ruby"]<br />
<%= link_to "Add Chore", chore_path %>
</pre>
<p>and fire up cucumber</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore      <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage    <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      undefined <span style="color: #7a0874; font-weight: bold;">local</span> variable or method <span style="color: #ff0000;">'chore_path'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #666666; font-style: italic;">#&lt;actionView::Base:0x4baf67c&gt; (ActionView::TemplateError)</span>
      On line <span style="color: #666666; font-style: italic;">#1 of app/views/home/index.html.erb</span>
&nbsp;
      <span style="color: #000000;">1</span>: <span style="color: #000000; font-weight: bold;">&lt;%</span>= link_to <span style="color: #ff0000;">&quot;Add Chore&quot;</span>, chore_path <span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
      app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>index.html.erb:<span style="color: #000000;">1</span></pre></div></div>

<p>ok, we need to define resource for this, let's add a route and controller.</p>
<p>[sourcecode language="ruby"]<br />
ActionController::Routing::Routes.draw do |map|<br />
  map.resources :chores<br />
  map.root :controller => 'home'<br />
end
</pre>
<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate controller Chores
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>chores
      exists  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>chores_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>chores_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>chores_helper.rb</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore    <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage   <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
      chore_url failed to generate from <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;show&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;chores&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
 - you may have ambiguous routes, or you may need to supply additional parameter
s <span style="color: #000000; font-weight: bold;">for</span> this route.  content_url has the following required parameters: <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;chores&quot;</span>,
 :<span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> - are they all satisfied? <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionView::TemplateError<span style="color: #7a0874; font-weight: bold;">&#41;</span>
      On line <span style="color: #666666; font-style: italic;">#1 of app/views/home/index.html.erb</span>
&nbsp;
      <span style="color: #000000;">1</span>: <span style="color: #000000; font-weight: bold;">&lt;%</span>= link_to <span style="color: #ff0000;">&quot;Add Chore&quot;</span>, chore_path <span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>

<p>Dang it! still getting an error.  Hmmm.. wait a minute.  chore_path is generating a show action.  That's not what we want to do.  We want a new action to be RESTful or maybe an index action if we don't see REST in the future for this app. A quick consultation with the domain expert (me) says that there is no valid reason not follow the RESTful guidelines at this point so let's fix the home/index view to read.</p>
<p>[sourcecode language="ruby"]<br />
<%= link_to "Add Chore", new_chore_path %>
</pre>
<p>cucumber says...</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore   <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage   <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
    When I follow <span style="color: #ff0000;">&quot;Add Chore&quot;</span>   <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:8</span>
      No action responded to new. Actions:  <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionController::UnknownAction<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Great!  That fixed it.  Now we need to make sure there is a new action on the chores controller.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ChoresController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> new
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cucumber features
Story:  Define chores  <span style="color: #666666; font-style: italic;"># features/define_chores.feature</span>
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore    <span style="color: #666666; font-style: italic;"># features/define_chores.feature:6</span>
    Given I am on the homepage    <span style="color: #666666; font-style: italic;"># features/step_definitions/chores_steps.rb:1</span>
    When I follow <span style="color: #ff0000;">&quot;Add Chore&quot;</span>      <span style="color: #666666; font-style: italic;"># features/step_definitions/webrat_steps.rb:8</span>
      Missing template chores<span style="color: #000000; font-weight: bold;">/</span>new.erb <span style="color: #000000; font-weight: bold;">in</span> view path c:<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>chores<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>views: <span style="color: #7a0874; font-weight: bold;">&#40;</span>ActionView::MissingTemplate<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>cucumber likes it!  But we still have an error.  Let's create ./app/views/chores/new.html.erb as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_for<span style="color:#006600; font-weight:bold;">&#40;</span>@chore<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">error_messages</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
  &lt;p&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
&nbsp;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">&quot;Add&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/p&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Hmmm.. wait we are getting ahead of ourselves. We need a model to be able to pass it to our view.  We will have to generate that next.</p>
<p>Well we didn't get to Test::Unit this time around, but with a model in sight it's sure to be right around the corner.  Until next time..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/chores-a-test-driven-website-part-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Back to Blogging</title>
		<link>http://blog.rubyyot.com/2009/01/back-to-blogging/</link>
		<comments>http://blog.rubyyot.com/2009/01/back-to-blogging/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 03:46:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[introduction]]></category>

		<guid isPermaLink="false">http://www.blog.rubyyot.com/?p=3</guid>
		<description><![CDATA[I&#8217;ve started and stopped blogging at various times and for various reasons.  Now I&#8217;ve started again because I&#8217;ve realized that I need a centralized location for my output.  Naturally I setup a blog (again).  We&#8217;ll see how long it lasts.  I am hoping to talk about my experiences with Ruby, Rails, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started and stopped blogging at various times and for various reasons.  Now I&#8217;ve started again because I&#8217;ve realized that I need a centralized location for my output.  Naturally I setup a blog (again).  We&#8217;ll see how long it lasts.  I am hoping to talk about my experiences with Ruby, Rails, .NET and new for 2009 (hopefully) Erlang with occational stops into my personal life or other areas.  We will see what happens.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyyot.com/2009/01/back-to-blogging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
