<?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>john wyles dot com &#187; rails</title>
	<atom:link href="http://johnwyles.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnwyles.com</link>
	<description>a man a plan a blog san francisco</description>
	<lastBuildDate>Tue, 08 Jun 2010 06:02:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MongoDB Rails Skeleton</title>
		<link>http://johnwyles.com/2010/05/30/mongodb-rails-skeleton/</link>
		<comments>http://johnwyles.com/2010/05/30/mongodb-rails-skeleton/#comments</comments>
		<pubDate>Sun, 30 May 2010 17:23:45 +0000</pubDate>
		<dc:creator>John Wyles</dc:creator>
				<category><![CDATA[mongodb]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[compass]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[formtastic]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[mongomapper]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[skeleton]]></category>
		<category><![CDATA[will_paginate]]></category>

		<guid isPermaLink="false">http://johnwyles.com/?p=410</guid>
		<description><![CDATA[I have a more than a few rails application skeletons now that make use of MongoDB and have various other common components so I thought it would be worthwhile to summarize them with a rails skeleton.  The skeleton can be found on github under johnwyles/skeleton.  The skeleton includes the following:

Persistence

MongoMapper
Validatable (overwritten by: johnwyles/validatable)

Authentication [...]]]></description>
			<content:encoded><![CDATA[<p>I have a more than a few rails application skeletons now that make use of MongoDB and have various other common components so I thought it would be worthwhile to summarize them with a rails skeleton.  The skeleton can be found on github under <a href="http://github.com/johnwyles/skeleton">johnwyles/skeleton</a>.  The skeleton includes the following:</p>
<ul>
<li>Persistence
<ul>
<li>MongoMapper</li>
<li>Validatable (overwritten by: <a href="http://github.com/johnwyles/validatable">johnwyles/validatable</a>)</li>
</ul>
<li>Authentication and Authorization
<ul>
<li>Devise</li>
<li>CanCan</li>
<li>AASM (overwritten by: <a href="http://github.com/johnwyles/aasm">johnwyles/aasm</a>)</li>
<li>AASM::StatefulResource (included in: lib/aasm/stateful_resource.rb)</li>
</ul>
</li>
<li>Display
<ul>
<li>HAML</li>
<li>Compass</li>
<li>Formtastic</li>
<li>will_paginate</li>
</ul>
</li>
<li>Testing
<ul>
<li>Cucumber</li>
<li>Capybara</li>
<li>Culerity</li>
<li>rSpec</li>
<li>factory_girl</li>
<li>database_cleaner</li>
</ul>
</li>
<li>Configuration
<ul>
<li>AppConfig (included in: config/initializers/00_appconfig.rb)</li>
<li>i18n (included in: config/initializers/01_locales.rb)</li>
</ul>
</li>
</ul>
<p>AppConfig is a short little initializer with OpenStruct that reads a YAML file and loads various application specific settings (e.g. Application Name, Session Secret, Domain, etc.).</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjohnwyles.com%2F2010%2F05%2F30%2Fmongodb-rails-skeleton%2F&amp;layout=button_count&amp;&amp;width=200&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:200px;height:40px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://johnwyles.com/2010/05/30/mongodb-rails-skeleton/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Turning a Pickcle into a Cucumber</title>
		<link>http://johnwyles.com/2010/04/24/turning-a-pickcle-into-a-cucumber/</link>
		<comments>http://johnwyles.com/2010/04/24/turning-a-pickcle-into-a-cucumber/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 08:16:02 +0000</pubDate>
		<dc:creator>John Wyles</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>

		<guid isPermaLink="false">http://johnwyles.com/?p=260</guid>
		<description><![CDATA[I had seen Cucumber before but never really had any time to dabble with it and now that I have I cannot put it down!  After setting up a skeleton Ruby on Rails application using Cucumber, Capybara, Devise, and FactorGirl (along with Haml, Compass, and MongoMapper) I decided to circle back and write some [...]]]></description>
			<content:encoded><![CDATA[<p>I had seen Cucumber before but never really had any time to dabble with it and now that I have I cannot put it down!  After setting up a skeleton Ruby on Rails application using Cucumber, Capybara, Devise, and FactorGirl (along with Haml, Compass, and MongoMapper) I decided to circle back and write some Cucumber features to cover the basic user interactions: sign up, confirmation, login, logout, lost password, etc.  While it took me much longer than I expected my journey was very fruitful; it turns out some of the Features and their subsequent Scenarios were entirely covered by Cucumber and Capybara without me needing to write one bit of &#8220;glue code&#8221; to make them work (Cucumber calls these &#8220;step definitions&#8221;).  Most of the time I spent was refactoring out step definitions over and over until I found I did not need a single one!  Here is the final product from the &#8220;Signing Up&#8221; feature:</p>
<pre class="brush:ruby">
# features/authentication/signup.feature

Feature: Signing Up
  In order to sign up for an account
  As a guest
  I need to be able to register

  Scenario: Registration
    Given I am on the sign up page
    When I fill in "user_email" with "test@example.com"
    And I fill in "user_password" with "test1234"
    And I fill in "user_password_confirmation" with "test1234"
    And I press "Sign Up"
    Then I should see "You will receive an email with instructions"
</pre>
<p>Even after all of this I cannot be sure that I have completely covered the test but I will note that it does not require a single step definition outside of those that are provided by Capybara in the web_steps.rb convenient step definitions.  Here are the other Features, Backgrounds, Scenarios, and Scenario Outlines that I used to cover the authentication class of features:</p>
<p>The confirmation feature:</p>
<pre class="brush:ruby">
# features/authentication/confirmation.feature

Feature:
  In order activate my account
  As a user
  I want to be able to confirm

  Background:
    Given I am pending confirmation

  Scenario: Confirmation
    Given I received the email
    When I confirm the account
    Then I should find that I am confirmed
</pre>
<p>The session feature:</p>
<pre class="brush:ruby">
# features/authentication/session.feature

Feature: Session handling
  In order to use the site
  As a registered user
  I need to be able to login and logout

  Background:
    Given that a confirmed user exists

  Scenario Outline: Logging in
    Given I am on the login page
    When I fill in "user_email" with "&lt;email&gt;"
    And I fill in "user_password" with "&lt;password&gt;"
    And I press "Sign in"
    Then I should &lt;action&gt;
    Examples:
      |         email       |  password   |              action             |
      | minimal@example.com |  test1234   | see "Signed in successfully"    |
      | bad@example.com     |  password   | see "Invalid email or password" |

  Scenario: Logging out
    Given I am logged in
    When I go to the sign out link
    Then I should see "Signed out successfully"
</pre>
<p>The forgotpassword feature:</p>
<pre class="brush:ruby">
# features/authentication/forgotpassword.feature

Feature: Forgot password
  In order to login
  As a user
  When I have forgotten my password
  I should be able to reset it

  Background:
    Given that a confirmed user exists

  Scenario Outline: Reset password request
    Given I am on the forgotten password page
    When I fill in "user_email" with "&lt;email&gt;"
    And I press "Send me reset password instructions"
    Then I should &lt;action&gt;
    Examples:
      |         email       |                                       action                                       |
      | minimal@example.com | see "You will receive an email with instructions about how to reset your password" |
      | bad@example.com     | see "Email not found"                                                              |

  Scenario: Reset password confirmation
    Given that I have reset my password
    When I follow the reset password link in my email
    Then I expect to be able to reset my password
</pre>
<p>and all of the step definitions:</p>
<pre class="brush:ruby">
# features/step_definitions/authentication_steps.rb

# Confrimation
Given /^I received the email$/ do
  @user.confirmed?.should be_false
end

When /^I confirm the account$/ do
  visit user_confirmation_path(:confirmation_token => @user.confirmation_token)
  page.should have_content("Your account was successfully confirmed")
  @user.confirm!
end

Then /^I should find that I am confirmed$/ do
  @user.confirmed?.should be_true
end

# Forgottenpassword
Given /^that I have a confirmed account$/ do
  @user.confirmed?
end

Given /^that I have reset my password$/ do
  @user.send_reset_password_instructions
end

When /^I follow the reset password link in my email$/ do
  visit edit_user_password_path(:reset_password_token => @user.reset_password_token)
  page.should have_content("Change your password")
end

Then /^I expect to be able to reset my password$/ do
  visit edit_user_password_path(:reset_password_token => @user.reset_password_token)
  fill_in 'user_password', :with => 'test1234'
  fill_in 'user_password_confirmation', :with => 'test1234'
  click_button('Change my password')
  page.should have_content('Your password was changed successfully')
end

# Session
Given /^I am logged in$/ do
  visit path_to('the login page')
  fill_in('user_email', :with => @user.email)
  fill_in('user_password', :with => @user.password)
  click_button('Sign in')
  if defined?(Spec::Rails::Matchers)
    page.should have_content('Signed in successfully')
  else
    assert page.has_content?('Signed in successfully')
  end
end
</pre>
<p>To get the minimal user, referenced in a few of the step definitions, I created a Factory:</p>
<pre class="brush:ruby">
# spec/factories/user.rb

Factory.define :minimal_user, :class => User do |u|
  u.email 'minimal@example.com'
  u.password 'test1234'
  u.password_confirmation 'test1234'
end
</pre>
<p>And added the FactoryGirl gem to the Cucumber environment:</p>
<pre class="brush:ruby">
# config/environments/cucumber.rb

config.gem "factory_girl"
</pre>
<p>As you can see there is a lot here and a lot of it probably duplicates the test coverage found in the Devise gem.  However, developing these Features, Scenarios, and Step Definitions has been great practice for me and warmed me up very gently to how fun Behavior Driven Design (BDD) can be.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjohnwyles.com%2F2010%2F04%2F24%2Fturning-a-pickcle-into-a-cucumber%2F&amp;layout=button_count&amp;&amp;width=200&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:200px;height:40px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://johnwyles.com/2010/04/24/turning-a-pickcle-into-a-cucumber/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails 3 Beta is Out</title>
		<link>http://johnwyles.com/2010/02/05/rails-3-beta-is-out/</link>
		<comments>http://johnwyles.com/2010/02/05/rails-3-beta-is-out/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 17:09:06 +0000</pubDate>
		<dc:creator>John Wyles</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[3]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://johnwyles.com/?p=110</guid>
		<description><![CDATA[The Rails 3 beta has been officially announced and that means its time to start tinkering.  Some very important things I was looking forward to coming out of the merb / rails merge were the massive decoupling of many of the core components.  One nice example of the widespread decoupling that has occurred [...]]]></description>
			<content:encoded><![CDATA[<p>The Rails 3 beta has been <a href="http://weblog.rubyonrails.org/2010/2/5/rails-3-0-beta-release">officially announced</a> and that means its time to start tinkering.  Some very important things I was looking forward to coming out of the merb / rails merge were the massive decoupling of many of the core components.  One nice example of the widespread decoupling that has occurred is with the ActiveModel library which has been pulled apart to accommodate a non-RDBMS approach (such as <a href="http://mongodb.org/">MongoDB</a>).  However, the best example of this is the extensions API which has moved the core components (ActiveRecord, ActionMailer, etc.) to instead be extensions.  This will allow for the replacement of parts or whole areas of the core; we will see, with rails 3, the birth of much more extreme examples of a &#8220;rails&#8221; apps and that, i think, is what has everyone excited.</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjohnwyles.com%2F2010%2F02%2F05%2Frails-3-beta-is-out%2F&amp;layout=button_count&amp;&amp;width=200&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:200px;height:40px;margin-top:5px;"></iframe>]]></content:encoded>
			<wfw:commentRss>http://johnwyles.com/2010/02/05/rails-3-beta-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
