<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Testing in Rails: Part 7 - ActiveRecord Relationships</title>
	<atom:link href="http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/</link>
	<description>Code for Coders</description>
	<pubDate>Sun, 14 Mar 2010 12:19:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Taylor</title>
		<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/comment-page-1/#comment-1350</link>
		<dc:creator>Taylor</dc:creator>
		<pubDate>Thu, 08 Jan 2009 17:07:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/#comment-1350</guid>
		<description>This is an excellent post!  I'm glad I finally found it.  I have only one comment - I would suggest NOT having one big "test_relationships" method, but rather breaking up the tests into, for example, "test_belongs_to_winery" and "test_has_and_belongs_to_many_varietals".

This is partly personal style, but there is a good reason behind it too.  For one thing, if you have one big method, and the belongs_to test breaks, it precludes the later tests from being run.  So one failure can mask another.  For another, using smaller methods lets you name them more descriptively.

Great post though - thanks!</description>
		<content:encoded><![CDATA[<p>This is an excellent post!  I&#8217;m glad I finally found it.  I have only one comment - I would suggest NOT having one big &#8220;test_relationships&#8221; method, but rather breaking up the tests into, for example, &#8220;test_belongs_to_winery&#8221; and &#8220;test_has_and_belongs_to_many_varietals&#8221;.</p>
<p>This is partly personal style, but there is a good reason behind it too.  For one thing, if you have one big method, and the belongs_to test breaks, it precludes the later tests from being run.  So one failure can mask another.  For another, using smaller methods lets you name them more descriptively.</p>
<p>Great post though - thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marty McGee</title>
		<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/comment-page-1/#comment-1314</link>
		<dc:creator>Marty McGee</dc:creator>
		<pubDate>Thu, 27 Nov 2008 15:50:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/#comment-1314</guid>
		<description>This is by far the most helpful post about Rails 2+ model relationship testing I have found.  And just to keep the ball rolling, I wanted to point out that with Foxy Fixtures in Rails 2+, we don't even need to setup the join table fixtures (in this case, "varietals_wines").  Saves some time and effort and keeps tests running accurately in the future.  For instance, with the awesome HABTM relationship test Kevin has shared with us, we can simply omit the varietals_wines.yml fixture and have our wine unit test look this this...

class WineTest &lt; ActiveSupport::TestCase
  # omitted unneeded :varietals_wines fixture
  fixtures :wines, :wineries, :varietals

  def setup
    ...
    @bordeaux = wines(:bordeaux)
  end
 
  def test_relationships
    ...
    # has_and_belongs_to_many :varietals
    assert_equal(3, @bordeaux.varietals.count)
    @bordeaux.varietals.each do &#124;var&#124;
      assert(var.wines.include?(@bordeaux))
    end
    (Varietal.find(:all) - @bordeaux.varietals).each do &#124;var&#124;
      assert(!var.wines.include?(@bordeaux))
    end
    assert_equal("Cabernet Franc", @bordeaux.varietals.sort_by {&#124;v&#124; v.name}.first.name)
  end
end</description>
		<content:encoded><![CDATA[<p>This is by far the most helpful post about Rails 2+ model relationship testing I have found.  And just to keep the ball rolling, I wanted to point out that with Foxy Fixtures in Rails 2+, we don&#8217;t even need to setup the join table fixtures (in this case, &#8220;varietals_wines&#8221;).  Saves some time and effort and keeps tests running accurately in the future.  For instance, with the awesome HABTM relationship test Kevin has shared with us, we can simply omit the varietals_wines.yml fixture and have our wine unit test look this this&#8230;</p>
<p>class WineTest &lt; ActiveSupport::TestCase<br />
  # omitted unneeded :varietals_wines fixture<br />
  fixtures :wines, :wineries, :varietals</p>
<p>  def setup<br />
    &#8230;<br />
    @bordeaux = wines(:bordeaux)<br />
  end</p>
<p>  def test_relationships<br />
    &#8230;<br />
    # has_and_belongs_to_many :varietals<br />
    assert_equal(3, @bordeaux.varietals.count)<br />
    @bordeaux.varietals.each do |var|<br />
      assert(var.wines.include?(@bordeaux))<br />
    end<br />
    (Varietal.find(:all) - @bordeaux.varietals).each do |var|<br />
      assert(!var.wines.include?(@bordeaux))<br />
    end<br />
    assert_equal(&#8221;Cabernet Franc&#8221;, @bordeaux.varietals.sort_by {|v| v.name}.first.name)<br />
  end<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Skoglund</title>
		<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/comment-page-1/#comment-1231</link>
		<dc:creator>Kevin Skoglund</dc:creator>
		<pubDate>Mon, 04 Aug 2008 13:48:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/#comment-1231</guid>
		<description>@Denis: Yes, that would work too.  As long as you understand the difference.

In my example, the idea is that I'm testing two things to make sure they are the EXACT value I expect.  In your example, the idea is that you don't care what value they have, just that they are equal.  If @merlot.winery_id and @merlot.winery.id both have a value of 4 then my tests will fail and yours will pass.

The way you decide to write your tests will determine if that distinction makes a difference or not.</description>
		<content:encoded><![CDATA[<p>@Denis: Yes, that would work too.  As long as you understand the difference.</p>
<p>In my example, the idea is that I&#8217;m testing two things to make sure they are the EXACT value I expect.  In your example, the idea is that you don&#8217;t care what value they have, just that they are equal.  If @merlot.winery_id and @merlot.winery.id both have a value of 4 then my tests will fail and yours will pass.</p>
<p>The way you decide to write your tests will determine if that distinction makes a difference or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Denis</title>
		<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/comment-page-1/#comment-1230</link>
		<dc:creator>Denis</dc:creator>
		<pubDate>Mon, 04 Aug 2008 03:56:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/#comment-1230</guid>
		<description>In the first relationship test, you wrote:
  def test_relationships
    # belongs_to :winery
    assert_equal(1, @merlot.winery_id)
    assert_equal(1, @merlot.winery.id)
[...]

Could we just write this?
  def test_relationships
    # belongs_to :winery
    assert_equal(@merlot.winery.id, @merlot.winery_id)
[...]


Thanks
Denis</description>
		<content:encoded><![CDATA[<p>In the first relationship test, you wrote:<br />
  def test_relationships<br />
    # belongs_to :winery<br />
    assert_equal(1, @merlot.winery_id)<br />
    assert_equal(1, @merlot.winery.id)<br />
[...]</p>
<p>Could we just write this?<br />
  def test_relationships<br />
    # belongs_to :winery<br />
    assert_equal(@merlot.winery.id, @merlot.winery_id)<br />
[...]</p>
<p>Thanks<br />
Denis</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Improbabilidades</title>
		<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/comment-page-1/#comment-1064</link>
		<dc:creator>Improbabilidades</dc:creator>
		<pubDate>Tue, 18 Mar 2008 14:12:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/#comment-1064</guid>
		<description>&lt;strong&gt;Testing relationships in&#160;Rails...&lt;/strong&gt;

Ler este artigo em português
I've been looking for an elegant way to test relationships using Rais, and think it's interesting how so few people really care about it. Most simply say that it's up to the framework to test it's o...</description>
		<content:encoded><![CDATA[<p><strong>Testing relationships in&nbsp;Rails&#8230;</strong></p>
<p>Ler este artigo em português<br />
I&#8217;ve been looking for an elegant way to test relationships using Rais, and think it&#8217;s interesting how so few people really care about it. Most simply say that it&#8217;s up to the framework to test it&#8217;s o&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Fresh Cup &#187; Blog Archive &#187; Double Shot #120</title>
		<link>http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/comment-page-1/#comment-877</link>
		<dc:creator>A Fresh Cup &#187; Blog Archive &#187; Double Shot #120</dc:creator>
		<pubDate>Wed, 09 Jan 2008 12:00:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/08/testing-in-rails-part-7-activerecord-relationships/#comment-877</guid>
		<description>[...] Testing in Rails: Part 7 - ActiveRecord Relationships - More from Null is Love. [...]</description>
		<content:encoded><![CDATA[<p>[...] Testing in Rails: Part 7 - ActiveRecord Relationships - More from Null is Love. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
