mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Added tests for flexible routing constraints
This commit is contained in:
parent
2d7dc3e82d
commit
37c55eb192
4 changed files with 57 additions and 1 deletions
|
@ -161,6 +161,28 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|||
assert_contain 'Private!'
|
||||
end
|
||||
|
||||
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
|
||||
sign_in_as_admin(:active => false)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
assert_raises ActionController::RoutingError do
|
||||
get "/private/active"
|
||||
end
|
||||
end
|
||||
|
||||
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
|
||||
sign_in_as_admin(:active => true)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
get private_active_path
|
||||
|
||||
assert_response :success
|
||||
assert_template 'home/private'
|
||||
assert_contain 'Private!'
|
||||
end
|
||||
|
||||
test 'signed in as admin should get admin dashboard (authenticated accepted)' do
|
||||
sign_in_as_admin
|
||||
assert warden.authenticated?(:admin)
|
||||
|
@ -191,6 +213,28 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
|
||||
sign_in_as_admin(:active => false)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
assert_raises ActionController::RoutingError do
|
||||
get "/dashboard/active"
|
||||
end
|
||||
end
|
||||
|
||||
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
|
||||
sign_in_as_admin(:active => true)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
get dashboard_active_path
|
||||
|
||||
assert_response :success
|
||||
assert_template 'home/admin_dashboard'
|
||||
assert_contain 'Admin dashboard'
|
||||
end
|
||||
|
||||
test 'signed in user should not see unauthenticated page (unauthenticated denied)' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
|
|
|
@ -30,10 +30,18 @@ Rails.application.routes.draw do
|
|||
match "/private", :to => "home#private", :as => :private
|
||||
end
|
||||
|
||||
authenticate(:admin, lambda { |admin| admin.active? }) do
|
||||
match "/private/active", :to => "home#private", :as => :private_active
|
||||
end
|
||||
|
||||
authenticated :admin do
|
||||
match "/dashboard", :to => "home#admin_dashboard"
|
||||
end
|
||||
|
||||
authenticated :admin, lambda { |admin| admin.active? } do
|
||||
match "/dashboard/active", :to => "home#admin_dashboard"
|
||||
end
|
||||
|
||||
authenticated do
|
||||
match "/dashboard", :to => "home#user_dashboard"
|
||||
end
|
||||
|
|
|
@ -60,6 +60,9 @@ class CreateTables < ActiveRecord::Migration
|
|||
## Lockable
|
||||
t.datetime :locked_at
|
||||
|
||||
## Attribute for testing route blocks
|
||||
t.boolean :active, :default => false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,8 @@ class ActionDispatch::IntegrationTest
|
|||
@admin ||= begin
|
||||
admin = Admin.create!(
|
||||
:email => options[:email] || 'admin@test.com',
|
||||
:password => '123456', :password_confirmation => '123456'
|
||||
:password => '123456', :password_confirmation => '123456',
|
||||
:active => options[:active]
|
||||
)
|
||||
admin.confirm! unless options[:confirm] == false
|
||||
admin
|
||||
|
|
Loading…
Reference in a new issue