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
Joe Van Dyk
2006-Feb-08 17:31 UTC
[Rails] Re: validates_acceptance_of + functional testing
On 2/8/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> 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?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
Joe Van Dyk
2006-Feb-08 17:32 UTC
[Rails] Re: validates_acceptance_of + functional testing
On 2/8/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> On 2/8/06, Joe Van Dyk <joevandyk@gmail.com> wrote: > > 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? > > 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
Paul Ingles
2006-Feb-09 12:04 UTC
[Rails] Re: validates_acceptance_of + functional testing
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? > > JoeWell, 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 -- Posted via http://www.ruby-forum.com/.
Joe Van Dyk
2006-Feb-09 16:12 UTC
[Rails] Re: validates_acceptance_of + functional testing
On 2/9/06, Paul Ingles <paul.ingles@gmail.com> wrote:> 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?It is possible to test it, you just have to put :terms_and_conditions => "0" into the POST params when testing. Joe
On Feb 9, 2006, at 8:12 AM, Joe Van Dyk wrote:> On 2/9/06, Paul Ingles <paul.ingles@gmail.com> wrote: >> >> 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? > > 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