##// END OF EJS Templates
code format clean up UserTest...
Toshi MARUYAMA -
r12122:478a23bfa315
parent child
Show More
@@ -34,7 +34,8 class UserTest < ActiveSupport::TestCase
34 end
34 end
35
35
36 def test_sorted_scope_should_sort_user_by_display_name
36 def test_sorted_scope_should_sort_user_by_display_name
37 assert_equal User.all.map(&:name).map(&:downcase).sort, User.sorted.all.map(&:name).map(&:downcase)
37 assert_equal User.all.map(&:name).map(&:downcase).sort,
38 User.sorted.all.map(&:name).map(&:downcase)
38 end
39 end
39
40
40 def test_generate
41 def test_generate
@@ -138,7 +139,8 class UserTest < ActiveSupport::TestCase
138 u.login = 'newuser'
139 u.login = 'newuser'
139 u.password, u.password_confirmation = "password", "password"
140 u.password, u.password_confirmation = "password", "password"
140 assert u.save
141 assert u.save
141 u = User.new(:firstname => "Similar", :lastname => "User", :mail => "similaruser@somenet.foo")
142 u = User.new(:firstname => "Similar", :lastname => "User",
143 :mail => "similaruser@somenet.foo")
142 u.login = 'NewUser'
144 u.login = 'NewUser'
143 u.password, u.password_confirmation = "password", "password"
145 u.password, u.password_confirmation = "password", "password"
144 assert !u.save
146 assert !u.save
@@ -207,7 +209,8 class UserTest < ActiveSupport::TestCase
207
209
208 def test_destroy_should_update_comments
210 def test_destroy_should_update_comments
209 comment = Comment.create!(
211 comment = Comment.create!(
210 :commented => News.create!(:project_id => 1, :author_id => 1, :title => 'foo', :description => 'foo'),
212 :commented => News.create!(:project_id => 1,
213 :author_id => 1, :title => 'foo', :description => 'foo'),
211 :author => User.find(2),
214 :author => User.find(2),
212 :comments => 'foo'
215 :comments => 'foo'
213 )
216 )
@@ -218,7 +221,8 class UserTest < ActiveSupport::TestCase
218 end
221 end
219
222
220 def test_destroy_should_update_issues
223 def test_destroy_should_update_issues
221 issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo')
224 issue = Issue.create!(:project_id => 1, :author_id => 2,
225 :tracker_id => 1, :subject => 'foo')
222
226
223 User.find(2).destroy
227 User.find(2).destroy
224 assert_nil User.find_by_id(2)
228 assert_nil User.find_by_id(2)
@@ -226,7 +230,8 class UserTest < ActiveSupport::TestCase
226 end
230 end
227
231
228 def test_destroy_should_unassign_issues
232 def test_destroy_should_unassign_issues
229 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2)
233 issue = Issue.create!(:project_id => 1, :author_id => 1,
234 :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2)
230
235
231 User.find(2).destroy
236 User.find(2).destroy
232 assert_nil User.find_by_id(2)
237 assert_nil User.find_by_id(2)
@@ -234,7 +239,8 class UserTest < ActiveSupport::TestCase
234 end
239 end
235
240
236 def test_destroy_should_update_journals
241 def test_destroy_should_update_journals
237 issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo')
242 issue = Issue.create!(:project_id => 1, :author_id => 2,
243 :tracker_id => 1, :subject => 'foo')
238 issue.init_journal(User.find(2), "update")
244 issue.init_journal(User.find(2), "update")
239 issue.save!
245 issue.save!
240
246
@@ -244,7 +250,8 class UserTest < ActiveSupport::TestCase
244 end
250 end
245
251
246 def test_destroy_should_update_journal_details_old_value
252 def test_destroy_should_update_journal_details_old_value
247 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2)
253 issue = Issue.create!(:project_id => 1, :author_id => 1,
254 :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2)
248 issue.init_journal(User.find(1), "update")
255 issue.init_journal(User.find(1), "update")
249 issue.assigned_to_id = nil
256 issue.assigned_to_id = nil
250 assert_difference 'JournalDetail.count' do
257 assert_difference 'JournalDetail.count' do
@@ -259,7 +266,8 class UserTest < ActiveSupport::TestCase
259 end
266 end
260
267
261 def test_destroy_should_update_journal_details_value
268 def test_destroy_should_update_journal_details_value
262 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo')
269 issue = Issue.create!(:project_id => 1, :author_id => 1,
270 :tracker_id => 1, :subject => 'foo')
263 issue.init_journal(User.find(1), "update")
271 issue.init_journal(User.find(1), "update")
264 issue.assigned_to_id = 2
272 issue.assigned_to_id = 2
265 assert_difference 'JournalDetail.count' do
273 assert_difference 'JournalDetail.count' do
@@ -275,16 +283,16 class UserTest < ActiveSupport::TestCase
275
283
276 def test_destroy_should_update_messages
284 def test_destroy_should_update_messages
277 board = Board.create!(:project_id => 1, :name => 'Board', :description => 'Board')
285 board = Board.create!(:project_id => 1, :name => 'Board', :description => 'Board')
278 message = Message.create!(:board_id => board.id, :author_id => 2, :subject => 'foo', :content => 'foo')
286 message = Message.create!(:board_id => board.id, :author_id => 2,
279
287 :subject => 'foo', :content => 'foo')
280 User.find(2).destroy
288 User.find(2).destroy
281 assert_nil User.find_by_id(2)
289 assert_nil User.find_by_id(2)
282 assert_equal User.anonymous, message.reload.author
290 assert_equal User.anonymous, message.reload.author
283 end
291 end
284
292
285 def test_destroy_should_update_news
293 def test_destroy_should_update_news
286 news = News.create!(:project_id => 1, :author_id => 2, :title => 'foo', :description => 'foo')
294 news = News.create!(:project_id => 1, :author_id => 2,
287
295 :title => 'foo', :description => 'foo')
288 User.find(2).destroy
296 User.find(2).destroy
289 assert_nil User.find_by_id(2)
297 assert_nil User.find_by_id(2)
290 assert_equal User.anonymous, news.reload.author
298 assert_equal User.anonymous, news.reload.author
@@ -313,7 +321,8 class UserTest < ActiveSupport::TestCase
313 end
321 end
314
322
315 def test_destroy_should_update_time_entries
323 def test_destroy_should_update_time_entries
316 entry = TimeEntry.new(:hours => '2', :spent_on => Date.today, :activity => TimeEntryActivity.create!(:name => 'foo'))
324 entry = TimeEntry.new(:hours => '2', :spent_on => Date.today,
325 :activity => TimeEntryActivity.create!(:name => 'foo'))
317 entry.project_id = 1
326 entry.project_id = 1
318 entry.user_id = 2
327 entry.user_id = 2
319 entry.save!
328 entry.save!
@@ -332,7 +341,8 class UserTest < ActiveSupport::TestCase
332 end
341 end
333
342
334 def test_destroy_should_delete_watchers
343 def test_destroy_should_delete_watchers
335 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo')
344 issue = Issue.create!(:project_id => 1, :author_id => 1,
345 :tracker_id => 1, :subject => 'foo')
336 watcher = Watcher.create!(:user_id => 2, :watchable => issue)
346 watcher = Watcher.create!(:user_id => 2, :watchable => issue)
337
347
338 User.find(2).destroy
348 User.find(2).destroy
@@ -344,7 +354,9 class UserTest < ActiveSupport::TestCase
344 wiki_content = WikiContent.create!(
354 wiki_content = WikiContent.create!(
345 :text => 'foo',
355 :text => 'foo',
346 :author_id => 2,
356 :author_id => 2,
347 :page => WikiPage.create!(:title => 'Foo', :wiki => Wiki.create!(:project_id => 3, :start_page => 'Start'))
357 :page => WikiPage.create!(:title => 'Foo',
358 :wiki => Wiki.create!(:project_id => 3,
359 :start_page => 'Start'))
348 )
360 )
349 wiki_content.text = 'bar'
361 wiki_content.text = 'bar'
350 assert_difference 'WikiContent::Version.count' do
362 assert_difference 'WikiContent::Version.count' do
@@ -418,7 +430,8 class UserTest < ActiveSupport::TestCase
418
430
419 def test_validate_password_length
431 def test_validate_password_length
420 with_settings :password_min_length => '100' do
432 with_settings :password_min_length => '100' do
421 user = User.new(:firstname => "new100", :lastname => "user100", :mail => "newuser100@somenet.foo")
433 user = User.new(:firstname => "new100",
434 :lastname => "user100", :mail => "newuser100@somenet.foo")
422 user.login = "newuser100"
435 user.login = "newuser100"
423 user.password, user.password_confirmation = "password100", "password100"
436 user.password, user.password_confirmation = "password100", "password100"
424 assert !user.save
437 assert !user.save
@@ -473,25 +486,29 class UserTest < ActiveSupport::TestCase
473
486
474 def test_fields_for_order_statement_should_return_fields_according_user_format_setting
487 def test_fields_for_order_statement_should_return_fields_according_user_format_setting
475 with_settings :user_format => 'lastname_coma_firstname' do
488 with_settings :user_format => 'lastname_coma_firstname' do
476 assert_equal ['users.lastname', 'users.firstname', 'users.id'], User.fields_for_order_statement
489 assert_equal ['users.lastname', 'users.firstname', 'users.id'],
490 User.fields_for_order_statement
477 end
491 end
478 end
492 end
479
493
480 def test_fields_for_order_statement_width_table_name_should_prepend_table_name
494 def test_fields_for_order_statement_width_table_name_should_prepend_table_name
481 with_settings :user_format => 'lastname_firstname' do
495 with_settings :user_format => 'lastname_firstname' do
482 assert_equal ['authors.lastname', 'authors.firstname', 'authors.id'], User.fields_for_order_statement('authors')
496 assert_equal ['authors.lastname', 'authors.firstname', 'authors.id'],
497 User.fields_for_order_statement('authors')
483 end
498 end
484 end
499 end
485
500
486 def test_fields_for_order_statement_with_blank_format_should_return_default
501 def test_fields_for_order_statement_with_blank_format_should_return_default
487 with_settings :user_format => '' do
502 with_settings :user_format => '' do
488 assert_equal ['users.firstname', 'users.lastname', 'users.id'], User.fields_for_order_statement
503 assert_equal ['users.firstname', 'users.lastname', 'users.id'],
504 User.fields_for_order_statement
489 end
505 end
490 end
506 end
491
507
492 def test_fields_for_order_statement_with_invalid_format_should_return_default
508 def test_fields_for_order_statement_with_invalid_format_should_return_default
493 with_settings :user_format => 'foo' do
509 with_settings :user_format => 'foo' do
494 assert_equal ['users.firstname', 'users.lastname', 'users.id'], User.fields_for_order_statement
510 assert_equal ['users.firstname', 'users.lastname', 'users.id'],
511 User.fields_for_order_statement
495 end
512 end
496 end
513 end
497
514
General Comments 0
You need to be logged in to leave comments. Login now