diff options
author | Azul <azul@leap.se> | 2012-11-04 21:01:27 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-11-04 21:01:27 +0100 |
commit | e1fc3f4850ee73e0591bd67a92b104db4f63e4cb (patch) | |
tree | 1207ce14cb1c2551a3fda09e7c670cc97182a0f6 /users/test/support | |
parent | c0f92bf9f481463dcaef6f4b30343130a8910a00 (diff) |
stubbing current_user the warden way
Diffstat (limited to 'users/test/support')
-rw-r--r-- | users/test/support/auth_test_helper.rb | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb index 9412058..f211597 100644 --- a/users/test/support/auth_test_helper.rb +++ b/users/test/support/auth_test_helper.rb @@ -1,17 +1,18 @@ module AuthTestHelper + extend ActiveSupport::Concern - def stub_logged_in - @user_id = stub - @user = stub - session[:user_id] = @user_id - User.expects(:find).once.with(@user_id).returns(@user) - return @user + # Controller will fetch current user from warden. + # Make it pick up our current_user + included do + setup do + request.env['warden'] ||= stub :user => nil + end end - def stub_logged_out - @user_id = stub - session[:user_id] = @user_id - User.expects(:find).once.with(@user_id).returns(nil) + def login(user = nil) + @current_user = user || stub + request.env['warden'] = stub :user => @current_user + return @current_user end def assert_access_denied(denied = true) |