before_filter

11 views
Skip to first unread message

skg

unread,
Jun 24, 2009, 6:34:37 AM6/24/09
to shoulda
I have a a controller say Contacts It has
include ContactsHelper
before_filter :user_enabled?

Now this user_enabled? is in Contacts helper

def user_enabled?
redirect_to root_path if Person.current.type.nil?
end


How can I write a test for the above I tried like below but not
working What I tried

context "Contact" do
setup do
login_as contacts(:administrator)
Contact.before_filter.expects(:user_enabled?).returns(false)
get :some_function
end
should_respond_with :success
end

But this never calls some_function in controller rather just it
redirects because Person.current.type.nil? is true How can I solve
this?

sk

Cynthia Kiser

unread,
Jun 26, 2009, 5:26:03 PM6/26/09
to sho...@googlegroups.com

Am I reading the expects line correctly? I think when user_enabled?
returns false, you should get the redirect to "/". I would have
thought that in order to fall through to :some_function that line
should return 'true'.

Contact.before_filter.expects(:user_enabled?).returns(false)

Or do I not understand your code? (I do admit to not doing a lot of
mocks/stubs because I don't fully understand them yet.)

Reply all
Reply to author
Forward
0 new messages