1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Allow to give :skip in devise_for to skip routes for an specific controller.

This commit is contained in:
José Valim 2010-03-12 09:54:57 +01:00
parent 59b26d8427
commit 3f0bae1968
7 changed files with 17 additions and 8 deletions

View file

@ -83,6 +83,10 @@ module ActionDispatch::Routing
#
# devise_for :users, :controllers => { :sessions => "users/sessions" }
#
# * :skip => tell which modules you want to skip routes from being created:
#
# devise_for :users, :skip => :authenticatable
#
def devise_for(*resources)
options = resources.extract_options!
resources.map!(&:to_sym)
@ -99,7 +103,8 @@ module ActionDispatch::Routing
Devise.default_scope ||= mapping.name
Devise.mappings[mapping.name] = mapping
mapping.modules.each do |mod|
routes_modules = mapping.modules - Array(options.delete(:skip))
routes_modules.each do |mod|
send(mod, mapping, mapping.controllers) if self.respond_to?(mod, true)
end
end

View file

@ -26,7 +26,7 @@ class MappingTest < ActiveSupport::TestCase
allowed = Devise.mappings[:admin].allowed_controllers
assert allowed.include?("sessions")
assert_not allowed.include?("devise/confirmations")
assert_not allowed.include?("devise/passwords")
assert_not allowed.include?("devise/unlocks")
end
test 'find mapping by path' do
@ -110,8 +110,9 @@ class MappingTest < ActiveSupport::TestCase
mapping = Devise.mappings[:admin]
assert mapping.authenticatable?
assert mapping.recoverable?
assert_not mapping.confirmable?
assert_not mapping.recoverable?
assert_not mapping.lockable?
assert_not mapping.rememberable?
end
end

View file

@ -23,7 +23,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
end
test 'add modules cherry pick' do
assert_include_modules Admin, :authenticatable, :registerable, :timeoutable
assert_include_modules Admin, :authenticatable, :registerable, :timeoutable, :recoverable
end
test 'set a default value for stretches' do

View file

@ -1,5 +1,5 @@
class Admin < ActiveRecord::Base
devise :authenticatable, :registerable, :timeoutable
devise :authenticatable, :registerable, :timeoutable, :recoverable
def self.find_for_authentication(conditions)
last(:conditions => conditions)

View file

@ -2,7 +2,7 @@ class Admin
include MongoMapper::Document
include MongoMapper::Plugins::Callbacks
devise :authenticatable, :timeoutable, :registerable
devise :authenticatable, :timeoutable, :registerable, :recoverable
def self.find_for_authentication(conditions)
last(:conditions => conditions, :order => "email")

View file

@ -6,7 +6,7 @@ Rails::Application.routes.draw do
resources :admins, :only => [:index]
devise_for :users
devise_for :admin, :as => "admin_area", :controllers => { :sessions => "sessions" }
devise_for :admin, :as => "admin_area", :controllers => { :sessions => "sessions" }, :skip => :recoverable
devise_for :accounts, :scope => "manager", :path_prefix => ":locale",
:class_name => "User", :path_names => {
:sign_in => "login", :sign_out => "logout",
@ -17,5 +17,8 @@ Rails::Application.routes.draw do
match "/admin_area/home", :to => "admins#index", :as => :admin_root
match "/sign_in", :to => "devise/sessions#new"
# Dummy route for new admin pasword
match "/anywhere", :to => "foo#bar", :as => :new_admin_password
root :to => "home#index"
end

View file

@ -84,7 +84,7 @@ class MapRoutingTest < ActionController::TestCase
test 'does not map admin confirmation' do
assert_raise ActionController::RoutingError do
assert_recognizes({:controller => 'devise/confirmations', :action => 'new'}, 'admin_area/confirmation/new')
assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'admin_area/password/new')
end
end