Mercurial > hg > soundsoftware-site
comparison .svn/pristine/af/afff6ebb421c46aa468f585b7d8909132a409f4d.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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_update_account | |
86 post :account, | |
87 :user => { | |
88 :firstname => "Joe", | |
89 :login => "root", | |
90 :admin => 1, | |
91 :group_ids => ['10'], | |
92 :custom_field_values => {"4" => "0100562500"} | |
93 } | |
94 | |
95 assert_redirected_to '/my/account' | |
96 user = User.find(2) | |
97 assert_equal user, assigns(:user) | |
98 assert_equal "Joe", user.firstname | |
99 assert_equal "jsmith", user.login | |
100 assert_equal "0100562500", user.custom_value_for(4).value | |
101 # ignored | |
102 assert !user.admin? | |
103 assert user.groups.empty? | |
104 end | |
105 | |
106 def test_my_account_should_show_destroy_link | |
107 get :account | |
108 assert_select 'a[href=/my/account/destroy]' | |
109 end | |
110 | |
111 def test_get_destroy_should_display_the_destroy_confirmation | |
112 get :destroy | |
113 assert_response :success | |
114 assert_template 'destroy' | |
115 assert_select 'form[action=/my/account/destroy]' do | |
116 assert_select 'input[name=confirm]' | |
117 end | |
118 end | |
119 | |
120 def test_post_destroy_without_confirmation_should_not_destroy_account | |
121 assert_no_difference 'User.count' do | |
122 post :destroy | |
123 end | |
124 assert_response :success | |
125 assert_template 'destroy' | |
126 end | |
127 | |
128 def test_post_destroy_without_confirmation_should_destroy_account | |
129 assert_difference 'User.count', -1 do | |
130 post :destroy, :confirm => '1' | |
131 end | |
132 assert_redirected_to '/' | |
133 assert_match /deleted/i, flash[:notice] | |
134 end | |
135 | |
136 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account | |
137 User.any_instance.stubs(:own_account_deletable?).returns(false) | |
138 | |
139 assert_no_difference 'User.count' do | |
140 post :destroy, :confirm => '1' | |
141 end | |
142 assert_redirected_to '/my/account' | |
143 end | |
144 | |
145 def test_change_password | |
146 get :password | |
147 assert_response :success | |
148 assert_template 'password' | |
149 | |
150 # non matching password confirmation | |
151 post :password, :password => 'jsmith', | |
152 :new_password => 'secret123', | |
153 :new_password_confirmation => 'secret1234' | |
154 assert_response :success | |
155 assert_template 'password' | |
156 assert_error_tag :content => /Password doesn't match confirmation/ | |
157 | |
158 # wrong password | |
159 post :password, :password => 'wrongpassword', | |
160 :new_password => 'secret123', | |
161 :new_password_confirmation => 'secret123' | |
162 assert_response :success | |
163 assert_template 'password' | |
164 assert_equal 'Wrong password', flash[:error] | |
165 | |
166 # good password | |
167 post :password, :password => 'jsmith', | |
168 :new_password => 'secret123', | |
169 :new_password_confirmation => 'secret123' | |
170 assert_redirected_to '/my/account' | |
171 assert User.try_to_login('jsmith', 'secret123') | |
172 end | |
173 | |
174 def test_change_password_should_redirect_if_user_cannot_change_its_password | |
175 User.find(2).update_attribute(:auth_source_id, 1) | |
176 | |
177 get :password | |
178 assert_not_nil flash[:error] | |
179 assert_redirected_to '/my/account' | |
180 end | |
181 | |
182 def test_page_layout | |
183 get :page_layout | |
184 assert_response :success | |
185 assert_template 'page_layout' | |
186 end | |
187 | |
188 def test_add_block | |
189 post :add_block, :block => 'issuesreportedbyme' | |
190 assert_redirected_to '/my/page_layout' | |
191 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') | |
192 end | |
193 | |
194 def test_add_invalid_block_should_redirect | |
195 post :add_block, :block => 'invalid' | |
196 assert_redirected_to '/my/page_layout' | |
197 end | |
198 | |
199 def test_remove_block | |
200 post :remove_block, :block => 'issuesassignedtome' | |
201 assert_redirected_to '/my/page_layout' | |
202 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') | |
203 end | |
204 | |
205 def test_order_blocks | |
206 xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews'] | |
207 assert_response :success | |
208 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] | |
209 end | |
210 | |
211 def test_reset_rss_key_with_existing_key | |
212 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing | |
213 post :reset_rss_key | |
214 | |
215 assert_not_equal @previous_token_value, User.find(2).rss_key | |
216 assert User.find(2).rss_token | |
217 assert_match /reset/, flash[:notice] | |
218 assert_redirected_to '/my/account' | |
219 end | |
220 | |
221 def test_reset_rss_key_without_existing_key | |
222 assert_nil User.find(2).rss_token | |
223 post :reset_rss_key | |
224 | |
225 assert User.find(2).rss_token | |
226 assert_match /reset/, flash[:notice] | |
227 assert_redirected_to '/my/account' | |
228 end | |
229 | |
230 def test_reset_api_key_with_existing_key | |
231 @previous_token_value = User.find(2).api_key # Will generate one if it's missing | |
232 post :reset_api_key | |
233 | |
234 assert_not_equal @previous_token_value, User.find(2).api_key | |
235 assert User.find(2).api_token | |
236 assert_match /reset/, flash[:notice] | |
237 assert_redirected_to '/my/account' | |
238 end | |
239 | |
240 def test_reset_api_key_without_existing_key | |
241 assert_nil User.find(2).api_token | |
242 post :reset_api_key | |
243 | |
244 assert User.find(2).api_token | |
245 assert_match /reset/, flash[:notice] | |
246 assert_redirected_to '/my/account' | |
247 end | |
248 end |