Forum: Ruby on Rails validates_acceptance_of + functional testing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-08 16:57
(Received via mailing list)
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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-08 18:31
(Received via mailing list)
On 2/8/06, Joe Van Dyk <joevandyk@gmail.com> 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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-08 18:33
(Received via mailing list)
On 2/8/06, Joe Van Dyk <joevandyk@gmail.com> 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
8792eb3f43fc92c20ee61b66cb620842?d=identicon&s=25 Paul Ingles (Guest)
on 2006-02-09 13:04
Joe Van Dyk wrote:
> On 2/8/06, Joe Van Dyk <joevandyk@gmail.com> 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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-02-09 17:12
(Received via mailing list)
On 2/9/06, Paul Ingles <paul.ingles@gmail.com> 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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-02-12 08:11
(Received via mailing list)
On Feb 9, 2006, at 8:12 AM, Joe Van Dyk 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 Hodel - drbrain@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
This topic is locked and can not be replied to.