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:
Ross Kaffenberger
2014-04-15 17:20:21 -04:00
parent 38e868dc79
commit 5f32cd25fd
2 changed files with 22 additions and 5 deletions

View File

@@ -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