Hello, Using shoulda, any ideas how to allow blank when having this test: should validate_uniqueness_of(:email) Thanks. -- J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) -- 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.
:allow_blank => true On Jun 15, 3:26 pm, J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> wrote:> Hello, > > Using shoulda, any ideas how to allow blank when having this test: > > should validate_uniqueness_of(:email) > > Thanks. > -- > J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com)-- 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.
J. Pablo Fernández
2010-Jun-17 05:28 UTC
Re: Re: Allow blank on should validate_uniqueness_of
Where do you pass that? should validate_uniqueness_of(:email, :allow_blank => true) That doesn''t work. That method takes only one argument: /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:429:in `validate_uniqueness_of'': wrong number of arguments (2 for 1) (ArgumentError) from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:429:in `send'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:429:in `method_missing'' from ./test/unit/meta_data_test.rb:14:in `__bind_1276752425_894930'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:306:in `call'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:306:in `merge_block'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:301:in `initialize'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:199:in `new'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/shoulda-2.11.0/lib/shoulda/context.rb:199:in `context'' from ./test/unit/meta_data_test.rb:8 from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in `load_without_new_constant_marking'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:147:in `load'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5 from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'' from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5 On Tue, Jun 15, 2010 at 22:46, chewmanfoo <chewmanfoo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> :allow_blank => true > > On Jun 15, 3:26 pm, J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> wrote: >> Hello, >> >> Using shoulda, any ideas how to allow blank when having this test: >> >> should validate_uniqueness_of(:email) >> >> Thanks. >> -- >> J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) > > -- > 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. > >-- J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) -- 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.
On Jun 17, 1:28 am, J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> wrote:> Where do you pass that? > > should validate_uniqueness_of(:email, :allow_blank => true) > > That doesn''t work. That method takes only one argument:group/rubyonrails-talk?hl=en.> > -- > J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com)Here is a link to the validation method doc: http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001400 You should be able to use :allow_blank => true, unless your version of Rails does not support the option, which I guess could be possible? If that is the case you should be able to use :if or :unless: Supposing your model is for a customer: # The ''c'' inside the proc represents the customer record you''re validating (you can, of course, use any variable name you want). validate_uniqueness_of :email, :unless => Proc.new {|c| c.email.blank?} You have to take into consideration that if your DB table has a unique constraint on the e-mail column you''ll still run into problems because the DB itself will not let you add 2 records with an empty e-mail address, only one. The second attempt will fail. Hope it helps. -- 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.
2010/6/15 J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org>:> Hello, > > Using shoulda, any ideas how to allow blank when having this test: > > should validate_uniqueness_of(:email)I think there is confusion about your question. Are you asking how to allow blank in the validation itself (in which case allows_blank in the call of validates_uniqueness of is the way to go) or are you asking how to code the test to check that multiple blank emails are allowed? Colin -- 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.
On 17 June 2010 09:18, pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:> On Jun 17, 1:28 am, J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> wrote: >> Where do you pass that? >> >> should validate_uniqueness_of(:email, :allow_blank => true) >> >> That doesn''t work. That method takes only one argument: > group/rubyonrails-talk?hl=en. >> >> -- >> J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) > > Here is a link to the validation method doc: > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001400 > > You should be able to use :allow_blank => true, unless your version of > Rails does not support the option, which I guess could be possible? If > that is the case you should be able to use :if or :unless: > > Supposing your model is for a customer: > > # The ''c'' inside the proc represents the customer record you''re > validating (you can, of course, use any variable name you want). > validate_uniqueness_of :email, :unless => Proc.new {|c| > c.email.blank?} > > You have to take into consideration that if your DB table has a unique > constraint on the e-mail column you''ll still run into problems because > the DB itself will not let you add 2 records with an empty e-mail > address, only one. The second attempt will fail.Is the solution to allow null for the email rather than empty string? Will the unique constraint fail in that case? Colin -- 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.
I''m asking how to test the validation with shoulda with the new syntax, hence the line: should validate_uniqueness_of(:email) On Thu, Jun 17, 2010 at 10:45, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2010/6/15 J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org>: >> Hello, >> >> Using shoulda, any ideas how to allow blank when having this test: >> >> should validate_uniqueness_of(:email) > > I think there is confusion about your question. Are you asking how to > allow blank in the validation itself (in which case allows_blank in > the call of validates_uniqueness of is the way to go) or are you > asking how to code the test to check that multiple blank emails are > allowed? > > Colin > > -- > 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. > >-- J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) -- 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.
J. Pablo Fernández
2010-Jun-17 08:50 UTC
Re: Re: Allow blank on should validate_uniqueness_of
pepe, I''m not asking how to do the validation, I''m asking how to test the validation with shoulda using the new syntax, I already have this line in the model: validate_uniqueness_of :email, :allow_blank => true in my tests I have: should validate_uniqueness_of(:email) should being a shoulda method. On Thu, Jun 17, 2010 at 10:18, pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:> On Jun 17, 1:28 am, J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> wrote: >> Where do you pass that? >> >> should validate_uniqueness_of(:email, :allow_blank => true) >> >> That doesn''t work. That method takes only one argument: > group/rubyonrails-talk?hl=en. >> >> -- >> J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) > > Here is a link to the validation method doc: > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001400 > > You should be able to use :allow_blank => true, unless your version of > Rails does not support the option, which I guess could be possible? If > that is the case you should be able to use :if or :unless: > > Supposing your model is for a customer: > > # The ''c'' inside the proc represents the customer record you''re > validating (you can, of course, use any variable name you want). > validate_uniqueness_of :email, :unless => Proc.new {|c| > c.email.blank?} > > You have to take into consideration that if your DB table has a unique > constraint on the e-mail column you''ll still run into problems because > the DB itself will not let you add 2 records with an empty e-mail > address, only one. The second attempt will fail. > > Hope it helps. > > -- > 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. > >-- J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) -- 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.
No, allowing blank is fine, the validation is this: validate_uniqueness_of(:email, :allow_blank => true) The issue is writing the test. On Jun 17, 10:47 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 17 June 2010 09:18, pepe <P...-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote: > > > > > > > On Jun 17, 1:28 am, J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> wrote: > >> Where do you pass that? > > >> should validate_uniqueness_of(:email, :allow_blank => true) > > >> That doesn''t work. That method takes only one argument: > > group/rubyonrails-talk?hl=en. > > >> -- > >> J. Pablo Fernández <pup...-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com) > > > Here is a link to the validation method doc: > > >http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMeth... > > > You should be able to use :allow_blank => true, unless your version of > > Rails does not support the option, which I guess could be possible? If > > that is the case you should be able to use :if or :unless: > > > Supposing your model is for a customer: > > > # The ''c'' inside the proc represents the customer record you''re > > validating (you can, of course, use any variable name you want). > > validate_uniqueness_of :email, :unless => Proc.new {|c| > > c.email.blank?} > > > You have to take into consideration that if your DB table has a unique > > constraint on the e-mail column you''ll still run into problems because > > the DB itself will not let you add 2 records with an empty e-mail > > address, only one. The second attempt will fail. > > Is the solution to allow null for the email rather than empty string? > Will the unique constraint fail in that case? > > Colin-- 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.