2010-03-26 06:27:19 -04:00
|
|
|
require 'test_helper'
|
2009-11-16 11:58:14 -05:00
|
|
|
|
|
|
|
class TestHelpersTest < ActionController::TestCase
|
|
|
|
tests UsersController
|
|
|
|
include Devise::TestHelpers
|
|
|
|
|
|
|
|
test "redirects if attempting to access a page unauthenticated" do
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
2010-04-03 05:43:31 -04:00
|
|
|
assert_redirected_to new_user_session_path
|
2009-11-16 11:58:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "redirects if attempting to access a page with a unconfirmed account" do
|
|
|
|
swap Devise, :confirm_within => 0 do
|
|
|
|
sign_in create_user
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
2010-04-03 05:43:31 -04:00
|
|
|
assert_redirected_to new_user_session_path
|
2009-11-16 11:58:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not redirect with valid user" do
|
|
|
|
user = create_user
|
|
|
|
user.confirm!
|
|
|
|
|
|
|
|
sign_in user
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
2009-11-16 11:58:14 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "redirects if valid user signed out" do
|
|
|
|
user = create_user
|
|
|
|
user.confirm!
|
|
|
|
|
|
|
|
sign_in user
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
2009-11-16 11:58:14 -05:00
|
|
|
|
|
|
|
sign_out user
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
2010-04-03 05:43:31 -04:00
|
|
|
assert_redirected_to new_user_session_path
|
2009-11-16 11:58:14 -05:00
|
|
|
end
|
|
|
|
|
2009-12-14 16:48:15 -05:00
|
|
|
test "allows to sign in with different users" do
|
2009-12-21 15:10:23 -05:00
|
|
|
first_user = create_user
|
2009-12-14 16:48:15 -05:00
|
|
|
first_user.confirm!
|
|
|
|
|
|
|
|
sign_in first_user
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
|
|
|
assert_match /User ##{first_user.id}/, @response.body
|
2009-12-14 16:48:15 -05:00
|
|
|
sign_out first_user
|
|
|
|
|
2009-12-21 15:10:23 -05:00
|
|
|
second_user = create_user
|
2009-12-14 16:48:15 -05:00
|
|
|
second_user.confirm!
|
|
|
|
|
|
|
|
sign_in second_user
|
2010-02-16 11:00:36 -05:00
|
|
|
get :index
|
|
|
|
assert_match /User ##{second_user.id}/, @response.body
|
2009-12-14 16:48:15 -05:00
|
|
|
end
|
2009-11-16 11:58:14 -05:00
|
|
|
end
|