[Ruby] Testing Models in Rails

Laurel Fan laurel.fan at gmail.com
Thu Jul 26 13:33:31 PDT 2007


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.

If the general problem is that you can't have a test database on your
real database server, and can't install your own instance of it,
sqlite is really easy to set up
(http://wiki.rubyonrails.org/rails/pages/HowtoUseSQLite).

If you need to do this for just this one test you could close the
connection (eg. user.connection.disconnect!) and possibly reopen it
after if you need it again (reconnect!).

-- 
Laurel Fan
http://blog.gorgorg.org


More information about the Ruby mailing list