Created
February 23, 2010 03:50
-
-
Save whalec/311836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WardenStub | |
def warden | |
@_warden ||= mock | |
end | |
def user | |
@_user ||= mock(User) | |
end | |
def mock_warden_for(*scopes) | |
scopes.each do |scope| | |
warden.stub!(:authenticate!).with(:scope => scope) | |
warden.stub!(:authenticated?).and_return(true) | |
warden.stub!(:user).and_return(user) | |
end | |
@controller.request.env['warden'] = warden | |
end | |
def mock_admin | |
mock_warden_for :user | |
user.stub!(:admin?).and_return(true) | |
end | |
def mock_non_admin | |
mock_warden_for :user | |
user.stub!(:admin?).and_return(false) | |
end | |
def mock_warden | |
mock_warden_for :user | |
user.stub!(:authenticated?).and_return(true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment