# How to test a plugin with an around\_filter?

**URL:** <https://www.ruby-forum.com/t/how-to-test-a-plugin-with-an-around-filter/89037>\
**Category:** Rails\
**Created:** [March 16, 2007, 5:59pm UTC](https://www.ruby-forum.com/t/how-to-test-a-plugin-with-an-around-filter/89037 "2007-03-16T17:59:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [March 16, 2007, 5:59pm UTC](https://www.ruby-forum.com/t/how-to-test-a-plugin-with-an-around-filter/89037/1 "2007-03-16T17:59:59Z")

</div>

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/](http://svn.techno-weenie.net/projects/plugins/)  
[2] [http://dev.rubyonrails.org/svn/rails/plugins/](http://dev.rubyonrails.org/svn/rails/plugins/)  
[3] [http://topfunky.net/svn/plugins/](http://topfunky.net/svn/plugins/)

Thanks and regards,  
Andy S.
