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-J0of1frlU80@public.gmane.org'' 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2011-01-17, at 9:51 AM, adam wrote:> > 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.What happens if you do this: u = Factory.build(:valid_user) u.tc_check = true u.save! Luke -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks, but I have tried that - I get the same result. Validation seems to get called on build as well as create. On Jan 17, 9:20 pm, Luke Cowell <lcow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2011-01-17, at 9:51 AM, adam wrote: > > > > > 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. > > What happens if you do this: > > u = Factory.build(:valid_user) > u.tc_check = true > u.save! > > Luke-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
OK, I think I have the answer. The docs say: http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_acceptance_of ... The default value is a string “1”, which makes it easy to relate to an HTML checkbox. So simply change your factory line to this: Factory.create(:valid_user, :tc_check => "1") Luke On 2011-01-18, at 12:57 AM, adam wrote:> Thanks, but I have tried that - I get the same result. > Validation seems to get called on build as well as create. > > On Jan 17, 9:20 pm, Luke Cowell <lcow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 2011-01-17, at 9:51 AM, adam wrote: >> >> >> >>> 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. >> >> What happens if you do this: >> >> u = Factory.build(:valid_user) >> u.tc_check = true >> u.save! >> >> Luke > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Thank you ! that was the problem... :) On Jan 19, 3:57 pm, Luke Cowell <lcow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OK, I think I have the answer. > > The docs say:http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMeth... > > ... The default value is a string “1”, which makes it easy to relate to an HTML checkbox. > > So simply change your factory line to this: > > Factory.create(:valid_user, :tc_check => "1") > > Luke > > On 2011-01-18, at 12:57 AM, adam wrote: > > > > > Thanks, but I have tried that - I get the same result. > > Validation seems to get called on build as well as create. > > > On Jan 17, 9:20 pm, Luke Cowell <lcow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On 2011-01-17, at 9:51 AM, adam wrote: > > >>> 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. > > >> What happens if you do this: > > >> u = Factory.build(:valid_user) > >> u.tc_check = true > >> u.save! > > >> Luke > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.