Devise now allows you to have custom controlleers. Check the README for more information.

This commit is contained in:
José Valim
2010-02-17 13:15:19 +01:00
parent 691f9324f5
commit f6cc219210
8 changed files with 114 additions and 66 deletions

View File

@@ -134,9 +134,7 @@ class AuthenticationTest < ActionController::IntegrationTest
end
test 'error message is configurable by resource name' do
store_translations :en, :devise => {
:sessions => { :admin => { :invalid => "Invalid credentials" } }
} do
store_translations :en, :devise => { :sessions => { :admin => { :invalid => "Invalid credentials" } } } do
sign_in_as_admin do
fill_in 'password', :with => 'abcdef'
end
@@ -210,6 +208,7 @@ class AuthenticationTest < ActionController::IntegrationTest
assert_equal "Cart", @controller.user_session[:cart]
end
# Scoped views
test 'renders the scoped view if turned on and view is available' do
swap Devise, :scoped_views => true do
assert_raise Webrat::NotFoundError do
@@ -249,6 +248,24 @@ class AuthenticationTest < ActionController::IntegrationTest
end
end
# Default scope
test 'uses the mapping from the default scope if specified' do
swap Devise, :use_default_scope => true do
get '/sign_in'
assert_response :ok
assert_contain 'Sign in'
end
end
# Custom controller
test 'uses the custom controller with the custom controller view' do
get '/admin_area/sign_in'
assert_contain 'Sign in'
assert_contain 'Welcome to "sessions" controller!'
assert_contain 'Welcome to "sessions/new" view!'
end
# Access
test 'render 404 on roles without permission' do
get '/admin_area/password/new', {}, "action_dispatch.show_exceptions" => true
assert_response :not_found
@@ -260,12 +277,4 @@ class AuthenticationTest < ActionController::IntegrationTest
assert_response :not_found
assert_not_contain 'Sign in'
end
test 'uses the mapping from the default scope if specified' do
swap Devise, :use_default_scope => true do
get '/sign_in'
assert_response :ok
assert_contain 'Sign in'
end
end
end

View File

@@ -0,0 +1,6 @@
class SessionsController < Devise::SessionsController
def new
flash[:notice] = "Welcome to #{controller_path.inspect} controller!"
super
end
end

View File

@@ -0,0 +1,2 @@
Welcome to "sessions/new" view!
<%= render :file => "devise/sessions/new" %>

View File

@@ -3,18 +3,19 @@ Rails::Application.routes.draw do
get :expire, :on => :member
end
resources :admins, :only => [:index]
devise_for :users
devise_for :admin, :as => 'admin_area'
devise_for :accounts, :scope => 'manager', :path_prefix => ':locale',
devise_for :admin, :as => "admin_area", :controllers => { :sessions => "sessions" }
devise_for :accounts, :scope => "manager", :path_prefix => ":locale",
:class_name => "User", :path_names => {
:sign_in => 'login', :sign_out => 'logout',
:password => 'secret', :confirmation => 'verification',
:unlock => 'unblock', :sign_up => 'register'
:sign_in => "login", :sign_out => "logout",
:password => "secret", :confirmation => "verification",
:unlock => "unblock", :sign_up => "register"
}
resources :admins, :only => [:index]
root :to => "home#index"
match "/admin_area/home", :to => "admins#index", :as => :admin_root
match "/sign_in", :to => "devise/sessions#new"
match '/admin_area/home', :to => "admins#index", :as => :admin_root
match '/sign_in', :to => "devise/sessions#new"
end
root :to => "home#index"
end

View File

@@ -74,8 +74,12 @@ class MapRoutingTest < ActionController::TestCase
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
end
test 'map admin session with :as option' do
assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
test 'map admin with :as option' do
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'admin_area/sign_up', :method => :get})
end
test 'map admin with :controllers option' do
assert_recognizes({:controller => 'sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
end
test 'does not map admin confirmation' do