[Ruby] Testing Models in Rails
Eric Hodel
drbrain at segment7.net
Thu Jul 26 23:41:33 PDT 2007
On Jul 26, 2007, at 10:19, Aaron Patterson wrote:
> On Thu, Jul 26, 2007 at 01:33:31PM -0700, Laurel Fan wrote:
>> On 7/26/07, Aaron Patterson <aaron at tenderlovemaking.com> wrote:
>>> This seems like it should be easy, but I can't figure it out! I
>>> have a
>>> model that defines a before_update callback, and I want to assert
>>> that
>>> that callback is set. But I don't want to save the object
>>> because I'm
>>> trying to avoid hitting the database.
>>
>> Why are you trying to avoid hitting the database? I would imagine
>> that avoiding the database makes it hard to test much of anything.
>
> Because hitting the database is expensive. Actually I've found that
> I can test most of my code without hitting the database. It makes my
> tests much faster. The problem here is that I don't know how to
> assert
> that my callback is defined *without* hitting the database.
>
> I trust that the active record callback chain works properly when I
> call
> save. I just want to make sure that my callback is in that chain.
I looked into how its stored, and its beyond me. Maybe you can
figure something out.
User.inheritable_attributes[:before_update] seems to record something
related to before_update.
--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars
More information about the Ruby
mailing list