lib/devise/test_helpers.rb in devise-1.1.9 vs lib/devise/test_helpers.rb in devise-1.2.rc
- old
+ new
@@ -1,6 +1,13 @@
module Devise
+ # Devise::TestHelpers provides a facility to test controllers in isolation
+ # when using ActionController::TestCase allowing you to quickly sign_in or
+ # sign_out an user. Do not use Devise::TestHelpers in integration tests.
+ #
+ # Notice you should not test Warden specific behavior (like Warden callbacks)
+ # using Devise::TestHelpers since it is a stub of the actual behavior. Such
+ # callbacks should be tested in your integration suite instead.
module TestHelpers
def self.included(base)
base.class_eval do
setup :setup_controller_for_warden, :warden if respond_to?(:setup)
end
@@ -59,10 +66,11 @@
def warden #:nodoc:
@warden ||= (@request.env['warden'] = TestWarden.new(@controller))
end
# sign_in a given resource by storing its keys in the session.
+ # This method bypass any warden authentication callback.
#
# Examples:
#
# sign_in :user, @user # sign_in(scope, resource)
# sign_in @user # sign_in(resource)
@@ -72,19 +80,21 @@
resource ||= resource_or_scope
warden.session_serializer.store(resource, scope)
end
# Sign out a given resource or scope by calling logout on Warden.
+ # This method bypass any warden logout callback.
#
# Examples:
#
# sign_out :user # sign_out(scope)
# sign_out @user # sign_out(resource)
#
def sign_out(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
@controller.instance_variable_set(:"@current_#{scope}", nil)
- warden.logout(scope)
+ user = warden.instance_variable_get(:@users).delete(scope)
+ warden.session_serializer.delete(scope, user)
end
end
end