diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index c8a20e80..023fc67b 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -22,7 +22,7 @@ module Devise # # is the modules included in the class # 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 # 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.merge!(:registration => "") @path_names.merge!(options[:path_names] || {}) + + @sign_out_via = options[:sign_out_via] || :get end # Return modules for the mapping. diff --git a/test/mapping_test.rb b/test/mapping_test.rb index a02220e3..f8040e9f 100644 --- a/test/mapping_test.rb +++ b/test/mapping_test.rb @@ -21,6 +21,16 @@ class MappingTest < ActiveSupport::TestCase assert_equal "admin_area", Devise.mappings[:admin].path 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 assert_equal "accounts", Devise.mappings[:manager].path end diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index db38ad21..3231e544 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -43,6 +43,12 @@ Rails.application.routes.draw do } 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" root :to => "home#index" end \ No newline at end of file