<?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>Web Dev Bros &#187; Testing</title>
	<atom:link href="http://www.webdevbros.net/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Thu, 20 Jan 2011 19:55:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ASP.Net MVC, Fluent Validation and testing</title>
		<link>http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/</link>
		<comments>http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 15:40:58 +0000</pubDate>
		<dc:creator>Dai Bok</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.net MVC]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=932</guid>
		<description><![CDATA[In this post, I will show you how I set up fluent validation, to work smoothly with my MVC 2 project. I create a custom model binder to validate view models and show how to validate a registration using fluent validation. Finally I show how to unit test the validation rules I needed for registration.]]></description>
			<content:encoded><![CDATA[<p>I am finally coming to the end of a project, and I thought it would be good to write a little post on how we have managed to set up our fluent validation for our MVC project. In the start we did some research into how to go about performing validation, and found a number of recommendations. But all involved using data annotations. In this post, I will show you how I set up fluent validation, to work smoothly with my MVC 2 project. I create a custom model binder to validate view models and show how to validate a registration using fluent validation. Finally I show how to unit test the validation rules I needed for registration.
</p>
<p>To start with, there are some problems I have with data annotations
<p>1 –  Too many annotations  make your model s look ugly. <a href="http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs ">Take this example</a> . </p>
<p>
   <span style='color:blue'>public</span> <span style='color:blue'>class</span> <span style='color:#2B91AF'>Product</span> { </br><br />
     &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>int</span> Id { <span style='color:blue'> get </span> ; <span style='color:blue'> set </span> ; }<br />
</br><br />
 &nbsp;  &nbsp; &nbsp; [<span style='color:#2B91AF'>Required</span>]<br />
 &nbsp;  &nbsp; &nbsp; [<span style='color:#2B91AF'>StringLength</span>(10)]<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>string</span> Name { <span style='color:blue'>get</span>; <span style='color:blue'>set</span>; } </p>
<p> &nbsp;  &nbsp; &nbsp; [<span style='color:#2B91AF'>Required</span>]<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>string</span> Description { <span style='color:blue'>get</span>; <span style='color:blue'>set</span>; }</p>
<p> &nbsp;  &nbsp; &nbsp; [<span style='color:#2B91AF'>DisplayName</span>(<span style='color:#A31515'>&quot;Price&quot;</span>)]<br />
 &nbsp;  &nbsp; &nbsp; [<span style='color:#2B91AF'>Required</span>]<br />
 &nbsp;  &nbsp; &nbsp; [<span style='color:#2B91AF'>RegularExpression</span>(<span style='color:#A31515'>@&quot;^\$?\d+(\.(\d{2}))?$&quot;</span>)]<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>decimal</span> UnitPrice { <span style='color:blue'>get</span>; <span style='color:blue'>set</span>; }<br />
 &nbsp;  &nbsp; &nbsp;}</p>
<p>Now wouldn’t it be nice to have your model/entity just look like this. </p>
<p><span style='color:blue'>public</span> <span style='color:blue'>class</span> <span style='color:#2B91AF'>Product</span> <br />
{<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>int</span> Id { <span style='color:blue'>get</span>; <span style='color:blue'>set</span>; }<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>string</span> Name { <span style='color:blue'>get</span>; <span style='color:blue'>set</span>; }<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>string</span> Description { <span style='color:blue'>get</span>; <span style='color:blue'>set</span>; }<br />
 &nbsp;  &nbsp; &nbsp; <span style='color:blue'>public</span> <span style='color:blue'>decimal</span> UnitPrice { <span style='color:blue'>get</span>;<span style='color:blue'>set</span>; }<br />
}</p>
<p>2 – Complex data validation with attributes makes your code get even more ugly.<a href=" http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx "> Take a lot at this example showing how</a> to achieve slightly more complexity with data annotations. Now trying to reuse and share attributes seem to make things more and more complex&#8230;.</p>
<p> 3- I think there may be a performance issue, as we need to extract the validation attributes using reflection. Now, while these are simple models, with simple validation rules, we may not notice the performance degrading, but I am sure that with numerous complex attributes, things might run a little slow. (I need to prove this though – maybe when I get time, I will write some tests – I could be wrong here, things might change in MVC 3) </p>
<p> So after looking at some examples, such as<a href="http://xval.codeplex.com/"> xVal –dead now</a>, <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2007/10/24/entity-validation-with-visitors-and-extension-methods.aspx"> Entity validation with visitors and extension methods </a>these all did the job, but I would need to write lots of helpers, what I needed was some kind of framework for validation. <a href="http://fluentvalidation.codeplex.com/">Then I found fluent validation.</a>
</p>
<h3>Linking MVC with Fluent Validation </h3>
<p></p>
<p>So let us look at how we set our MVC project . Firstly, I want to automate the validation, so that any errors are automically added to the models state.  With some <a href="http://fluentvalidation.codeplex.com/Thread/View.aspx?ThreadId=76865">help from Jeremy</a>  I set up an customised BindAndValidate attribute.  Here is a simplified attribute we started with. </p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">BindAndValidateAttribute</span> : <span style="color: #2b91af;">CustomModelBinderAttribute</span>,&nbsp; <span style="color: #2b91af;">IModelBinder</span> {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">AttributedValidatorFactory</span> validatorFactory = <span style="color: blue;">new</span> <span style="color: #2b91af;">AttributedValidatorFactory</span>();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">override</span> <span style="color: #2b91af;">IModelBinder</span> GetBinder() {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: blue;">this</span>;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">object</span> BindModel(<span style="color: #2b91af;">ControllerContext</span> controllerContext, <span style="color: #2b91af;">ModelBindingContext</span> bindingContext) {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;10</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> innerBinder = <span style="color: blue;">new</span> <span style="color: #2b91af;">DefaultModelBinder</span>();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> boundInstance = innerBinder.BindModel(controllerContext, bindingContext);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (boundInstance != <span style="color: blue;">null</span>)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ValidateInstance(boundInstance, bindingContext);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;15</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> boundInstance;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;16</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;17</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;18</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> ValidateInstance(<span style="color: blue;">object</span> instance, <span style="color: #2b91af;">ModelBindingContext</span> context) {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;19</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> validator = validatorFactory.GetValidator(context.ModelType);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;20</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (validator != <span style="color: blue;">null</span>)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;21</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;22</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> result = validator.Validate(instance);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;23</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; result.AddToModelState(context.ModelState, <span style="color: #a31515;">&quot;&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;24</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;25</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;26</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></p>
<p>Now all I need to do is hook this up with my controller method. In the Sign in method, I add the attribute [BindAndValidatiate] and all I need to do is check that the model state is valid. If so, I perform the log in.</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">AccountController</span> : <span style="color: #2b91af;">BaseController</span> {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> Signin() {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> View();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">HttpPost</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> Signin([<span style="color: #2b91af;">BindAndValidate</span>] <span style="color: #2b91af;">ChangeEmailModel</span> model) {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (ModelState.IsValid)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;10</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PerformSignIn();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> View();</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></p>
<h3>Linking MVC View Models with Fluent Validation</h3>
<p></p>
<p>Lets look at how all this works. What we need to do is create out model, then create our validator. We then hook our validator to our model by adding the validator atrribute to our model. I am using a simple Register View Model here as an example.</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Validator</span>(<span style="color: blue;">typeof</span>(<span style="color: #2b91af;">RegisterViewModelValidator</span>))]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">RegisterViewModel</span></p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">string</span> Email { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">string</span> Password { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">string</span> ConfirmPassword { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></p>
<p>Now for the model validator. Here we have some simple rules. The password must not be empty, and it must also be a good password. The password confirmation must be the same as the password, and finally the Email must be a valid email address, and also not already exisit in our site. </p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">RegisterViewModelValidator</span> : <span style="color: #2b91af;">AbstractValidator</span>&lt;<span style="color: #2b91af;">RegisterViewModel</span>&gt; {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> RegisterViewModelValidator() {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RuleFor(reg =&gt; reg.Password)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .NotEmpty()</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .WithMessage(<span style="color: #a31515;">&quot;Please provide a password&quot;</span>)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .Must(BeGoodPassword)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .WithMessage(<span style="color: #a31515;">&quot;Password must be at least 8 characters long, and contain numbers and letters&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RuleFor(reg =&gt; reg.ConfirmPassword)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;10</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .Equal(reg =&gt; reg.Password)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .WithMessage(<span style="color: #a31515;">&quot;Passwords do not match&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RuleFor(reg =&gt; reg.Email)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .EmailAddress()</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;15</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .WithMessage(<span style="color: #a31515;">&quot;Invalid Email&quot;</span>)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;16</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .Must(BeUniqueEmail)</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;17</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .WithMessage(<span style="color: #a31515;">&quot;Account already Registered&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;18</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;19</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;20</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> BeGoodPassword(<span style="color: blue;">string</span> password) {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;21</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Regex</span> regex = <span style="color: blue;">new</span> <span style="color: #2b91af;">Regex</span>(<span style="color: #a31515;">@&quot;^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;22</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> regex.IsMatch(password);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;23</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;24</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;25</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> BeUniqueEmail(<span style="color: blue;">string</span> email) {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;26</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> count = <span style="color: #2b91af;">Repository</span>.GetInstance().CountOccurrencesOfEmail(email);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;27</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> (count == 0);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;28</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;29</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></p>
<h3>Test your validation</h3>
<p>Now, finally for the testing, whcih is really useful, when I want to make sure that things work 100%! To keep it simepl, I am just going to test the password rule, because testing the email requires a lot more of an explination. So working from some <a href="http://fluentvalidation.codeplex.com/wikipage?title=Testing">simple examples Here: </a>I have written three tests. Thfirst is to make sure that the password can not be null. The second is to catch a week password. The third makes sure that a strong password does not cause an error. </p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Should_have_error_when_Password_is_null() {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; validator.ShouldHaveValidationErrorFor(reg =&gt; reg.Password, <span style="color: blue;">null</span> <span style="color: blue;">as</span> <span style="color: blue;">string</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Should_have_error_when_Password_is_weak() {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; validator.ShouldHaveValidationErrorFor(reg =&gt; reg.Password, <span style="color: #a31515;">&quot;weakpass&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;10</span>&nbsp;</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;11</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;12</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Should_not_have_error_when_Password_is_strong() {</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;13</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Validator.ShouldNotHaveValidationErrorFor(reg =&gt; reg.Password, <span style="color: #a31515;">&quot;SecretPassword123&quot;</span>);</p>
<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;&nbsp;14</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></p>
<p>And that is it! There is quite a lot you can achieve with fluent validation, such as <a href="http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&#038;referringTitle=Documentation&#038;ANCHOR#ReusingValidators">reusing validators</a>  on complex properties and also some useful conditions like<a href="http://fluentvalidation.codeplex.com/wikipage?title=Customising&#038;referringTitle=Documentation&#038;ANCHOR#WhenUnless"> when or unless</a>! The reasons I like this are that it uses generics to help build clean code. There is now no need to attributes on every property I have. Also, Jeremy was also very quick to help with any questions I had. <a href="http://www.jeremyskinner.co.uk/">Thanks for the help Jeremy.</a> </p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/&amp;t=ASP.Net+MVC%2C+Fluent+Validation+and+testing&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/&amp;title=ASP.Net+MVC%2C+Fluent+Validation+and+testing&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/&amp;title=ASP.Net+MVC%2C+Fluent+Validation+and+testing&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=ASP.Net+MVC%2C+Fluent+Validation+and+testing;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2010/12/03/asp-net-mvc-fluent-validation-and-tesing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing code changes, bugfixes, new features, …</title>
		<link>http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/</link>
		<comments>http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 23:00:52 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[general stuff]]></category>
		<category><![CDATA[programming style]]></category>

		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=14</guid>
		<description><![CDATA[When you implement a new feature somewhere, when you change just some bits of your code, when you fix a bug, or you just change a common text in an app&#8230; What do you do afterwards? Do you really check the result or do you trust yourself that it works fine 100%. It is an [...]]]></description>
			<content:encoded><![CDATA[<p>When you implement a new feature somewhere, when you change just some bits of your code, when you fix a bug, or you just change a common text in an app&#8230; What do you do afterwards? Do you really check the result or do you trust yourself that it works fine 100%. It is an interesting thing to talk about…<span id="more-14"></span></p>
<p>I have to be honest and admit that I trusted myself a lot of times in the early days and at least 2 of 10 times I was wrong. If you deal with customers then it&#8217;s two times too much. Especially when you have that guy on the phone and you claim that you did change it, but he is browsing the application and does not see any changes. In that case you&#8217;re really pissed because you haven&#8217;t spent one minute to check the result/consequence of your change.</p>
<p>So that&#8217;s why I always suggest to check EVERYTHING that has been changed. You never know what you forget, but when you get sure that you see the change yourself then you&#8217;re on the safe side. Here is a list what you could not have thought about:</p>
<ul>
<li>you have been working in the wrong file. The file you have been working on was just a backup, in the wrong location, wrong server, etc. Such things happen everyday. </li>
<li>you forgot to refresh/restart some service, application, etc. </li>
<li>forgot to publish the file. This is common but i am sure it happens as well. For instance you forgot to upload the file on the server if its a web app. </li>
<li>forgot to compile. for all out there who need to do this. </li>
<li>last but not least programing failures which you haven&#8217;t thought about (especially when you are changing code of others you should 100% check the effect of the change even if it&#8217;s just a typo): you changed the wrong part of the code. Happens usually when there are duplicate pieces of code, which in turn happens because of bad programming style (think of the DRY principle).
</li>
</ul>
<p>Hence it&#8217;s highly recommended to check EVERY change. You save yourself and others a lot of troubles and iterations of changing and testing. Personally I think that this is a programmers quality characteristic and that it&#8217;s not a tall order to expect a check of the change. In most cases it&#8217;s less than a minute. Don&#8217;t get lazy …. For sure everybody does, but be aware of all the points I mentioned above. </p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/&amp;t=Testing+code+changes%2C+bugfixes%2C+new+features%2C+%E2%80%A6&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/&amp;title=Testing+code+changes%2C+bugfixes%2C+new+features%2C+%E2%80%A6&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/&amp;title=Testing+code+changes%2C+bugfixes%2C+new+features%2C+%E2%80%A6&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Testing+code+changes%2C+bugfixes%2C+new+features%2C+%E2%80%A6;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2009/08/20/testing-a-change-bugfix-implemented-feature-%e2%80%a6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bulk testing your model attributes with rails</title>
		<link>http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/</link>
		<comments>http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 11:20:39 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/</guid>
		<description><![CDATA[When it comes to testing in Ruby on Rails I tend to test every piece of its public interface. This means I test every single public method and attribute to ensure my desired functionality. Recently I've updated my application from Rails 1.2.5 to 2.0.1 and I was happy to have tests. None of them failed [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to testing in Ruby on Rails I tend to test every piece of its public interface. This means I test every single public method and attribute to ensure my desired functionality. Recently I've updated my application from Rails 1.2.5 to <a href="http://weblog.rubyonrails.org/2007/12/7/rails-2-0-it-s-done">2.0.1</a> and I was happy to have tests. None of them failed and so I knew that my application is ready to rock with the new Rails 2.0.<br />
However, what I want to write in this article about is how to do bulk testing of each single attribute of your models. Let's be a bit precise. Say we have a model <code>User</code> which has attributes <code>firstname</code>, <code>lastname</code>and <code>age</code>. In order to perfectly test the <code>User</code> model we should write tests which ...</p>
<ol>
<li>ensure that invalid values result in an error for the tested attribute (e.g. age -2 is invalid, so the instance should hold an error for the attribute <code>age</code>)</li>
<li>and valid values don't result in an error for the tested attribute (e.g. age 20 should be fine)</li>
</ol>
<p>Usually you should test a couple of invalid values and a couple of valid values against each attribute of your model. This can be quite a lot to code. I explain a nice approach how to speed things up and save time for the next family event.<span id="more-130"></span></p>
<p>(Code below has been tested with Rails 1.2.5 and Rails 2.0.1) Let's say our User class looks the following:</p>
<div class="igBar"><span id="lruby-6"><a href="#" onclick="javascript:showCodeTxt('ruby-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-6">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> User &lt;ActiveRecord::Base</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_length_of :firstname, :<span style="color:#9966CC; font-weight:bold;">in</span> =&gt; <span style="color:#006666;color:#800000;">2</span>..<span style="color:#006666;color:#800000;">255</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_length_of :lastname, :<span style="color:#9966CC; font-weight:bold;">in</span> =&gt; <span style="color:#006666;color:#800000;">3</span>..<span style="color:#006666;color:#800000;">255</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_numericality_of :age, :only_integer =&gt; <span style="color:#0000FF; font-weight:bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; protected</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> validate</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; errors.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>:age, <span style="color:#996600;">"must be greater 0 and maximum 100"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> age.<span style="color:#0000FF; font-weight:bold;">nil</span>? || <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1</span>..<span style="color:#006666;color:#800000;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>age<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I don't go too much into detail about this. Simply: It's a <code>User</code> which is bound to a <code>Users</code> database table and includes three validations:</p>
<ul>
<li>the firstname should have at least 2 chars and maximum 255</li>
<li>the firstname should have at least 3 chars and maximum 255</li>
<li>the age must be a number greater than 0 and maximum 100</li>
</ul>
<p>Best case would be if we completele test the <code>User</code> model for the following cases (testing that wrong values fail and correct values don't fail):</p>
<ul>
<li>valid firstnames: <code>michal, tom, John, Jennifer K, David</code></li>
<li>invalid firstname: 	<code>nil, J, ''</code></li>
<li>valid lastnames: <code>gabrukiewicz, Aniston, Heinemeier Hansson</code></li>
<li>invalid lastnames: <code>nil, gr, t, ''</code></li>
<li>valid ages: <code>1, 10, 20, 73</code></li>
<li>invalid ages: <code>nil, '', 0, -10, -36, x, 7sz, 101, 120</code></li>
<li>creating a valid User and successfully saving (not described in this article)</li>
<li>get an existing user, modify some attributes and save (not described in this article))</li>
</ul>
<p>Here we defined what is wrong and what not (what is even better: you could write this tests even before you write your <code>User</code> model). In order to do the bulk testing I have written a helper method which will do the stuff for us in a Rails-way. We put this method into our <code>test_helper.rb</code> so its available to all our test cases:</p>
<div class="igBar"><span id="lruby-7"><a href="#" onclick="javascript:showCodeTxt('ruby-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-7">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#tests ONE attribute of the tested model (@model must be set in setup method of the testcase) against given values.</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#expecting: what do we expect the values to be (:valid or :invalid)</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#attr: the tested attribute (provide an array if the error key differs from the attribute name)</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#vals: the values you want to test against</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>expecting, attr, vals<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> ArgumentError, 'model must be set to the testing model' <span style="color:#9966CC; font-weight:bold;">if</span> @model.<span style="color:#9900CC;">blank</span>?</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; key = att = attr</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; att, key = attr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, attr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> attr.<span style="color:#9900CC;">is_a</span>? <span style="color:#CC0066; font-weight:bold;">Array</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; vals.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |v|</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m = @model.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>att =&gt; v<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m.<span style="color:#9900CC;">valid</span>?</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; errors = m.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">on</span><span style="color:#006600; font-weight:bold;">&#40;</span>key<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> expecting == :valid</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; assert errors.<span style="color:#0000FF; font-weight:bold;">nil</span>?, <span style="color:#996600;">"'#{v}' should be a valid #{att.to_s} (#{errors})"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; assert !errors.<span style="color:#0000FF; font-weight:bold;">nil</span>?, <span style="color:#996600;">"'#{v}' should be an invalid #{att.to_s}"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You see that the method expects the attribute we want to test (<code>attr</code>), the tested values (<code>vals</code>) and what we expect the values to be (<code>expecting</code>) - valid or invalid. Furthermore you see that the tested model is taken from the instance variable (<code>@model</code>) which will be taken from your individual test case (placed into the <code>setup</code> method). Thats to stick with DRY (cause every unit test deals with one model). Last but not least the helper <strong>asserts with a nice error message</strong> which eases us up to find the problem .. if there is one.<br />
Ok enough, we can use this now for the test of our <code>User</code>. Rails generated the <code>UserTest</code> for us when we generated the model. We test our attributes <code>firstname</code>, <code>lastname</code> and <code>age</code>. All for validity and invalidity.</p>
<div class="igBar"><span id="lruby-8"><a href="#" onclick="javascript:showCodeTxt('ruby-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-8">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> UserTest &lt;Test::Unit::TestCase</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> setup</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @model = User</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_firstname</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:valid, :firstname, <span style="color:#006600; font-weight:bold;">&#91;</span>'michal', 'tom', 'John', 'Jennifer K', 'David'<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:invalid, :lastname, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, 'J', ''<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Thats nice but at this point we stop. We are not testing <code>lastname</code> and <code>age</code> anymore because before we do so we DRY this a bit up. We add another helper method which uses our existing <code>attr_test</code> and tests the invalid and valid values in one go. After that we sit back and watch our tests run. Bung this method into your <code>test_helper.rb</code> ..</p>
<div class="igBar"><span id="lruby-9"><a href="#" onclick="javascript:showCodeTxt('ruby-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-9">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#this checks valid and invalid attributes in one go.</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#- check attr_test to understand more details if necessary</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>attr, values<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:invalid, attr, values<span style="color:#006600; font-weight:bold;">&#91;</span>:invalid<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:valid, attr, values<span style="color:#006600; font-weight:bold;">&#91;</span>:valid<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>with this we are ready to rock our <code>User</code> class. See the full test now...</p>
<div class="igBar"><span id="lruby-10"><a href="#" onclick="javascript:showCodeTxt('ruby-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-10">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> UserTest &lt;Test::Unit::TestCase</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> setup</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @model = User</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_firstname</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:firstname,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:valid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span>'michal', 'tom', 'John', 'Jennifer K', 'David'<span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:invalid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, 'J', ''<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_lastname</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:lastname,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:valid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span>'gabrukiewicz', 'Aniston', 'Heinemeier Hansson'<span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:invalid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, 'gr', 't', ''<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_age</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:age,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:valid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span>, <span style="color:#006666;color:#800000;">10</span>, <span style="color:#006666;color:#800000;">20</span>, <span style="color:#006666;color:#800000;">73</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:invalid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, '', <span style="color:#006666;color:#800000;">0</span>, -<span style="color:#006666;color:#800000;">10</span>, -<span style="color:#006666;color:#800000;">36</span>, x, 7sz, <span style="color:#006666;color:#800000;">101</span>, <span style="color:#006666;color:#800000;">120</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>That's it if the tests were successful then your model is working fine. If not then you will see helpful messages in your console which will indicate what went wrong during the attributes test.</p>
<p>I strongly recommend you to test all your models against the functionality you will use in your application(s) (all public class members). This takes a bit of time but it let's you sleep better after doing any upgrades, enhancements, bug fixes etc. And don't forget: never cheat on yourself when writing tests! you are writing them for you ...</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/&amp;t=Bulk+testing+your+model+attributes+with+rails&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/&amp;title=Bulk+testing+your+model+attributes+with+rails&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/&amp;title=Bulk+testing+your+model+attributes+with+rails&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Bulk+testing+your+model+attributes+with+rails;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

