Revision 487
Added by Jean-Philippe Lang about 18 years ago
trunk/test/functional/my_controller_test.rb | ||
---|---|---|
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 |
|
|
1 | 18 |
require File.dirname(__FILE__) + '/../test_helper' |
2 | 19 |
require 'my_controller' |
3 | 20 |
|
... | ... | |
8 | 25 |
def setup |
9 | 26 |
@controller = MyController.new |
10 | 27 |
@request = ActionController::TestRequest.new |
28 |
@request.session[:user_id] = 2 |
|
11 | 29 |
@response = ActionController::TestResponse.new |
12 | 30 |
end |
13 | 31 |
|
14 |
# Replace this with your real tests. |
|
15 |
def test_truth |
|
16 |
assert true |
|
32 |
def test_index |
|
33 |
get :index |
|
34 |
assert_response :success |
|
35 |
assert_template 'page' |
|
17 | 36 |
end |
37 |
|
|
38 |
def test_page |
|
39 |
get :page |
|
40 |
assert_response :success |
|
41 |
assert_template 'page' |
|
42 |
end |
|
43 |
|
|
44 |
def test_get_account |
|
45 |
get :account |
|
46 |
assert_response :success |
|
47 |
assert_template 'account' |
|
48 |
assert_equal User.find(2), assigns(:user) |
|
49 |
end |
|
50 |
|
|
51 |
def test_update_account |
|
52 |
post :account, :user => {:firstname => "Joe", :login => "root", :admin => 1} |
|
53 |
assert_response :success |
|
54 |
assert_template 'account' |
|
55 |
user = User.find(2) |
|
56 |
assert_equal user, assigns(:user) |
|
57 |
assert_equal "Joe", user.firstname |
|
58 |
assert_equal "jsmith", user.login |
|
59 |
assert !user.admin? |
|
60 |
end |
|
61 |
|
|
62 |
def test_change_password |
|
63 |
get :account |
|
64 |
assert_response :success |
|
65 |
assert_template 'account' |
|
66 |
|
|
67 |
# non matching password confirmation |
|
68 |
post :change_password, :password => 'jsmith', |
|
69 |
:new_password => 'hello', |
|
70 |
:new_password_confirmation => 'hello2' |
|
71 |
assert_response :success |
|
72 |
assert_template 'account' |
|
73 |
assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } |
|
74 |
|
|
75 |
# wrong password |
|
76 |
post :change_password, :password => 'wrongpassword', |
|
77 |
:new_password => 'hello', |
|
78 |
:new_password_confirmation => 'hello' |
|
79 |
assert_redirected_to 'my/account' |
|
80 |
assert_equal 'Wrong password', flash[:notice] |
|
81 |
|
|
82 |
# good password |
|
83 |
post :change_password, :password => 'jsmith', |
|
84 |
:new_password => 'hello', |
|
85 |
:new_password_confirmation => 'hello' |
|
86 |
assert_redirected_to 'my/account' |
|
87 |
assert User.try_to_login('jsmith', 'hello') |
|
88 |
end |
|
18 | 89 |
end |
trunk/test/integration/account_test.rb | ||
---|---|---|
1 | 1 |
# redMine - project management software |
2 |
# Copyright (C) 2006 Jean-Philippe Lang |
|
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 |
... | ... | |
31 | 31 |
assert_template "my/account" |
32 | 32 |
end |
33 | 33 |
|
34 |
def test_change_password |
|
35 |
log_user('jsmith', 'jsmith') |
|
36 |
get "my/account" |
|
37 |
assert_response :success |
|
38 |
assert_template "my/account" |
|
39 |
|
|
40 |
post "my/change_password", :password => 'jsmith', :new_password => "hello", :new_password_confirmation => "hello2" |
|
41 |
assert_response :success |
|
42 |
assert_template "my/account" |
|
43 |
assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } |
|
44 |
|
|
45 |
post "my/change_password", :password => 'jsmithZZ', :new_password => "hello", :new_password_confirmation => "hello" |
|
46 |
assert_redirected_to "my/account" |
|
47 |
assert_equal 'Wrong password', flash[:notice] |
|
48 |
|
|
49 |
post "my/change_password", :password => 'jsmith', :new_password => "hello", :new_password_confirmation => "hello" |
|
50 |
assert_redirected_to "my/account" |
|
51 |
log_user('jsmith', 'hello') |
|
52 |
end |
|
53 |
|
|
54 |
def test_my_account |
|
55 |
log_user('jsmith', 'jsmith') |
|
56 |
get "my/account" |
|
57 |
assert_response :success |
|
58 |
assert_template "my/account" |
|
59 |
|
|
60 |
post "my/account", :user => {:firstname => "Joe", :login => "root", :admin => 1} |
|
61 |
assert_response :success |
|
62 |
assert_template "my/account" |
|
63 |
user = User.find(2) |
|
64 |
assert_equal "Joe", user.firstname |
|
65 |
assert_equal "jsmith", user.login |
|
66 |
assert_equal false, user.admin? |
|
67 |
end |
|
68 |
|
|
69 |
def test_my_page |
|
70 |
log_user('jsmith', 'jsmith') |
|
71 |
get "my/page" |
|
72 |
assert_response :success |
|
73 |
assert_template "my/page" |
|
74 |
end |
|
75 |
|
|
76 | 34 |
def test_lost_password |
77 | 35 |
Token.delete_all |
78 | 36 |
|
Also available in: Unified diff
Moved functional tests for MyController