@@ -1,216 +1,224 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__) |
|
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 < ActionController::TestCase |
|
25 | fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields | |
|
25 | fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources | |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = MyController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @request.session[:user_id] = 2 |
|
31 | 31 | @response = ActionController::TestResponse.new |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_index |
|
35 | 35 | get :index |
|
36 | 36 | assert_response :success |
|
37 | 37 | assert_template 'page' |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_page |
|
41 | 41 | get :page |
|
42 | 42 | assert_response :success |
|
43 | 43 | assert_template 'page' |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_my_account_should_show_editable_custom_fields |
|
47 | 47 | get :account |
|
48 | 48 | assert_response :success |
|
49 | 49 | assert_template 'account' |
|
50 | 50 | assert_equal User.find(2), assigns(:user) |
|
51 | 51 | |
|
52 | 52 | assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def test_my_account_should_not_show_non_editable_custom_fields |
|
56 | 56 | UserCustomField.find(4).update_attribute :editable, false |
|
57 | 57 | |
|
58 | 58 | get :account |
|
59 | 59 | assert_response :success |
|
60 | 60 | assert_template 'account' |
|
61 | 61 | assert_equal User.find(2), assigns(:user) |
|
62 | 62 | |
|
63 | 63 | assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_update_account |
|
67 | 67 | post :account, |
|
68 | 68 | :user => { |
|
69 | 69 | :firstname => "Joe", |
|
70 | 70 | :login => "root", |
|
71 | 71 | :admin => 1, |
|
72 | 72 | :group_ids => ['10'], |
|
73 | 73 | :custom_field_values => {"4" => "0100562500"} |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | assert_redirected_to '/my/account' |
|
77 | 77 | user = User.find(2) |
|
78 | 78 | assert_equal user, assigns(:user) |
|
79 | 79 | assert_equal "Joe", user.firstname |
|
80 | 80 | assert_equal "jsmith", user.login |
|
81 | 81 | assert_equal "0100562500", user.custom_value_for(4).value |
|
82 | 82 | # ignored |
|
83 | 83 | assert !user.admin? |
|
84 | 84 | assert user.groups.empty? |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | 87 | def test_my_account_should_show_destroy_link |
|
88 | 88 | get :account |
|
89 | 89 | assert_select 'a[href=/my/account/destroy]' |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def test_get_destroy_should_display_the_destroy_confirmation |
|
93 | 93 | get :destroy |
|
94 | 94 | assert_response :success |
|
95 | 95 | assert_template 'destroy' |
|
96 | 96 | assert_select 'form[action=/my/account/destroy]' do |
|
97 | 97 | assert_select 'input[name=confirm]' |
|
98 | 98 | end |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def test_post_destroy_without_confirmation_should_not_destroy_account |
|
102 | 102 | assert_no_difference 'User.count' do |
|
103 | 103 | post :destroy |
|
104 | 104 | end |
|
105 | 105 | assert_response :success |
|
106 | 106 | assert_template 'destroy' |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def test_post_destroy_without_confirmation_should_destroy_account |
|
110 | 110 | assert_difference 'User.count', -1 do |
|
111 | 111 | post :destroy, :confirm => '1' |
|
112 | 112 | end |
|
113 | 113 | assert_redirected_to '/' |
|
114 | 114 | assert_match /deleted/i, flash[:notice] |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account |
|
118 | 118 | User.any_instance.stubs(:own_account_deletable?).returns(false) |
|
119 | 119 | |
|
120 | 120 | assert_no_difference 'User.count' do |
|
121 | 121 | post :destroy, :confirm => '1' |
|
122 | 122 | end |
|
123 | 123 | assert_redirected_to '/my/account' |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def test_change_password |
|
127 | 127 | get :password |
|
128 | 128 | assert_response :success |
|
129 | 129 | assert_template 'password' |
|
130 | 130 | |
|
131 | 131 | # non matching password confirmation |
|
132 | 132 | post :password, :password => 'jsmith', |
|
133 | 133 | :new_password => 'hello', |
|
134 | 134 | :new_password_confirmation => 'hello2' |
|
135 | 135 | assert_response :success |
|
136 | 136 | assert_template 'password' |
|
137 | 137 | assert_error_tag :content => /Password doesn't match confirmation/ |
|
138 | 138 | |
|
139 | 139 | # wrong password |
|
140 | 140 | post :password, :password => 'wrongpassword', |
|
141 | 141 | :new_password => 'hello', |
|
142 | 142 | :new_password_confirmation => 'hello' |
|
143 | 143 | assert_response :success |
|
144 | 144 | assert_template 'password' |
|
145 | 145 | assert_equal 'Wrong password', flash[:error] |
|
146 | 146 | |
|
147 | 147 | # good password |
|
148 | 148 | post :password, :password => 'jsmith', |
|
149 | 149 | :new_password => 'hello', |
|
150 | 150 | :new_password_confirmation => 'hello' |
|
151 | 151 | assert_redirected_to '/my/account' |
|
152 | 152 | assert User.try_to_login('jsmith', 'hello') |
|
153 | 153 | end |
|
154 | 154 | |
|
155 | def test_change_password_should_redirect_if_user_cannot_change_its_password | |
|
156 | User.find(2).update_attribute(:auth_source_id, 1) | |
|
157 | ||
|
158 | get :password | |
|
159 | assert_not_nil flash[:error] | |
|
160 | assert_redirected_to '/my/account' | |
|
161 | end | |
|
162 | ||
|
155 | 163 | def test_page_layout |
|
156 | 164 | get :page_layout |
|
157 | 165 | assert_response :success |
|
158 | 166 | assert_template 'page_layout' |
|
159 | 167 | end |
|
160 | 168 | |
|
161 | 169 | def test_add_block |
|
162 | 170 | xhr :post, :add_block, :block => 'issuesreportedbyme' |
|
163 | 171 | assert_response :success |
|
164 | 172 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') |
|
165 | 173 | end |
|
166 | 174 | |
|
167 | 175 | def test_remove_block |
|
168 | 176 | xhr :post, :remove_block, :block => 'issuesassignedtome' |
|
169 | 177 | assert_response :success |
|
170 | 178 | assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') |
|
171 | 179 | end |
|
172 | 180 | |
|
173 | 181 | def test_order_blocks |
|
174 | 182 | xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews'] |
|
175 | 183 | assert_response :success |
|
176 | 184 | assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] |
|
177 | 185 | end |
|
178 | 186 | |
|
179 | 187 | def test_reset_rss_key_with_existing_key |
|
180 | 188 | @previous_token_value = User.find(2).rss_key # Will generate one if it's missing |
|
181 | 189 | post :reset_rss_key |
|
182 | 190 | |
|
183 | 191 | assert_not_equal @previous_token_value, User.find(2).rss_key |
|
184 | 192 | assert User.find(2).rss_token |
|
185 | 193 | assert_match /reset/, flash[:notice] |
|
186 | 194 | assert_redirected_to '/my/account' |
|
187 | 195 | end |
|
188 | 196 | |
|
189 | 197 | def test_reset_rss_key_without_existing_key |
|
190 | 198 | assert_nil User.find(2).rss_token |
|
191 | 199 | post :reset_rss_key |
|
192 | 200 | |
|
193 | 201 | assert User.find(2).rss_token |
|
194 | 202 | assert_match /reset/, flash[:notice] |
|
195 | 203 | assert_redirected_to '/my/account' |
|
196 | 204 | end |
|
197 | 205 | |
|
198 | 206 | def test_reset_api_key_with_existing_key |
|
199 | 207 | @previous_token_value = User.find(2).api_key # Will generate one if it's missing |
|
200 | 208 | post :reset_api_key |
|
201 | 209 | |
|
202 | 210 | assert_not_equal @previous_token_value, User.find(2).api_key |
|
203 | 211 | assert User.find(2).api_token |
|
204 | 212 | assert_match /reset/, flash[:notice] |
|
205 | 213 | assert_redirected_to '/my/account' |
|
206 | 214 | end |
|
207 | 215 | |
|
208 | 216 | def test_reset_api_key_without_existing_key |
|
209 | 217 | assert_nil User.find(2).api_token |
|
210 | 218 | post :reset_api_key |
|
211 | 219 | |
|
212 | 220 | assert User.find(2).api_token |
|
213 | 221 | assert_match /reset/, flash[:notice] |
|
214 | 222 | assert_redirected_to '/my/account' |
|
215 | 223 | end |
|
216 | 224 | end |
General Comments 0
You need to be logged in to leave comments.
Login now