I''m using thoughtbot''s shoulda, and I have this in a model:
validates_inclusion_of :year, :in => %w[ 09-10 10-11 ]
where :year is of type string. How do I test this in shoulda? Is it
with
(1) should ensure_inclusion_of
or do I have to do
(2) should allow_value(''09-10'').for(:year) and the should_not
equivalents?
So? (2) seems verbose... I mean, having to do a bunch of should''s and
should_not''s?
--
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.
David Kahn
2010-Dec-21 03:55 UTC
Re: Shoulda Question: how to test validates_inclusion_of...?
On Mon, Dec 20, 2010 at 9:28 PM, daze <dmonopoly10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m using thoughtbot''s shoulda, and I have this in a model: > > validates_inclusion_of :year, :in => %w[ 09-10 10-11 ] > > where :year is of type string. How do I test this in shoulda? Is it > with > (1) should ensure_inclusion_of > or do I have to do > (2) should allow_value(''09-10'').for(:year) and the should_not > equivalents? > > > So? (2) seems verbose... I mean, having to do a bunch of should''s and > should_not''s? >I would be curious if there was another way if I understand exactly what you are doing, but I think (2) is what you have to do... seems to me it is similar to validating the format of an attribute. Although, you might have to change your structure but seems that somehow you could use "should include_value_in_range"... (see http://rubydoc.info/github/thoughtbot/shoulda/master/Shoulda/ActiveRecord/Macros )> > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-21 03:58 UTC
Re: Shoulda Question: how to test validates_inclusion_of...?
On Mon, Dec 20, 2010 at 9:55 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote:> > > On Mon, Dec 20, 2010 at 9:28 PM, daze <dmonopoly10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> I''m using thoughtbot''s shoulda, and I have this in a model: >> >> validates_inclusion_of :year, :in => %w[ 09-10 10-11 ] >> >> where :year is of type string. How do I test this in shoulda? Is it >> with >> (1) should ensure_inclusion_of >> or do I have to do >> (2) should allow_value(''09-10'').for(:year) and the should_not >> equivalents? >> >> >> So? (2) seems verbose... I mean, having to do a bunch of should''s and >> should_not''s? >> > > I would be curious if there was another way if I understand exactly what > you are doing, but I think (2) is what you have to do... seems to me it is > similar to validating the format of an attribute. > > Although, you might have to change your structure but seems that somehow > you could use "should include_value_in_range"... > > (see > http://rubydoc.info/github/thoughtbot/shoulda/master/Shoulda/ActiveRecord/Macros > ) >Oops, I was looking at deprecated stuff... anyhow you would probably have to change your structure to something numeric or date-like to use ensure_inclusion_of but maybe in the end that would be the right way to do it.> > >> >> -- >> >> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.