Hello,
Does anybody know how to test a plugin module that looks like the one
below? It’s designed to be included by a controller, typically the
application controller.
My specific questions are:
- Can I get at my do_before and do_after methods from a unit test to
probe them individually? - How can I set up a fake request into which I can stuff various
values for the HTTP_REFERER header? - How can I then get an appropriate fake reponse?
Also, is using a class variable the correct way to hold my_data?
module MyModule
@@my_data = []
@@my_data << %w( foo bar baz )
def self.included(controller)
controller.around_filter :my_method
end
protected
def my_method
do_before
yield
do_after
end
private
def do_before
unless request.env[‘HTTP_REFERER’].blank?
# do stuff, using my @@data
end
end
def do_after
# do stuff with response.body
end
end
I have tried mangling a functional test and also looked at various
plugins from the usual suspects[1-3] but the penny still hasn’t dropped.
[1] http://svn.techno-weenie.net/projects/plugins/
[2] http://dev.rubyonrails.org/svn/rails/plugins/
[3] http://topfunky.net/svn/plugins/
Thanks and regards,
Andy S.