I have a custom function, for kicks: def find_newest Card.find(:last) end In my unit test I want to: assert_kind_of(Card,Card.find_newest) But I get the "method not found" error. What am I missing? -Tom --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rather, it should be noted that find_newest is in my model... On Jun 16, 2:20 pm, "sullivan.t" <sulliva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a custom function, for kicks: > > def find_newest > Card.find(:last) > end > > In my unit test I want to: > > assert_kind_of(Card,Card.find_newest) > > But I get the "method not found" error. > > What am I missing? > > -Tom--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 answered my own thought... in the unit test, I have an object, created via fixtures, @c and I am able to call the proper method, and get back the proper value, passing the assertion. (I figured I would stuff "find newest" into the model) On Jun 16, 2:20 pm, "sullivan.t" <sulliva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a custom function, for kicks: > > def find_newest > Card.find(:last) > end > > In my unit test I want to: > > assert_kind_of(Card,Card.find_newest) > > But I get the "method not found" error. > > What am I missing? > > -Tom--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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
2008-Jun-16 19:23 UTC
Re: Testing custom model functions in unit tests...
On Jun 16, 8:16 pm, "sullivan.t" <sulliva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I answered my own thought... in the unit test, I have an object, > created via fixtures, @c and I am able to call the proper method, and > get back the proper value, passing the assertion.What you shoud probably do is create find_newest as a class method, ie def self.find_newest ... end rather than requiring an instance of the class for something that is not specific to any particular instance Fred> > (I figured I would stuff "find newest" into the model) > > On Jun 16, 2:20 pm, "sullivan.t" <sulliva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a custom function, for kicks: > > > def find_newest > > Card.find(:last) > > end > > > In my unit test I want to: > > > assert_kind_of(Card,Card.find_newest) > > > But I get the "method not found" error. > > > What am I missing? > > > -Tom--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
And don''t write the Card constant within the method once you do this, since self in a class method is the class. def self.find_newest find(:last) end On Jun 16, 3:23 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 16, 8:16 pm, "sullivan.t" <sulliva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I answered my own thought... in the unit test, I have an object, > > created via fixtures, @c and I am able to call the proper method, and > > get back the proper value, passing the assertion. > > What you shoud probably do is create find_newest as a class method, ie > > def self.find_newest > ... > end > > rather than requiring an instance of the class for something that is > not specific to any particular instance > > Fred > > > > > (I figured I would stuff "find newest" into the model) > > > On Jun 16, 2:20 pm, "sullivan.t" <sulliva...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a custom function, for kicks: > > > > def find_newest > > > Card.find(:last) > > > end > > > > In my unit test I want to: > > > > assert_kind_of(Card,Card.find_newest) > > > > But I get the "method not found" error. > > > > What am I missing? > > > > -Tom--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
> In my unit test I want to: > > assert_kind_of(Card,Card.find_newest) > > But I get the "method not found" error.After you apply the ''def self.find_newest'', look up my assert_latest, to learn its Card.maximum(:id) trick: http://www.oreillynet.com/onlamp/blog/2007/07/assert_latest_and_greatest.html Note that the online version of assert_latest is fully productized... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Interesting. Thanks for the thoughts, guys! On Jun 16, 9:07 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In my unit test I want to: > > > assert_kind_of(Card,Card.find_newest) > > > But I get the "method not found" error. > > After you apply the ''def self.find_newest'', look up my assert_latest, to learn > its Card.maximum(:id) trick: > > http://www.oreillynet.com/onlamp/blog/2007/07/assert_latest_and_great... > > Note that the online version of assert_latest is fully productized...--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---