Hi, I''m converting some AR classes into modules and moving their attributes to whatever AR classes formerly held the association. I''m finding it hard to test these modules. I think I want to use a tableless AR model in my module tests. I just define one of these -- with the attributes the module needs -- in the test file and use it in the test. This works, but not for all AR methods. In particular, I run into errors when I invoke certain AR methods that seem to require the presence of a table. So, simply put, how do I get a fully functional AR model for use in testing, without an accompanying migration? Any thoughts? Thanks, Lille -- 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.
Frederick Cheung
2011-May-16 14:47 UTC
Re: how best to test modules for ''mixing-in'' with AR classes?
On May 16, 3:37 pm, Lille <lille.pengu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m converting some AR classes into modules and moving their > attributes to whatever AR classes formerly held the association. > > I''m finding it hard to test these modules. > > I think I want to use a tableless AR model in my module tests. I just > define one of these -- with the attributes the module needs -- in the > test file and use it in the test. This works, but not for all AR > methods. In particular, I run into errors when I invoke certain AR > methods that seem to require the presence of a table. > > So, simply put, how do I get a fully functional AR model for use in > testing, without an accompanying migration? >not entirely what you ask, but how about creating an in memory sqlite3 database and creating tables in there (you don''t need a migration file - you can have the table creating stuff in your test''s setup) ? Fred> Any thoughts? > > Thanks, > > Lille-- 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.
Lille
2011-May-16 15:01 UTC
Re: how best to test modules for ''mixing-in'' with AR classes?
Thanks! So, maybe I automate the creation of the in-memory database with a rake task for the test? If not, what do you think? I think an issue here is that my modules assuming their parents are AR classes. Is that really modular? Lille On May 16, 10:47 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 16, 3:37 pm, Lille <lille.pengu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > Hi, > > > I''m converting some AR classes into modules and moving their > > attributes to whatever AR classes formerly held the association. > > > I''m finding it hard to test these modules. > > > I think I want to use a tableless AR model in my module tests. I just > > define one of these -- with the attributes the module needs -- in the > > test file and use it in the test. This works, but not for all AR > > methods. In particular, I run into errors when I invoke certain AR > > methods that seem to require the presence of a table. > > > So, simply put, how do I get a fully functional AR model for use in > > testing, without an accompanying migration? > > not entirely what you ask, but how about creating an in memory > sqlite3 database and creating tables in there (you don''t need a > migration file - you can have the table creating stuff in your test''s > setup) ? > > Fred > > > > > > > > > Any thoughts? > > > Thanks, > > > Lille-- 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.
Frederick Cheung
2011-May-16 17:28 UTC
Re: Re: how best to test modules for ''mixing-in'' with AR classes?
On 16 May 2011, at 16:01, Lille <lille.penguini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks! > > So, maybe I automate the creation of the in-memory database with a > rake task for the test? If not, what do you think? > > I think an issue here is that my modules assuming their parents are AR > classes. Is that really modular?Depends on what your code does - if it is inherently very active-recordy stuff then that''s probably ok. If it is legitimate to include the module in a non activerecord class then I''d aim to do that in tests too. Fred.> > Lille > > On May 16, 10:47 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On May 16, 3:37 pm, Lille <lille.pengu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >> >> >> >> >>> Hi, >> >>> I''m converting some AR classes into modules and moving their >>> attributes to whatever AR classes formerly held the association. >> >>> I''m finding it hard to test these modules. >> >>> I think I want to use a tableless AR model in my module tests. I just >>> define one of these -- with the attributes the module needs -- in the >>> test file and use it in the test. This works, but not for all AR >>> methods. In particular, I run into errors when I invoke certain AR >>> methods that seem to require the presence of a table. >> >>> So, simply put, how do I get a fully functional AR model for use in >>> testing, without an accompanying migration? >> >> not entirely what you ask, but how about creating an in memory >> sqlite3 database and creating tables in there (you don''t need a >> migration file - you can have the table creating stuff in your test''s >> setup) ? >> >> Fred >> >> >> >> >> >> >> >>> Any thoughts? >> >>> Thanks, >> >>> Lille > > -- > 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. >-- 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.