Testing custom model functions in unit tests

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

Rather, it should be noted that find_newest is in my model…

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)

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 C. [email protected]

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:

Note that the online version of assert_latest is fully productized…

On Jun 16, 8:16 pm, “sullivan.t” [email protected] 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

Interesting.

Thanks for the thoughts, guys!