[Ruby] Testing Models in Rails

Ryan Davis ryand-ruby at zenspider.com
Fri Jul 27 21:09:28 PDT 2007


On Jul 27, 2007, at 05:32 , Aaron Patterson wrote:

> This is what I've got so far:
>
>   def assert_callback(model_class, callback, method_name, message=nil)
>     assert(
>       (vars = model_class\
>         .instance_variable_get(:@inheritable_attributes)).key? 
> (callback) &&
>       vars[callback].include?(method_name), message)
>   end

How about?

   def assert_callback(model_class, callback, method_name, message=nil)
     vars = model_class.instance_variable_get(:@inheritable_attributes)
     assert vars.has_key?(callback), message
     assert_include vars[callback], method_name, message
   end

> Its not perfect, but you can say:
>
>   assert_callback(Model, :before_save, :something)

I like it, alot, but I like it better cleaned up.

P.S. I don't recommend it, but you can use a trailing dot instead of  
backslash-return-dot:

obj.
   msg(args).
   msg(args).
   etc



More information about the Ruby mailing list