warden.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # encoding: utf-8
  2. require 'forwardable'
  3. require 'warden/mixins/common'
  4. require 'warden/proxy'
  5. require 'warden/manager'
  6. require 'warden/errors'
  7. require 'warden/session_serializer'
  8. require 'warden/strategies'
  9. require 'warden/strategies/base'
  10. module Warden
  11. class NotAuthenticated < StandardError; end
  12. module Test
  13. autoload :WardenHelpers, 'warden/test/warden_helpers'
  14. autoload :Helpers, 'warden/test/helpers'
  15. end
  16. # Provides helper methods to warden for testing.
  17. #
  18. # To setup warden in test mode call the +test_mode!+ method on warden
  19. #
  20. # @example
  21. # Warden.test_mode!
  22. #
  23. # This will provide a number of methods.
  24. # Warden.on_next_request(&blk) - captures a block which is yielded the warden proxy on the next request
  25. # Warden.test_reset! - removes any captured blocks that would have been executed on the next request
  26. #
  27. # Warden.test_reset! should be called in after blocks for rspec, or teardown methods for Test::Unit
  28. def self.test_mode!
  29. unless Warden::Test::WardenHelpers === Warden
  30. Warden.extend Warden::Test::WardenHelpers
  31. Warden::Manager.on_request do |proxy|
  32. unless proxy.asset_request?
  33. while blk = Warden._on_next_request.shift
  34. blk.call(proxy)
  35. end
  36. end
  37. end
  38. end
  39. true
  40. end
  41. end