Validates_acceptance_of + functional testing

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

On 2/8/06, Joe Van D. [email protected] 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

On 2/8/06, Joe Van D. [email protected] 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

Joe Van D. wrote:

On 2/8/06, Joe Van D. [email protected] 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

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. - [email protected] - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

On 2/9/06, Paul I. [email protected] 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