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