[Ruby] Testing Models in Rails

Aaron Patterson aaron at tenderlovemaking.com
Thu Jul 26 09:51:30 PDT 2007


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.


Here is a short example model:

class User < ActiveRecord::Base
  before_update :do_stuff

  def do_stuff
    self.name = 'L Richie'
    self.current_mood = 'All night long'
  end
end

I want to make sure that "do_stuff" is in the callbacks, but I don't
want to save the model and assert that that stuff happened.  Does anyone
have any suggestions for testing situations like this?

-- 
Aaron Patterson
http://tenderlovemaking.com/


More information about the Ruby mailing list