<?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"
	>
<channel>
	<title>Comments on: Testing in Rails: Part 8 - Validations</title>
	<atom:link href="http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/</link>
	<description>Code for Coders</description>
	<pubDate>Thu, 28 Aug 2008 13:52:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Nicos Picos</title>
		<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1213</link>
		<dc:creator>Nicos Picos</dc:creator>
		<pubDate>Wed, 16 Jul 2008 15:50:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1213</guid>
		<description>Man.. really wish I had used helpers for the relationship stuff. Thanks for this tutorial, there is little good stuff on testing out there - and I found this very thorough and well written!</description>
		<content:encoded><![CDATA[<p>Man.. really wish I had used helpers for the relationship stuff. Thanks for this tutorial, there is little good stuff on testing out there - and I found this very thorough and well written!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicos Picos</title>
		<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1212</link>
		<dc:creator>Nicos Picos</dc:creator>
		<pubDate>Wed, 16 Jul 2008 15:49:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1212</guid>
		<description>I recommend for the helper that tests presence_of to use clone objects, because otherwise an error will be thrown in the reference for temp. In your example it works because you are just checking for the presence of literals. I found I was usually testing for the presence of other objects. Here is the edited code I used:

  # helper method used for validates_presence of
  def assert_presence_required(object, field)
    
    # Test that the initial object is valid
    assert_valid(object)
   
    # Test that it becomes invalid by removing the field
    temp = object.send(field)
    
    # CHANGE = use a clone because otherwise reference to the temp object is lost
    tempClone = temp.clone 
    object.send("#{field}=", nil)
    assert_invalid(object)
    assert(object.errors.invalid?(field), "Expected an error on validation")

    # CHANGE = set it to the clone now to make object valid again.
    object.send("#{field}=", tempClone)
    assert_valid(object)</description>
		<content:encoded><![CDATA[<p>I recommend for the helper that tests presence_of to use clone objects, because otherwise an error will be thrown in the reference for temp. In your example it works because you are just checking for the presence of literals. I found I was usually testing for the presence of other objects. Here is the edited code I used:</p>
<p>  # helper method used for validates_presence of<br />
  def assert_presence_required(object, field)</p>
<p>    # Test that the initial object is valid<br />
    assert_valid(object)</p>
<p>    # Test that it becomes invalid by removing the field<br />
    temp = object.send(field)</p>
<p>    # CHANGE = use a clone because otherwise reference to the temp object is lost<br />
    tempClone = temp.clone<br />
    object.send(&#8221;#{field}=&#8221;, nil)<br />
    assert_invalid(object)<br />
    assert(object.errors.invalid?(field), &#8220;Expected an error on validation&#8221;)</p>
<p>    # CHANGE = set it to the clone now to make object valid again.<br />
    object.send(&#8221;#{field}=&#8221;, tempClone)<br />
    assert_valid(object)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Skoglund</title>
		<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1211</link>
		<dc:creator>Kevin Skoglund</dc:creator>
		<pubDate>Wed, 16 Jul 2008 15:47:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1211</guid>
		<description>There is no reason not to use helpers anytime you are repeating yourself.  They make testing a lot easier.  I didn't use them through this tutorial because I wanted to make sure that the core concepts were clear.</description>
		<content:encoded><![CDATA[<p>There is no reason not to use helpers anytime you are repeating yourself.  They make testing a lot easier.  I didn&#8217;t use them through this tutorial because I wanted to make sure that the core concepts were clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicos Picos</title>
		<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1210</link>
		<dc:creator>Nicos Picos</dc:creator>
		<pubDate>Wed, 16 Jul 2008 15:04:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1210</guid>
		<description>Hey,

I was wondering how come you don't use such helper methods for testing relationships. Just spent an entire day writing relationship tests, and would have been a lot easier to just have templates (even for the setup could be nice to have a template that will set up all your fixtures according to parameters). 

Any reason not to do this?</description>
		<content:encoded><![CDATA[<p>Hey,</p>
<p>I was wondering how come you don&#8217;t use such helper methods for testing relationships. Just spent an entire day writing relationship tests, and would have been a lot easier to just have templates (even for the setup could be nice to have a template that will set up all your fixtures according to parameters). </p>
<p>Any reason not to do this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Skoglund</title>
		<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1089</link>
		<dc:creator>Kevin Skoglund</dc:creator>
		<pubDate>Tue, 08 Apr 2008 12:59:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1089</guid>
		<description>Good catch.  Thanks, David.</description>
		<content:encoded><![CDATA[<p>Good catch.  Thanks, David.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1088</link>
		<dc:creator>David</dc:creator>
		<pubDate>Tue, 08 Apr 2008 03:21:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.nullislove.com/2008/01/23/testing-in-rails-part-8-validations/#comment-1088</guid>
		<description>This is great and I can't wait for more, but I think you have a typo in your text for the error in the validates format with regex.  The code is right with the $ inside the / but the text shows them swapped.  Great series.

David</description>
		<content:encoded><![CDATA[<p>This is great and I can&#8217;t wait for more, but I think you have a typo in your text for the error in the validates format with regex.  The code is right with the $ inside the / but the text shows them swapped.  Great series.</p>
<p>David</p>
]]></content:encoded>
	</item>
</channel>
</rss>
