# How do I unit test this?

**URL:** <https://www.ruby-forum.com/t/how-do-i-unit-test-this/193253>\
**Category:** Rails\
**Created:** [August 14, 2010, 4:40am UTC](https://www.ruby-forum.com/t/how-do-i-unit-test-this/193253 "2010-08-14T04:40:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [August 14, 2010, 4:40am UTC](https://www.ruby-forum.com/t/how-do-i-unit-test-this/193253/1 "2010-08-14T04:40:30Z")

</div>

I’ve got a cache sweeper running observing a model  
“after\_validation\_on\_update”. Inside that filter method, a call to  
“controller.current\_user” is made to access that  
application\_controller method (to get the current user in session).

I get the error “NoMethodError: undefined method `current\_user’ for  
nil:NilClass” when running my unit test because, by definition, there  
is no controller instantiated in a unit test. How do I get around  
this to test? Thanks for any help.
