diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 7b834c81..8b5445e8 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,7 +1,11 @@ +* deprecations + * Deprecate :singular in devise_for and use :scope instead + * enhancements * [#37] Create after_sign_in_path_for and after_sign_out_path_for hooks to be overwriten in ApplicationController * Create sign_in_and_redirect and sign_out_and_redirect helpers + * Warden::Manager.default_scope is automatically configured to the first given scope == 0.5.3 diff --git a/lib/devise.rb b/lib/devise.rb index 108eace8..f1621c8d 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -138,6 +138,9 @@ rescue require 'warden' end +# Set the default_scope to nil, so it's overwritten when the first route is declared. +Warden::Manager.default_scope = nil + require 'devise/strategies/base' require 'devise/serializers/base' diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 4092ff1c..35a9b8d9 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -85,6 +85,7 @@ module ActionController::Routing resources.map!(&:to_sym) resources.each do |resource| mapping = Devise::Mapping.new(resource, options.dup) + Warden::Manager.default_scope ||= mapping.name Devise.mappings[mapping.name] = mapping route_options = mapping.route_options.merge(:path_prefix => mapping.raw_path, :name_prefix => "#{mapping.name}_") diff --git a/test/devise_test.rb b/test/devise_test.rb index e7394d7d..dfefdcfb 100644 --- a/test/devise_test.rb +++ b/test/devise_test.rb @@ -66,6 +66,10 @@ class DeviseTest < ActiveSupport::TestCase assert manager.silence_missing_strategies end + test 'warden default scope is set' do + assert_equal :user, Warden::Manager.default_scope + end + test 'warden manager user configuration through a block' do begin @executed = false diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index 7ff39fa6..faf1feeb 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -4,7 +4,7 @@ ActionController::Routing::Routes.draw do |map| map.devise_for :account, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' } - map.devise_for :organizers, :singular => 'manager', + map.devise_for :organizers, :scope => 'manager', :path_prefix => '/:locale', :requirements => { :extra => 'value' }