Functional test puzzle with validates_acceptance_of

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:


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?


def create
@user =[:user])

(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
assert_difference(‘User.count’) do
post :create, :user => {:invitation_token => @invitation.token,
:email => @test_email, :login =>
:password => @test_password,
:password_confirmation => @test_password,
:age_over_13 => 1,
:terms_of_service => 1}

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?