Mercurial > hg > soundsoftware-site
comparison test/functional/users_controller_test.rb @ 119:8661b858af72
* Update to Redmine trunk rev 4705
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 14:12:06 +0000 |
parents | 94944d00e43c |
children | 07fa8a8b56a8 |
comparison
equal
deleted
inserted
replaced
39:150ceac17a8d | 119:8661b858af72 |
---|---|
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 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 | 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. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.dirname(__FILE__) + '/../test_helper' | 18 require File.expand_path('../../test_helper', __FILE__) |
19 require 'users_controller' | 19 require 'users_controller' |
20 | 20 |
21 # Re-raise errors caught by the controller. | 21 # Re-raise errors caught by the controller. |
22 class UsersController; def rescue_action(e) raise e end; end | 22 class UsersController; def rescue_action(e) raise e end; end |
23 | 23 |
117 memberships = assigns(:memberships) | 117 memberships = assigns(:memberships) |
118 assert_not_nil memberships | 118 assert_not_nil memberships |
119 project_ids = memberships.map(&:project_id) | 119 project_ids = memberships.map(&:project_id) |
120 assert project_ids.include?(2) #private project admin can see | 120 assert project_ids.include?(2) #private project admin can see |
121 end | 121 end |
122 | 122 |
123 context "GET :new" do | 123 def test_show_current_should_require_authentication |
124 setup do | 124 @request.session[:user_id] = nil |
125 get :new | 125 get :show, :id => 'current' |
126 end | 126 assert_response 302 |
127 | 127 end |
128 should_assign_to :user | 128 |
129 should_respond_with :success | 129 def test_show_current |
130 should_render_template :new | 130 @request.session[:user_id] = 2 |
131 end | 131 get :show, :id => 'current' |
132 | 132 assert_response :success |
133 context "POST :create" do | 133 assert_template 'show' |
134 context "when successful" do | 134 assert_equal User.find(2), assigns(:user) |
135 setup do | 135 end |
136 post :create, :user => { | 136 |
137 :firstname => 'John', | 137 def test_new |
138 :lastname => 'Doe', | 138 get :new |
139 :login => 'jdoe', | 139 |
140 :password => 'test', | 140 assert_response :success |
141 :password_confirmation => 'test', | 141 assert_template :new |
142 :mail => 'jdoe@gmail.com' | 142 assert assigns(:user) |
143 }, | 143 end |
144 :notification_option => 'none' | 144 |
145 end | 145 def test_create |
146 | 146 Setting.bcc_recipients = '1' |
147 should_assign_to :user | 147 |
148 should_respond_with :redirect | 148 assert_difference 'User.count' do |
149 should_redirect_to('user edit') { {:controller => 'users', :action => 'edit', :id => User.find_by_login('jdoe')}} | 149 assert_difference 'ActionMailer::Base.deliveries.size' do |
150 | 150 post :create, |
151 should 'set the users mail notification' do | 151 :user => { |
152 user = User.last | 152 :firstname => 'John', |
153 assert_equal 'none', user.mail_notification | 153 :lastname => 'Doe', |
154 :login => 'jdoe', | |
155 :password => 'secret', | |
156 :password_confirmation => 'secret', | |
157 :mail => 'jdoe@gmail.com', | |
158 :mail_notification => 'none' | |
159 }, | |
160 :send_information => '1' | |
154 end | 161 end |
155 end | 162 end |
156 | 163 |
157 context "when unsuccessful" do | 164 user = User.first(:order => 'id DESC') |
158 setup do | 165 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id |
159 post :create, :user => {} | 166 |
160 end | 167 assert_equal 'John', user.firstname |
161 | 168 assert_equal 'Doe', user.lastname |
162 should_assign_to :user | 169 assert_equal 'jdoe', user.login |
163 should_respond_with :success | 170 assert_equal 'jdoe@gmail.com', user.mail |
164 should_render_template :new | 171 assert_equal 'none', user.mail_notification |
172 assert user.check_password?('secret') | |
173 | |
174 mail = ActionMailer::Base.deliveries.last | |
175 assert_not_nil mail | |
176 assert_equal [user.mail], mail.bcc | |
177 assert mail.body.include?('secret') | |
178 end | |
179 | |
180 def test_create_with_failure | |
181 assert_no_difference 'User.count' do | |
182 post :create, :user => {} | |
165 end | 183 end |
166 | 184 |
185 assert_response :success | |
186 assert_template 'new' | |
187 end | |
188 | |
189 def test_edit | |
190 get :edit, :id => 2 | |
191 | |
192 assert_response :success | |
193 assert_template 'edit' | |
194 assert_equal User.find(2), assigns(:user) | |
167 end | 195 end |
168 | 196 |
169 def test_update | 197 def test_update |
170 ActionMailer::Base.deliveries.clear | 198 ActionMailer::Base.deliveries.clear |
171 put :update, :id => 2, :user => {:firstname => 'Changed'}, :notification_option => 'all', :pref => {:hide_mail => '1', :comments_sorting => 'desc'} | 199 put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'} |
172 | 200 |
173 user = User.find(2) | 201 user = User.find(2) |
174 assert_equal 'Changed', user.firstname | 202 assert_equal 'Changed', user.firstname |
175 assert_equal 'all', user.mail_notification | 203 assert_equal 'only_assigned', user.mail_notification |
176 assert_equal true, user.pref[:hide_mail] | 204 assert_equal true, user.pref[:hide_mail] |
177 assert_equal 'desc', user.pref[:comments_sorting] | 205 assert_equal 'desc', user.pref[:comments_sorting] |
178 assert ActionMailer::Base.deliveries.empty? | 206 assert ActionMailer::Base.deliveries.empty? |
207 end | |
208 | |
209 def test_update_with_failure | |
210 assert_no_difference 'User.count' do | |
211 put :update, :id => 2, :user => {:firstname => ''} | |
212 end | |
213 | |
214 assert_response :success | |
215 assert_template 'edit' | |
216 end | |
217 | |
218 def test_update_with_group_ids_should_assign_groups | |
219 put :update, :id => 2, :user => {:group_ids => ['10']} | |
220 | |
221 user = User.find(2) | |
222 assert_equal [10], user.group_ids | |
179 end | 223 end |
180 | 224 |
181 def test_update_with_activation_should_send_a_notification | 225 def test_update_with_activation_should_send_a_notification |
182 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') | 226 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') |
183 u.login = 'foo' | 227 u.login = 'foo' |
192 assert_not_nil mail | 236 assert_not_nil mail |
193 assert_equal ['foo.bar@somenet.foo'], mail.bcc | 237 assert_equal ['foo.bar@somenet.foo'], mail.bcc |
194 assert mail.body.include?(ll('fr', :notice_account_activated)) | 238 assert mail.body.include?(ll('fr', :notice_account_activated)) |
195 end | 239 end |
196 | 240 |
197 def test_updat_with_password_change_should_send_a_notification | 241 def test_update_with_password_change_should_send_a_notification |
198 ActionMailer::Base.deliveries.clear | 242 ActionMailer::Base.deliveries.clear |
199 Setting.bcc_recipients = '1' | 243 Setting.bcc_recipients = '1' |
200 | 244 |
245 put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1' | |
201 u = User.find(2) | 246 u = User.find(2) |
202 put :update, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1' | 247 assert u.check_password?('newpass') |
203 assert_equal User.hash_password('newpass'), u.reload.hashed_password | |
204 | 248 |
205 mail = ActionMailer::Base.deliveries.last | 249 mail = ActionMailer::Base.deliveries.last |
206 assert_not_nil mail | 250 assert_not_nil mail |
207 assert_equal [u.mail], mail.bcc | 251 assert_equal [u.mail], mail.bcc |
208 assert mail.body.include?('newpass') | 252 assert mail.body.include?('newpass') |
212 # Configure as auth source | 256 # Configure as auth source |
213 u = User.find(2) | 257 u = User.find(2) |
214 u.auth_source = AuthSource.find(1) | 258 u.auth_source = AuthSource.find(1) |
215 u.save! | 259 u.save! |
216 | 260 |
217 put :update, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass' | 261 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass'}, :password_confirmation => 'newpass' |
218 | 262 |
219 assert_equal nil, u.reload.auth_source | 263 assert_equal nil, u.reload.auth_source |
220 assert_equal User.hash_password('newpass'), u.reload.hashed_password | 264 assert u.check_password?('newpass') |
221 end | 265 end |
222 | 266 |
223 def test_edit_membership | 267 def test_edit_membership |
224 post :edit_membership, :id => 2, :membership_id => 1, | 268 post :edit_membership, :id => 2, :membership_id => 1, |
225 :membership => { :role_ids => [2]} | 269 :membership => { :role_ids => [2]} |