1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Allow to sign in with two different users in the same functional test with Devise::TestHelpers.

This commit is contained in:
José Valim 2009-12-14 22:48:15 +01:00
parent b8c216e0db
commit b04241ddff
4 changed files with 33 additions and 7 deletions

View file

@ -1,3 +1,7 @@
* bug fix
* Fixed render_with_scope to work with all controllers
* Allow sign in with two different users in Devise::TestHelpers
== 0.7.1
* enhancements

View file

@ -78,6 +78,7 @@ module Devise
#
def sign_out(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
@controller.instance_variable_set(:"@current_#{scope}", nil)
warden.logout(scope)
end

View file

@ -9,4 +9,8 @@ class UsersController < ApplicationController
user_session['last_request_at'] = 31.minutes.ago.utc
render :text => 'User will be expired on next request'
end
def show
render :text => current_user.id.to_s
end
end

View file

@ -5,14 +5,14 @@ class TestHelpersTest < ActionController::TestCase
include Devise::TestHelpers
test "redirects if attempting to access a page unauthenticated" do
get :index
get :show
assert_redirected_to "/users/sign_in?unauthenticated=true"
end
test "redirects if attempting to access a page with a unconfirmed account" do
swap Devise, :confirm_within => 0 do
sign_in create_user
get :index
get :show
assert_redirected_to "/users/sign_in?unconfirmed=true"
end
end
@ -22,7 +22,7 @@ class TestHelpersTest < ActionController::TestCase
user.confirm!
sign_in user
get :index
get :show
assert_response :success
end
@ -31,14 +31,31 @@ class TestHelpersTest < ActionController::TestCase
user.confirm!
sign_in user
get :index
get :show
sign_out user
get :index
get :show
assert_redirected_to "/users/sign_in?unauthenticated=true"
end
def create_user
User.create!(:email => "jose.valim@plataformatec.com", :password => "123456")
test "allows to sign in with different users" do
first_user = create_user(1)
first_user.confirm!
sign_in first_user
get :show
assert_equal first_user.id.to_s, @response.body
sign_out first_user
second_user = create_user(2)
second_user.confirm!
sign_in second_user
get :show
assert_equal second_user.id.to_s, @response.body
end
def create_user(i=nil)
User.create!(:email => "jose.valim#{i}@plataformatec.com", :password => "123456")
end
end