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