Merge pull request #2978 from rossta/support_for_multiple_warden_config_blocks

Support multiple warden configuration blocks
This commit is contained in:
Rafael Mendonça França
2014-04-15 18:46:28 -03:00
2 changed files with 22 additions and 5 deletions

View File

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

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