mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 14:58:05 -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:
@@ -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