Skip to content

Instantly share code, notes, and snippets.

@milk1000cc
Created May 25, 2009 10:14
Show Gist options
  • Save milk1000cc/117483 to your computer and use it in GitHub Desktop.
Save milk1000cc/117483 to your computer and use it in GitHub Desktop.
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
def signed_in_user_context(&blk)
describe "で、ログインしているとき" do
before { login }
merge_block(&blk)
end
end
def public_context(&blk)
describe "で、ログインしていないとき" do
before { logout }
merge_block(&blk)
end
end
def should_deny_access
it 'は、アクセスが拒絶されること' do
response.should redirect_to(new_user_session_url)
end
end
def merge_block(&blk)
blk.bind(self).call
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment