Mercurial > hg > soundsoftware-site
comparison test/functional/my_controller_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 3e4c3460b6ca |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
20 | 20 |
21 # Re-raise errors caught by the controller. | 21 # Re-raise errors caught by the controller. |
22 class MyController; def rescue_action(e) raise e end; end | 22 class MyController; def rescue_action(e) raise e end; end |
23 | 23 |
24 class MyControllerTest < ActionController::TestCase | 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, :members, :member_roles, |
26 :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources | |
26 | 27 |
27 def setup | 28 def setup |
28 @controller = MyController.new | 29 @controller = MyController.new |
29 @request = ActionController::TestRequest.new | 30 @request = ActionController::TestRequest.new |
30 @request.session[:user_id] = 2 | 31 @request.session[:user_id] = 2 |
39 | 40 |
40 def test_page | 41 def test_page |
41 get :page | 42 get :page |
42 assert_response :success | 43 assert_response :success |
43 assert_template 'page' | 44 assert_template 'page' |
45 end | |
46 | |
47 def test_page_with_timelog_block | |
48 preferences = User.find(2).pref | |
49 preferences[:my_page_layout] = {'top' => ['timelog']} | |
50 preferences.save! | |
51 TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10) | |
52 | |
53 get :page | |
54 assert_response :success | |
55 assert_select 'tr.time-entry' do | |
56 assert_select 'td.subject a[href=/issues/1]' | |
57 assert_select 'td.hours', :text => '2.50' | |
58 end | |
44 end | 59 end |
45 | 60 |
46 def test_my_account_should_show_editable_custom_fields | 61 def test_my_account_should_show_editable_custom_fields |
47 get :account | 62 get :account |
48 assert_response :success | 63 assert_response :success |
82 # ignored | 97 # ignored |
83 assert !user.admin? | 98 assert !user.admin? |
84 assert user.groups.empty? | 99 assert user.groups.empty? |
85 end | 100 end |
86 | 101 |
102 def test_my_account_should_show_destroy_link | |
103 get :account | |
104 assert_select 'a[href=/my/account/destroy]' | |
105 end | |
106 | |
107 def test_get_destroy_should_display_the_destroy_confirmation | |
108 get :destroy | |
109 assert_response :success | |
110 assert_template 'destroy' | |
111 assert_select 'form[action=/my/account/destroy]' do | |
112 assert_select 'input[name=confirm]' | |
113 end | |
114 end | |
115 | |
116 def test_post_destroy_without_confirmation_should_not_destroy_account | |
117 assert_no_difference 'User.count' do | |
118 post :destroy | |
119 end | |
120 assert_response :success | |
121 assert_template 'destroy' | |
122 end | |
123 | |
124 def test_post_destroy_without_confirmation_should_destroy_account | |
125 assert_difference 'User.count', -1 do | |
126 post :destroy, :confirm => '1' | |
127 end | |
128 assert_redirected_to '/' | |
129 assert_match /deleted/i, flash[:notice] | |
130 end | |
131 | |
132 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account | |
133 User.any_instance.stubs(:own_account_deletable?).returns(false) | |
134 | |
135 assert_no_difference 'User.count' do | |
136 post :destroy, :confirm => '1' | |
137 end | |
138 assert_redirected_to '/my/account' | |
139 end | |
140 | |
87 def test_change_password | 141 def test_change_password |
88 get :password | 142 get :password |
89 assert_response :success | 143 assert_response :success |
90 assert_template 'password' | 144 assert_template 'password' |
91 | 145 |
92 # non matching password confirmation | 146 # non matching password confirmation |
93 post :password, :password => 'jsmith', | 147 post :password, :password => 'jsmith', |
94 :new_password => 'hello', | 148 :new_password => 'secret123', |
95 :new_password_confirmation => 'hello2' | 149 :new_password_confirmation => 'secret1234' |
96 assert_response :success | 150 assert_response :success |
97 assert_template 'password' | 151 assert_template 'password' |
98 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } | 152 assert_error_tag :content => /Password doesn't match confirmation/ |
99 | 153 |
100 # wrong password | 154 # wrong password |
101 post :password, :password => 'wrongpassword', | 155 post :password, :password => 'wrongpassword', |
102 :new_password => 'hello', | 156 :new_password => 'secret123', |
103 :new_password_confirmation => 'hello' | 157 :new_password_confirmation => 'secret123' |
104 assert_response :success | 158 assert_response :success |
105 assert_template 'password' | 159 assert_template 'password' |
106 assert_equal 'Wrong password', flash[:error] | 160 assert_equal 'Wrong password', flash[:error] |
107 | 161 |
108 # good password | 162 # good password |
109 post :password, :password => 'jsmith', | 163 post :password, :password => 'jsmith', |
110 :new_password => 'hello', | 164 :new_password => 'secret123', |
111 :new_password_confirmation => 'hello' | 165 :new_password_confirmation => 'secret123' |
112 assert_redirected_to '/my/account' | 166 assert_redirected_to '/my/account' |
113 assert User.try_to_login('jsmith', 'hello') | 167 assert User.try_to_login('jsmith', 'secret123') |
168 end | |
169 | |
170 def test_change_password_should_redirect_if_user_cannot_change_its_password | |
171 User.find(2).update_attribute(:auth_source_id, 1) | |
172 | |
173 get :password | |
174 assert_not_nil flash[:error] | |
175 assert_redirected_to '/my/account' | |
114 end | 176 end |
115 | 177 |
116 def test_page_layout | 178 def test_page_layout |
117 get :page_layout | 179 get :page_layout |
118 assert_response :success | 180 assert_response :success |
119 assert_template 'page_layout' | 181 assert_template 'page_layout' |
120 end | 182 end |
121 | 183 |
122 def test_add_block | 184 def test_add_block |
123 xhr :post, :add_block, :block => 'issuesreportedbyme' | 185 post :add_block, :block => 'issuesreportedbyme' |
124 assert_response :success | 186 assert_redirected_to '/my/page_layout' |
125 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') | 187 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') |
126 end | 188 end |
127 | 189 |
128 def test_remove_block | 190 def test_remove_block |
129 xhr :post, :remove_block, :block => 'issuesassignedtome' | 191 post :remove_block, :block => 'issuesassignedtome' |
130 assert_response :success | 192 assert_redirected_to '/my/page_layout' |
131 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') | 193 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') |
132 end | 194 end |
133 | 195 |
134 def test_order_blocks | 196 def test_order_blocks |
135 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews'] | 197 xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews'] |
136 assert_response :success | 198 assert_response :success |
137 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] | 199 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] |
138 end | 200 end |
139 | 201 |
140 context "POST to reset_rss_key" do | 202 def test_reset_rss_key_with_existing_key |
141 context "with an existing rss_token" do | 203 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing |
142 setup do | 204 post :reset_rss_key |
143 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing | 205 |
144 post :reset_rss_key | 206 assert_not_equal @previous_token_value, User.find(2).rss_key |
145 end | 207 assert User.find(2).rss_token |
146 | 208 assert_match /reset/, flash[:notice] |
147 should "destroy the existing token" do | 209 assert_redirected_to '/my/account' |
148 assert_not_equal @previous_token_value, User.find(2).rss_key | 210 end |
149 end | 211 |
150 | 212 def test_reset_rss_key_without_existing_key |
151 should "create a new token" do | 213 assert_nil User.find(2).rss_token |
152 assert User.find(2).rss_token | 214 post :reset_rss_key |
153 end | 215 |
154 | 216 assert User.find(2).rss_token |
155 should_set_the_flash_to /reset/ | 217 assert_match /reset/, flash[:notice] |
156 should_redirect_to('my account') {'/my/account' } | 218 assert_redirected_to '/my/account' |
157 end | 219 end |
158 | 220 |
159 context "with no rss_token" do | 221 def test_reset_api_key_with_existing_key |
160 setup do | 222 @previous_token_value = User.find(2).api_key # Will generate one if it's missing |
161 assert_nil User.find(2).rss_token | 223 post :reset_api_key |
162 post :reset_rss_key | 224 |
163 end | 225 assert_not_equal @previous_token_value, User.find(2).api_key |
164 | 226 assert User.find(2).api_token |
165 should "create a new token" do | 227 assert_match /reset/, flash[:notice] |
166 assert User.find(2).rss_token | 228 assert_redirected_to '/my/account' |
167 end | 229 end |
168 | 230 |
169 should_set_the_flash_to /reset/ | 231 def test_reset_api_key_without_existing_key |
170 should_redirect_to('my account') {'/my/account' } | 232 assert_nil User.find(2).api_token |
171 end | 233 post :reset_api_key |
172 end | 234 |
173 | 235 assert User.find(2).api_token |
174 context "POST to reset_api_key" do | 236 assert_match /reset/, flash[:notice] |
175 context "with an existing api_token" do | 237 assert_redirected_to '/my/account' |
176 setup do | |
177 @previous_token_value = User.find(2).api_key # Will generate one if it's missing | |
178 post :reset_api_key | |
179 end | |
180 | |
181 should "destroy the existing token" do | |
182 assert_not_equal @previous_token_value, User.find(2).api_key | |
183 end | |
184 | |
185 should "create a new token" do | |
186 assert User.find(2).api_token | |
187 end | |
188 | |
189 should_set_the_flash_to /reset/ | |
190 should_redirect_to('my account') {'/my/account' } | |
191 end | |
192 | |
193 context "with no api_token" do | |
194 setup do | |
195 assert_nil User.find(2).api_token | |
196 post :reset_api_key | |
197 end | |
198 | |
199 should "create a new token" do | |
200 assert User.find(2).api_token | |
201 end | |
202 | |
203 should_set_the_flash_to /reset/ | |
204 should_redirect_to('my account') {'/my/account' } | |
205 end | |
206 end | 238 end |
207 end | 239 end |