1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
This commit is contained in:
Samuel Cochran 2011-06-23 10:44:46 +08:00
parent 80122856c4
commit e75354b3b0
6 changed files with 73 additions and 1 deletions

View file

@ -101,6 +101,54 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
assert_contain 'Private!'
end
test 'signed in as admin should get admin dashboard' do
sign_in_as_admin
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get dashboard_path
assert_response :success
assert_template 'home/admin'
assert_contain 'Admin dashboard'
end
test 'signed in as user should get user dashboard' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
get dashboard_path
assert_response :success
assert_template 'home/user'
assert_contain 'User dashboard'
end
test 'not signed in should get no dashboard' do
assert_raises ActionController::RoutingError do
get dashboard_path
end
end
test 'signed in user should not see join page' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
assert_raises ActionController::RoutingError do
get join_path
end
end
test 'not signed in should see join page' do
get join_path
assert_response :success
assert_template 'home/join'
assert_contain 'Join'
end
test 'signed in as user should not be able to access admins actions' do
sign_in_as_user
assert warden.authenticated?(:user)

View file

@ -5,6 +5,15 @@ class HomeController < ApplicationController
def private
end
def user_dashboard
end
def admin_dashboard
end
def join
end
def set
session["devise.foo_bar"] = "something"
head :ok

View file

@ -0,0 +1 @@
Admin dashboard

View file

@ -0,0 +1 @@
Join

View file

@ -0,0 +1 @@
User dashboard

View file

@ -27,7 +27,19 @@ Rails.application.routes.draw do
authenticate(:admin) do
match "/private", :to => "home#private", :as => :private
end
authenticated :admin do
match "/dashboard", :to => "home#admin_dashboard"
end
authenticated do
match "/dashboard", :to => "home#user_dashboard"
end
unauthenticated do
match "/join", :to => "home#join"
end
# Routes for constraints testing
devise_for :headquarters_admin, :class_name => "Admin", :path => "headquarters", :constraints => {:host => /192\.168\.1\.\d\d\d/}