<?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>The Turning Point &#187; Rails</title>
	<atom:link href="http://blog.franktrindade.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.franktrindade.com</link>
	<description>Agile, software and some nonsense</description>
	<lastBuildDate>Tue, 31 Jan 2012 21:30:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Page Model with Cucumber and Capybara</title>
		<link>http://blog.franktrindade.com/2011/03/04/page-model-with-cucumber-and-capybara/</link>
		<comments>http://blog.franktrindade.com/2011/03/04/page-model-with-cucumber-and-capybara/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 20:59:31 +0000</pubDate>
		<dc:creator>franktrindade</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[Tests]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>

		<guid isPermaLink="false">http://blog.franktrindade.com/?p=516</guid>
		<description><![CDATA[I&#8217;ve spent some time today changing the Cucumber/Capybara tests in one of my pet projects to use a page model. Since I didn&#8217;t find much stuff on the interwebs about it, why not write it here ? The idea behind having a page model is to keep steps related to a specific page on your [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some time today changing the Cucumber/Capybara tests in one of my pet projects to use a page model. Since I didn&#8217;t find much stuff on the interwebs about it, why not write it here ?</p>
<p>The idea behind having a page model is to keep steps related to a specific page on your app in the same place, so you can reduce the repetition of steps in different tests. Is definitely not a complicated practice, and setting Capybara for it is a simple step.</p>
<p>Setting the context, Im using Cucumber 0.10 with Capybara 0.4.1.2 and Rails 3.0.1. Have done the standard installation steps recommended by the <a href="https://github.com/aslakhellesoy/cucumber-rails">cucumber-rails github page</a>.</p>
<p>The only modification I&#8217;ve made with the created structure is adding a folder for the page objects, so the final structure is this:</p>
<p><a rel="attachment wp-att-519" href="http://blog.franktrindade.com/2011/03/04/page-model-with-cucumber-and-capybara/screen-shot-2011-03-05-at-2-00-31-am/"><img class="alignnone size-full wp-image-519" title="Screen shot 2011-03-05 at 2.00.31 AM" src="http://blog.franktrindade.com/wp-content/uploads/2011/03/Screen-shot-2011-03-05-at-2.00.31-AM.png" alt="" width="219" height="162" /></a></p>
<p>As you can see, inside the pages folder there is a home page file, which is responsible for every action/assertion related to the home page.</p>
<p>Nothing new with the cucumber features, which keep having it&#8217;s standard style</p>
<p><code>Feature: Manage tasks<br />
In order to manage my tasks,<br />
a user<br />
wants to create tasks in different categories</p>
<p>Scenario: Create a new task<br />
Given I am in the Do Me home page<br />
When I create an urgent and important task with description "my task"<br />
Then I should see "my task" in the "Urgent and Important" section<br />
</code></p>
<p>However, in order to create our page object, we need to inject the test driver on it, which in Capybara&#8217;s case, is the session object.</p>
<p><code>Given /^I am in the home page$/ do<br />
@home_page = HomePage.new(Capybara.current_session)<br />
@home_page.visit<br />
end</p>
<p>When /^I create an urgent and important task with description "([^"]*)"$/ do |task_description|<br />
@home_page.fill_task_description(task_description)<br />
@home_page.check_important<br />
@home_page.check_urgent<br />
@home_page.create_task<br />
end</code></p>
<p>And from there is just the trouble of creating the page class (or do like me, who shamelessly copied the style from <a href="http://watirmelon.com/2011/01/21/my-simple-cucumber-watir-page-object-pattern-framework/">here</a>).</p>
<p><code><br />
class HomePage<br />
</code</p>
<p><code><br />
URL = "/"</p>
<p>def initialize(session)<br />
@session = session<br />
end</p>
<p>def visit<br />
@session.visit URL<br />
end</p>
<p>def fill_task_description(description)<br />
@session.fill_in("Description", :with =&gt; description)<br />
end</p>
<p>def check_urgent<br />
check("Urgent")<br />
end</p>
<p>def check_important<br />
check("Important")<br />
end</p>
<p>def create_task<br />
@session.click_button("Create Task")<br />
end<br />
</code></p>
<p>And that&#8217;s pretty much it, now is just choosing your preferred driver and run the tests. As you can see, not much effort for a nice improvement.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.franktrindade.com/2011/03/04/page-model-with-cucumber-and-capybara/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails 2.3 New Features</title>
		<link>http://blog.franktrindade.com/2009/02/02/rails-23-new-features/</link>
		<comments>http://blog.franktrindade.com/2009/02/02/rails-23-new-features/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 12:21:18 +0000</pubDate>
		<dc:creator>franktrindade</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails 2.3]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.franktrindade.com/?p=199</guid>
		<description><![CDATA[In the set of new features from Rails 2.3, I was quite pleased by two of them: nested attributes and nested forms. Both allow the creation of forms containing information about more than just one model, and may solve a recurrent problem I had in past projects, which has lead to some painful headaches&#8230; Can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>In the set of new features from <a href="http://guides.rubyonrails.org/2_3_release_notes.html" target="_blank">Rails 2.3</a>, I was quite pleased by two of them: nested attributes and nested forms.</p>
<p>Both allow the creation of forms containing information about more than just one model, and may solve a recurrent problem I had in past projects, which has lead to some painful headaches&#8230;</p>
<p>Can&#8217;t wait to try it!</p>
<p>More information (<a href="http://guides.rubyonrails.org/2_3_release_notes.html">source</a>):</p>
<h3 id="_nested_attributes">3.1. Nested Attributes</h3>
<div class="paragraph">
<p>Active Record can now update the attributes on nested models directly, provided you tell it to do so:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-weight: bold;"><span style="color: #0000ff;">class</span></span> Book <span style="color: #990000;">&lt;</span> ActiveRecord<span style="color: #990000;">::</span>Base
  has_one <span style="color: #990000;">:</span>author
  has_many <span style="color: #990000;">:</span>pages

  accepts_nested_attributes_for <span style="color: #990000;">:</span>author<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>pages
<span style="font-weight: bold;"><span style="color: #0000ff;">end

</span></span></tt></pre>
<h3 id="_nested_object_forms">5.1. Nested Object Forms</h3>
<div class="paragraph">
<p>Provided the parent model accepts nested attributes for the child objects (as discussed in the Active Record section), you can create nested forms using <tt>form_for</tt> and <tt>field_for</tt>. These forms can be nested arbitrarily deep, allowing you to edit complex object hierarchies on a single view without excessive code. For example, given this model:</div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-weight: bold;"><span style="color: #0000ff;">class</span></span> Customer <span style="color: #990000;">&lt;</span> ActiveRecord<span style="color: #990000;">::</span>Base
  has_many <span style="color: #990000;">:</span>orders

  accepts_nested_attributes_for <span style="color: #990000;">:</span>orders<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>allow_destroy <span style="color: #990000;">=&gt;</span> <span style="font-weight: bold;"><span style="color: #0000ff;">true</span></span>
<span style="font-weight: bold;"><span style="color: #0000ff;">end</span></span></tt></pre>
</div>
</div>
<div class="paragraph">
<p>You can write this view in Rails 2.3:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #ff0000;">&lt;% form_for @customer do |customer_form| %&gt;</span>
  <span style="color: #ff0000;">&lt;div&gt;</span>
    <span style="color: #ff0000;">&lt;%= customer_form.label :name, 'Customer Name:' %&gt;</span>
    <span style="color: #ff0000;">&lt;%= customer_form.text_field :name %&gt;</span>
  <span style="color: #ff0000;">&lt;/div&gt;</span>

  <span style="color: #990000;">&lt;!--</span> Here we call fields_for on the customer_form
       builder instance<span style="color: #990000;">.</span> The block is called <span style="font-weight: bold;"><span style="color: #0000ff;">for</span></span> each
       member of the orders collection<span style="color: #990000;">.</span> <span style="color: #990000;">--&gt;</span>
  <span style="color: #ff0000;">&lt;% customer_form.fields_for :orders do |order_form| %&gt;</span>
      <span style="color: #ff0000;">&lt;p&gt;</span>
        <span style="color: #ff0000;">&lt;div&gt;</span>
          <span style="color: #ff0000;">&lt;%= order_form.label :number, 'Order Number:' %&gt;</span>
          <span style="color: #ff0000;">&lt;%= order_form.text_field :number %&gt;</span>
        <span style="color: #ff0000;">&lt;/div&gt;</span>

  <span style="color: #990000;">&lt;!--</span> The allow_destroy option <span style="font-weight: bold;"><span style="color: #0000ff;">in</span></span> the model
       enables deletion of child records<span style="color: #990000;">.</span> <span style="color: #990000;">--&gt;</span>
        <span style="color: #ff0000;">&lt;% unless order_form.object.new_record? %&gt;</span>
          <span style="color: #ff0000;">&lt;div&gt;</span>
            <span style="color: #ff0000;">&lt;%= order_form.label :_delete, 'Remove:' %&gt;</span>
            <span style="color: #ff0000;">&lt;%= order_form.check_box :_delete %&gt;</span>
          <span style="color: #ff0000;">&lt;/div&gt;</span>
        <span style="color: #ff0000;">&lt;% end %&gt;</span>
      <span style="color: #ff0000;">&lt;/p&gt;</span>
    <span style="color: #ff0000;">&lt;% end %&gt;</span>
  <span style="color: #ff0000;">&lt;% end %&gt;</span>

  <span style="color: #ff0000;">&lt;%= customer_form.submit %&gt;</span>
<span style="color: #ff0000;">&lt;% end %&gt;</span></tt></pre>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.franktrindade.com/2009/02/02/rails-23-new-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

