You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

account_controller_test.rb 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # redMine - project management software
  2. # Copyright (C) 2006-2007 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.dirname(__FILE__) + '/../test_helper'
  18. require 'account_controller'
  19. # Re-raise errors caught by the controller.
  20. class AccountController; def rescue_action(e) raise e end; end
  21. class AccountControllerTest < Test::Unit::TestCase
  22. fixtures :users
  23. def setup
  24. @controller = AccountController.new
  25. @request = ActionController::TestRequest.new
  26. @response = ActionController::TestResponse.new
  27. User.current = nil
  28. end
  29. def test_show
  30. get :show, :id => 2
  31. assert_response :success
  32. assert_template 'show'
  33. assert_not_nil assigns(:user)
  34. end
  35. def test_show_inactive
  36. get :show, :id => 5
  37. assert_response 404
  38. assert_nil assigns(:user)
  39. end
  40. def test_login_with_wrong_password
  41. post :login, :login => 'admin', :password => 'bad'
  42. assert_response :success
  43. assert_template 'login'
  44. assert_tag 'div',
  45. :attributes => { :class => "flash error" },
  46. :content => /Invalid user or password/
  47. end
  48. def test_autologin
  49. Setting.autologin = "7"
  50. Token.delete_all
  51. post :login, :login => 'admin', :password => 'admin', :autologin => 1
  52. assert_redirected_to 'my/page'
  53. token = Token.find :first
  54. assert_not_nil token
  55. assert_equal User.find_by_login('admin'), token.user
  56. assert_equal 'autologin', token.action
  57. end
  58. def test_logout
  59. @request.session[:user_id] = 2
  60. get :logout
  61. assert_redirected_to ''
  62. assert_nil @request.session[:user_id]
  63. end
  64. end