# Validates\_acceptance\_of + functional testing

**URL:** <https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530>\
**Category:** Rails\
**Created:** [February 8, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530 "2006-02-08T16:57:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 8, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530/1 "2006-02-08T16:57:12Z")

</div>

I had to add a check box indicating that a user accepted certain terms  
to a page. So, I put in a ‘validates\_acceptance\_of :terms’ line into  
the appropriate model and added a checkbox to my view. Everything  
works as expected in my web browser.

However, my functional tests still pass and I didn’t add or change  
anything to them. I was expecting to have to add another field called  
‘terms’ into the POST parameters for the test that tests that  
particular area of code. But it’s still passing just fine.

Is there any special going on with validates\_acceptance\_of and  
testing? Or are my tests just really bad?

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 8, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530/2 "2006-02-08T18:31:48Z")

</div>

On 2/8/06, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there any special going on with validates\_acceptance\_of and  
> testing? Or are my tests just really bad?

Ah, figured it out. If I add  
:terms =\> “0”  
to the POST parameters in the test, then the test will fail.

I’m a bit surprised that validates\_acceptance\_of apparently works fine  
if the validated field is not in the view.

Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 8, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530/3 "2006-02-08T18:33:05Z")

</div>

On 2/8/06, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Is there any special going on with validates\_acceptance\_of and  
> > testing? Or are my tests just really bad?
> 
> Ah, figured it out. If I add  
> :terms =\> “0”  
> to the POST parameters in the test, then the test will fail.
> 
> I’m a bit surprised that validates\_acceptance\_of apparently works fine  
> if the validated field is not in the view.

I just confirmed it. I removed the checkbox from my view, left the  
validates\_acceptance\_of code in the model and no errors are thrown.  
Is this the expected behavior?

Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 9, 2006, 1:04pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530/4 "2006-02-09T13:04:06Z")

</div>

Joe Van D. wrote:

> On 2/8/06, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > Is there any special going on with validates\_acceptance\_of and  
> > > testing? Or are my tests just really bad?
> > 
> > Ah, figured it out. If I add  
> > :terms =\> “0”  
> > to the POST parameters in the test, then the test will fail.
> > 
> > I’m a bit surprised that validates\_acceptance\_of apparently works fine  
> > if the validated field is not in the view.
> 
> I just confirmed it. I removed the checkbox from my view, left the  
> validates\_acceptance\_of code in the model and no errors are thrown.  
> Is this the expected behavior?
> 
> Joe

Well, looking at the code for ActiveRecord it is the intended behaviour.  
However, as you say, this kind of means that TDD functional testing  
isn’t possible when testing these validators. Since I’m a relative Rails  
newbie, TDDing has been essential in letting me verify my assumptions,  
so this kind of behaviour is a little misleading.

Can anyone think of a reason why you’d want to consider validation to  
have passed if the value were nil?

Paul

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 12, 2006, 8:11am UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530/5 "2006-02-12T08:11:49Z")

</div>

On Feb 9, 2006, at 8:12 AM, Joe Van D. wrote:

> > Can anyone think of a reason why you’d want to consider validation to  
> > have passed if the value were nil?
> 
> It is possible to test it, you just have to put  
> :terms\_and\_conditions =\> “0”  
> into the POST params when testing.

Um, no.

Changing the implementation should always cause a test to fail. I  
would file a bug.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [February 9, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-functional-testing/53530/6 "2006-02-09T17:12:51Z")

</div>

On 2/9/06, Paul I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > I’m a bit surprised that validates\_acceptance\_of apparently works fine  
> > > isn’t possible when testing these validators. Since I’m a relative Rails  
> > > newbie, TDDing has been essential in letting me verify my assumptions,  
> > > so this kind of behaviour is a little misleading.
> 
> Can anyone think of a reason why you’d want to consider validation to  
> have passed if the value were nil?

It is possible to test it, you just have to put  
:terms\_and\_conditions =\> “0”  
into the POST params when testing.

Joe
