Monday, January 17, 2011

[Rails] Factory Girl and attr_accessor with validation

I have a problem with a recent change to one of my models when created
via Factory.create.

class User < ActiveRecord::Base

attr_accessor :tc_check

validates :tc_check, :presence => true, :acceptance => true

...
end

The following definition fails, when calling
Factory.create(:valid_user)

Factory.define :valid_user, :class => User do |u|
u.email 'barry.white@test.com'
u.phone_number '(925) 555-1212'
u.active true
u.tc_check true
end

It falls over on validation - Validation failed: Tc check must be
accepted (ActiveRecord::RecordInvalid)

I've also tried setting it when called create like
Factory.create(:valid_user, :tc_check => true) which has the same
result.

Any way of setting this before validation so that I can get it to pass
the tests?

Thanks
Adam

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate