##// END OF EJS Templates
Fixed my_controller_test.rb (errors are now in flash[:error])...
Jean-Philippe Lang -
r603:5bd26ede4200
parent child
Show More
@@ -1,89 +1,89
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'my_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class MyController; def rescue_action(e) raise e end; end
23 23
24 24 class MyControllerTest < Test::Unit::TestCase
25 25 def setup
26 26 @controller = MyController.new
27 27 @request = ActionController::TestRequest.new
28 28 @request.session[:user_id] = 2
29 29 @response = ActionController::TestResponse.new
30 30 end
31 31
32 32 def test_index
33 33 get :index
34 34 assert_response :success
35 35 assert_template 'page'
36 36 end
37 37
38 38 def test_page
39 39 get :page
40 40 assert_response :success
41 41 assert_template 'page'
42 42 end
43 43
44 44 def test_get_account
45 45 get :account
46 46 assert_response :success
47 47 assert_template 'account'
48 48 assert_equal User.find(2), assigns(:user)
49 49 end
50 50
51 51 def test_update_account
52 52 post :account, :user => {:firstname => "Joe", :login => "root", :admin => 1}
53 53 assert_response :success
54 54 assert_template 'account'
55 55 user = User.find(2)
56 56 assert_equal user, assigns(:user)
57 57 assert_equal "Joe", user.firstname
58 58 assert_equal "jsmith", user.login
59 59 assert !user.admin?
60 60 end
61 61
62 62 def test_change_password
63 63 get :account
64 64 assert_response :success
65 65 assert_template 'account'
66 66
67 67 # non matching password confirmation
68 68 post :change_password, :password => 'jsmith',
69 69 :new_password => 'hello',
70 70 :new_password_confirmation => 'hello2'
71 71 assert_response :success
72 72 assert_template 'account'
73 73 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
74 74
75 75 # wrong password
76 76 post :change_password, :password => 'wrongpassword',
77 77 :new_password => 'hello',
78 78 :new_password_confirmation => 'hello'
79 79 assert_redirected_to 'my/account'
80 assert_equal 'Wrong password', flash[:notice]
80 assert_equal 'Wrong password', flash[:error]
81 81
82 82 # good password
83 83 post :change_password, :password => 'jsmith',
84 84 :new_password => 'hello',
85 85 :new_password_confirmation => 'hello'
86 86 assert_redirected_to 'my/account'
87 87 assert User.try_to_login('jsmith', 'hello')
88 88 end
89 89 end
General Comments 0
You need to be logged in to leave comments. Login now