mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-10 08:08:00 -05:00
Merge pull request #2978 from rossta/support_for_multiple_warden_config_blocks
Support multiple warden configuration blocks
This commit is contained in:
@@ -272,7 +272,7 @@ module Devise
|
||||
# Private methods to interface with Warden.
|
||||
mattr_accessor :warden_config
|
||||
@@warden_config = nil
|
||||
@@warden_config_block = nil
|
||||
@@warden_config_blocks = []
|
||||
|
||||
# When true, enter in paranoid mode to avoid user enumeration.
|
||||
mattr_accessor :paranoid
|
||||
@@ -413,7 +413,7 @@ module Devise
|
||||
# end
|
||||
# end
|
||||
def self.warden(&block)
|
||||
@@warden_config_block = block
|
||||
@@warden_config_blocks << block
|
||||
end
|
||||
|
||||
# Specify an omniauth provider.
|
||||
@@ -467,7 +467,7 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
@@warden_config_block.try :call, Devise.warden_config
|
||||
@@warden_config_blocks.map { |block| block.call Devise.warden_config }
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'test_helper'
|
||||
module Devise
|
||||
def self.yield_and_restore
|
||||
@@warden_configured = nil
|
||||
c, b = @@warden_config, @@warden_config_block
|
||||
c, b = @@warden_config, @@warden_config_blocks
|
||||
yield
|
||||
ensure
|
||||
@@warden_config, @@warden_config_block = c, b
|
||||
@@warden_config, @@warden_config_blocks = c, b
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,6 +53,23 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
test 'warden manager user configuration through multiple blocks' do
|
||||
Devise.yield_and_restore do
|
||||
@first_executed = false
|
||||
@second_executed = false
|
||||
Devise.warden do |config|
|
||||
@first_executed = true
|
||||
end
|
||||
Devise.warden do |config|
|
||||
@second_executed = true
|
||||
end
|
||||
|
||||
Devise.configure_warden!
|
||||
assert @first_executed
|
||||
assert @second_executed
|
||||
end
|
||||
end
|
||||
|
||||
test 'add new module using the helper method' do
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
||||
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
||||
|
||||
Reference in New Issue
Block a user