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