Skip to content

Instantly share code, notes, and snippets.

@potomak
Created August 20, 2010 13:11
Show Gist options
  • Save potomak/540276 to your computer and use it in GitHub Desktop.
Save potomak/540276 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe AdminController do
before { login }
it "should be accessible only by admins!"
end
def current_user(stubs = {})
@current_user ||= mock_model(User, stubs)
end
def user_session(stubs = {}, user_stubs = {})
@current_user ||= mock_model(UserSession, {:user => current_user(user_stubs)}.merge(stubs))
end
def login(session_stubs = {}, user_stubs = {})
UserSession.stub!(:find).and_return(user_session(session_stubs, user_stubs))
end
def logout
@user_session = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment