Since Devise::FailureApp is now a metal, we can get rid of this default_url_options stuff.

This commit is contained in:
José Valim 2010-02-19 10:13:53 +01:00
parent 4a0b9c663a
commit 1c6f18cb8b
8 changed files with 26 additions and 86 deletions

View File

@ -5,11 +5,13 @@
* All controllers and views are namespaced, for example: Devise::SessionsController and "devise/sessions".
* You can specify the controller in routes and have specific controllers for each role.
* Devise.orm is deprecated. This reduces the required API to hook your ORM with devise.
* Use metal for failure app.
* deprecations
* Rails 3 compatible only.
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
* Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead.
* Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options.
== 1.0.2

View File

@ -149,10 +149,16 @@ module Devise
yield self
end
# TODO Remove me on final release
# TODO Remove me on 1.1.0 final
def orm=(value)
ActiveSupport::Deprecation.warn "Devise.orm= and config.orm= are deprecated. " <<
"Just load devise/orm/\#{ORM_NAME} if Devise supports your ORM"
"Just load \"devise/orm/\#{ORM_NAME}\" if Devise supports your ORM"
end
# TODO Remove me on 1.1.0 final
def default_url_options
ActiveSupport::Deprecation.warn "Devise.default_url_options and config.default_url_options are deprecated. " <<
"Just modify ApplicationController.default_url_options and Devise will automatically pick it up"
end
# Sets warden configuration using a block that will be invoked on warden
@ -170,11 +176,6 @@ module Devise
@warden_config = block
end
# Configure default url options to be used within Devise and ActionController.
def default_url_options(&block)
Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
end
# A method used internally to setup warden manager from the Rails initialize
# block.
def configure_warden(config) #:nodoc:

View File

@ -7,12 +7,6 @@ module Devise
included do
helper_method :warden, :signed_in?, :devise_controller?,
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
# Use devise default_url_options. We have to declare it here to overwrite
# default definitions.
def default_url_options(options=nil)
Devise::Mapping.default_url_options
end
end
# The main accessor for the warden proxy instance

View File

@ -56,11 +56,6 @@ module Devise
end
end
# Default url options which can be used as prefix.
def self.default_url_options
{}
end
def initialize(name, options) #:nodoc:
@as = (options.delete(:as) || name).to_sym
@klass = (options.delete(:class_name) || name.to_s.classify).to_s
@ -95,19 +90,10 @@ module Devise
end
# Returns the raw path using path_prefix and as.
def raw_path
def path
path_prefix + as.to_s
end
# Returns the parsed path taking into account the relative url root and raw path.
def parsed_path
returning (ActionController::Base.relative_url_root.to_s + raw_path) do |path|
self.class.default_url_options.each do |key, value|
path.gsub!(key.inspect, value.to_param)
end
end
end
# Create magic predicates for verifying what module is activated by this map.
# Example:
#

View File

@ -69,11 +69,13 @@ module ActionDispatch::Routing
#
# devise_for :users, :path_prefix => "/:locale"
#
# If you are using a dynamic prefix, like :locale above, you need to configure default_url_options through Devise.
# You can do that in config/initializers/devise.rb or setting a Devise.default_url_options:
# If you are using a dynamic prefix, like :locale above, you need to configure default_url_options in your ApplicationController
# class level, so Devise can pick it:
#
# Devise.default_url_options do
# { :locale => I18n.locale }
# class ApplicationController < ActionController::Base
# def self.default_url_options
# { :locale => I18n.locale }
# end
# end
#
# * :controllers => the controller which should be used. All routes by default points to Devise controllers.
@ -103,7 +105,7 @@ module ActionDispatch::Routing
protected
def authenticatable(mapping, controllers)
scope mapping.raw_path do
scope mapping.path do
get mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#new", :as => :"new_#{mapping.name}_session"
post mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#create", :as => :"#{mapping.name}_session"
get mapping.path_names[:sign_out], :to => "#{controllers[:sessions]}#destroy", :as => :"destroy_#{mapping.name}_session"
@ -111,26 +113,26 @@ module ActionDispatch::Routing
end
def recoverable(mapping, controllers)
scope mapping.raw_path, :name_prefix => mapping.name do
scope mapping.path, :name_prefix => mapping.name do
resource :password, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:password], :controller => controllers[:passwords]
end
end
def confirmable(mapping, controllers)
scope mapping.raw_path, :name_prefix => mapping.name do
scope mapping.path, :name_prefix => mapping.name do
resource :confirmation, :only => [:new, :create, :show], :as => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
end
end
def lockable(mapping, controllers)
scope mapping.raw_path, :name_prefix => mapping.name do
scope mapping.path, :name_prefix => mapping.name do
resource :unlock, :only => [:new, :create, :show], :as => mapping.path_names[:unlock], :controller => controllers[:unlocks]
end
end
def registerable(mapping, controllers)
scope :name_prefix => mapping.name do
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.raw_path[1..-1],
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.path[1..-1],
:path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
end
end

View File

@ -63,8 +63,7 @@ Devise.setup do |config|
# ==> General configuration
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper
# (requires mongo_ext installed) and :data_mapper (experimental).
# require 'devise/orm/mongo_mapper'
# config.orm = :mongo_mapper
require 'devise/orm/active_record'
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "sessions/users/new". It's turned off by default because it's slower if you
@ -93,10 +92,4 @@ Devise.setup do |config|
# end
# manager.default_strategies.unshift :twitter_oauth
# end
# Configure default_url_options if you are using dynamic segments in :path_prefix
# for devise_for.
# config.default_url_options do
# { :locale => I18n.locale }
# end
end

View File

@ -178,13 +178,4 @@ class ControllerAuthenticableTest < ActionController::TestCase
test 'is not a devise controller' do
assert_not @controller.devise_controller?
end
test 'default url options are retrieved from devise' do
begin
Devise.default_url_options {{ :locale => I18n.locale }}
assert_equal({ :locale => :en }, @controller.send(:default_url_options))
ensure
Devise.default_url_options {{ }}
end
end
end

View File

@ -4,7 +4,6 @@ class MappingTest < ActiveSupport::TestCase
test 'store options' do
mapping = Devise.mappings[:user]
assert_equal User, mapping.to
assert_equal User.devise_modules, mapping.for
assert_equal :users, mapping.as
@ -96,37 +95,9 @@ class MappingTest < ActiveSupport::TestCase
assert_equal 2, Devise.mappings[:manager].as_position
end
test 'raw path is returned' do
assert_equal '/users', Devise.mappings[:user].raw_path
assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path
end
test 'raw path ignores the relative_url_root' do
swap ActionController::Base, :relative_url_root => "/abc" do
assert_equal '/users', Devise.mappings[:user].raw_path
end
end
test 'parsed path is returned' do
begin
Devise.default_url_options {{ :locale => I18n.locale }}
assert_equal '/users', Devise.mappings[:user].parsed_path
assert_equal '/en/accounts', Devise.mappings[:manager].parsed_path
ensure
Devise.default_url_options {{ }}
end
end
test 'parsed path adds in the relative_url_root' do
swap ActionController::Base, :relative_url_root => '/abc' do
assert_equal '/abc/users', Devise.mappings[:user].parsed_path
end
end
test 'parsed path deals with a nil relative_url_root' do
swap ActionController::Base, :relative_url_root => nil do
assert_equal '/users', Devise.mappings[:user].raw_path
end
test 'path is returned with path prefix and as' do
assert_equal '/users', Devise.mappings[:user].path
assert_equal '/:locale/accounts', Devise.mappings[:manager].path
end
test 'magic predicates' do