mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
support multiple warden configuration blocks
Changes the behavior of `Devise.warden` such that calling it multiple times with different blocks will result in a call to each block on `Devise.configure_warden!` rather than "last block wins". This is especially used for plugins that wish to extend warden functionality without clobbering base app configuration or vice versa.
This commit is contained in:
parent
38e868dc79
commit
5f32cd25fd
2 changed files with 22 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue