mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
provide :sign_out_via option for Devise::Mapping
This commit is contained in:
parent
701bbf2d3c
commit
f04e633542
3 changed files with 19 additions and 1 deletions
|
@ -22,7 +22,7 @@ module Devise
|
||||||
# # is the modules included in the class
|
# # is the modules included in the class
|
||||||
#
|
#
|
||||||
class Mapping #:nodoc:
|
class Mapping #:nodoc:
|
||||||
attr_reader :singular, :plural, :path, :controllers, :path_names, :class_name
|
attr_reader :singular, :plural, :path, :controllers, :path_names, :class_name, :sign_out_via
|
||||||
alias :name :singular
|
alias :name :singular
|
||||||
|
|
||||||
# Receives an object and find a scope for it. If a scope cannot be found,
|
# Receives an object and find a scope for it. If a scope cannot be found,
|
||||||
|
@ -57,6 +57,8 @@ module Devise
|
||||||
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
||||||
@path_names.merge!(:registration => "")
|
@path_names.merge!(:registration => "")
|
||||||
@path_names.merge!(options[:path_names] || {})
|
@path_names.merge!(options[:path_names] || {})
|
||||||
|
|
||||||
|
@sign_out_via = options[:sign_out_via] || :get
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return modules for the mapping.
|
# Return modules for the mapping.
|
||||||
|
|
|
@ -21,6 +21,16 @@ class MappingTest < ActiveSupport::TestCase
|
||||||
assert_equal "admin_area", Devise.mappings[:admin].path
|
assert_equal "admin_area", Devise.mappings[:admin].path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'sign_out_via defaults to :get' do
|
||||||
|
assert_equal :get, Devise.mappings[:user].sign_out_via
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'allows custom sign_out_via to be given' do
|
||||||
|
assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
|
||||||
|
assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
|
||||||
|
assert_equal [:delete, :post], Devise.mappings[:sign_out_via_delete_or_post].sign_out_via
|
||||||
|
end
|
||||||
|
|
||||||
test 'allows custom singular to be given' do
|
test 'allows custom singular to be given' do
|
||||||
assert_equal "accounts", Devise.mappings[:manager].path
|
assert_equal "accounts", Devise.mappings[:manager].path
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,6 +43,12 @@ Rails.application.routes.draw do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
namespace :sign_out_via do
|
||||||
|
devise_for :deletes, :sign_out_via => :delete, :class_name => "User", :controllers => { :sessions => "sessions" }
|
||||||
|
devise_for :posts, :sign_out_via => :post, :class_name => "User", :controllers => { :sessions => "sessions" }
|
||||||
|
devise_for :delete_or_posts, :sign_out_via => [:delete, :post], :class_name => "User", :controllers => { :sessions => "sessions" }
|
||||||
|
end
|
||||||
|
|
||||||
match "/set", :to => "home#set"
|
match "/set", :to => "home#set"
|
||||||
root :to => "home#index"
|
root :to => "home#index"
|
||||||
end
|
end
|
Loading…
Reference in a new issue