Compare commits

...

7 Commits

Author SHA1 Message Date
José Valim
59cd9e72b9 Release 1.5.3. 2011-12-19 12:56:56 +01:00
José Valim
fbb5c2af5c Update CHANGELOG. 2011-12-12 11:36:19 +01:00
José Valim
e137e9d5d1 PathChecker should not attempt to validate invalid routes, closes #1505 2011-12-12 11:35:57 +01:00
José Valim
5bc96f294f Update CHANGELOG. 2011-12-12 09:26:14 +01:00
José Valim
cd8af3c00c Fix a bug where passing :format => false to devise_for was permanent, closes #1504 2011-12-12 09:25:43 +01:00
José Valim
f5c643946b Update CHANGELOG 2011-12-07 13:19:53 +01:00
Dmitriy Kiriyenko
86d4ec223d Fix taking associated failure app from the scope in the given env.
There is a delegator to get failure app, introduced in 4629bee and tuned
in 24b26026. The latter commit introduced a bit of logic, however, no
tests are included into commit. Needless to say this resulted in a
broken code.

The point is that `env["warden.options"][:scope]` returns a string.
However, `Devise.mappings` is a hash with symbol keys.

Adding tests and converting scope to symbol here.

Signed-off-by: José Valim <jose.valim@gmail.com>
2011-12-07 13:14:22 +01:00
9 changed files with 66 additions and 14 deletions

View File

@@ -1,3 +1,10 @@
== 1.5.3
* bug fix
* Ensure delegator converts scope to symbol (by github.com/dmitriy-kiriyenko)
* Ensure passing :format => false to devise_for is not permanent
* Ensure path checker does not check invalid routes
== 1.5.2
* enhancements

View File

@@ -8,9 +8,9 @@ module Devise
def failure_app(env)
app = env["warden.options"] &&
(scope = env["warden.options"][:scope]) &&
Devise.mappings[scope].failure_app
Devise.mappings[scope.to_sym].failure_app
app || Devise::FailureApp
end
end
end
end

View File

@@ -23,8 +23,7 @@ module Devise
#
class Mapping #:nodoc:
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
:class_name, :sign_out_via, :format, :used_routes, :used_helpers,
:constraints, :defaults, :failure_app
:class_name, :sign_out_via, :format, :used_routes, :used_helpers, :failure_app
alias :name :singular
@@ -64,8 +63,6 @@ module Devise
default_failure_app(options)
default_controllers(options)
default_path_names(options)
default_constraints(options)
default_defaults(options)
default_used_route(options)
default_used_helpers(options)
end

View File

@@ -12,7 +12,8 @@ module Devise
end
def signing_out?
@current_path == send("destroy_#{@scope}_session_path")
route = "destroy_#{@scope}_session_path"
respond_to?(route) && @current_path == send(route)
end
end
end

View File

@@ -185,7 +185,7 @@ module ActionDispatch::Routing
options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {})
options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {})
@scope[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false
options[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false
resources.map!(&:to_sym)
@@ -208,7 +208,7 @@ module ActionDispatch::Routing
devise_scope mapping.name do
yield if block_given?
with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints, mapping.defaults do
with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
end
end
@@ -368,12 +368,15 @@ module ActionDispatch::Routing
@scope[:path] = path
end
def with_devise_exclusive_scope(new_path, new_as, new_constraints, new_defaults) #:nodoc:
old_as, old_path, old_module, old_constraints, old_defaults = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults]
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = new_as, new_path, nil, new_constraints, new_defaults
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
*@scope.values_at(:as, :path, :module, :constraints, :defaults, :options)
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options)
yield
ensure
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = old_as, old_path, old_module, old_constraints, old_defaults
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
old_as, old_path, old_module, old_constraints, old_defaults, old_options
end
def raise_no_devise_method_error!(klass) #:nodoc:

View File

@@ -1,3 +1,3 @@
module Devise
VERSION = "1.5.2".freeze
VERSION = "1.5.3".freeze
end

19
test/delegator_test.rb Normal file
View File

@@ -0,0 +1,19 @@
require 'test_helper'
class DelegatorTest < ActiveSupport::TestCase
def delegator
Devise::Delegator.new
end
test 'failure_app returns default failure app if no warden options in env' do
assert_equal Devise::FailureApp, delegator.failure_app({})
end
test 'failure_app returns default failure app if no scope in warden options' do
assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
end
test 'failure_app returns associated failure app by scope in the given environment' do
assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
end
end

21
test/path_checker_test.rb Normal file
View File

@@ -0,0 +1,21 @@
require 'test_helper'
class PathCheckerTest < ActiveSupport::TestCase
test 'check if sign out path matches' do
path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_out"}, :user)
assert path_checker.signing_out?
path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_in"}, :user)
assert_not path_checker.signing_out?
end
test 'considers script name' do
path_checker = Devise::PathChecker.new({"SCRIPT_NAME" => "/users", "PATH_INFO" => "/sign_out"}, :user)
assert path_checker.signing_out?
end
test 'ignores invalid routes' do
path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_in"}, :omg)
assert_not path_checker.signing_out?
end
end

View File

@@ -225,6 +225,10 @@ class CustomizedRoutingTest < ActionController::TestCase
assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => '/htmlonly_users/unlock.xml', :method => :get})
end
end
test 'map with format false is not permanent' do
assert_equal "/set.xml", @routes.url_helpers.set_path(:xml)
end
end
class ScopedRoutingTest < ActionController::TestCase