# Functional test puzzle with validates\_acceptance\_of

**URL:** <https://www.ruby-forum.com/t/functional-test-puzzle-with-validates-acceptance-of/179840>\
**Category:** Rails\
**Created:** [December 5, 2009, 1:04am UTC](https://www.ruby-forum.com/t/functional-test-puzzle-with-validates-acceptance-of/179840 "2009-12-05T01:04:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shalott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@shalott](https://www.ruby-forum.com/u/shalott)\
**Post date:** [December 5, 2009, 1:04am UTC](https://www.ruby-forum.com/t/functional-test-puzzle-with-validates-acceptance-of/179840/1 "2009-12-05T01:04:14Z")

</div>

Hi all, I can’t for the life of me figure out why this test is failing.

The code which works just fine in practice in the browser:

* * *

model:

# Virtual attribute for age check and terms of service

attr\_accessor :age\_over\_13  
attr\_accessor :terms\_of\_service  
attr\_accessible :age\_over\_13, :terms\_of\_service

validates\_acceptance\_of :terms\_of\_service,  
:allow\_nil =\> false,  
:message =\> “must accept tos”,  
:if =\> :first\_save?

validates\_acceptance\_of :age\_over\_13,  
:allow\_nil =\> false,  
:message =\> “must be over 13”,  
:if =\> :first\_save?

controller:

def create  
@user = User.new(params[:user])  
end

## (there’s more here but these are the relevant bits, I think)

The functional test that is failing:

* * *

## def test\_should\_create\_user @invitation = create\_invitation @test\_email = random\_email @test\_login = String.random @test\_password = random\_password debugger assert\_difference(‘User.count’) do post :create, :user =\> {:invitation\_token =\> @invitation.token, :email =\> @test\_email, :login =\> @test\_login, :password =\> @test\_password, :password\_confirmation =\> @test\_password, :age\_over\_13 =\> 1, :terms\_of\_service =\> 1} end end

When I run the debugger from the test, the user creation is failing on  
the age/tos values, which don’t seem to be getting set (the other values  
are set correctly). The failure occurs whether I pass the values 1, “1”,  
or “true”. The params[:user] has is correctly set in the controller.

In active\_record/base.rb initialize(),  
“attributes\_from\_column\_definition” does not include age\_over\_13 or  
terms\_of\_service, but I assume that’s correct, since these aren’t  
database columns, just “validates\_acceptance\_of” fields.

Any suggestions what might be going on?
