Mercurial > hg > soundsoftware-site
comparison test/unit/.svn/text-base/user_test.rb.svn-base @ 37:94944d00e43c
* Update to SVN trunk rev 4411
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 19 Nov 2010 13:24:41 +0000 |
parents | 40f7cfd4df19 |
children | af80e5618e9b |
comparison
equal
deleted
inserted
replaced
22:40f7cfd4df19 | 37:94944d00e43c |
---|---|
57 assert !user.save | 57 assert !user.save |
58 assert_equal 1, user.errors.count | 58 assert_equal 1, user.errors.count |
59 | 59 |
60 user.password, user.password_confirmation = "password", "password" | 60 user.password, user.password_confirmation = "password", "password" |
61 assert user.save | 61 assert user.save |
62 end | |
63 | |
64 context "User#before_create" do | |
65 should "set the mail_notification to the default Setting" do | |
66 @user1 = User.generate_with_protected! | |
67 assert_equal 'only_my_events', @user1.mail_notification | |
68 | |
69 with_settings :default_notification_option => 'all' do | |
70 @user2 = User.generate_with_protected! | |
71 assert_equal 'all', @user2.mail_notification | |
72 end | |
73 end | |
62 end | 74 end |
63 | 75 |
64 context "User.login" do | 76 context "User.login" do |
65 should "be case-insensitive." do | 77 should "be case-insensitive." do |
66 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | 78 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
283 # user with no role | 295 # user with no role |
284 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?} | 296 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?} |
285 end | 297 end |
286 | 298 |
287 def test_mail_notification_all | 299 def test_mail_notification_all |
288 @jsmith.mail_notification = true | 300 @jsmith.mail_notification = 'all' |
289 @jsmith.notified_project_ids = [] | 301 @jsmith.notified_project_ids = [] |
290 @jsmith.save | 302 @jsmith.save |
291 @jsmith.reload | 303 @jsmith.reload |
292 assert @jsmith.projects.first.recipients.include?(@jsmith.mail) | 304 assert @jsmith.projects.first.recipients.include?(@jsmith.mail) |
293 end | 305 end |
294 | 306 |
295 def test_mail_notification_selected | 307 def test_mail_notification_selected |
296 @jsmith.mail_notification = false | 308 @jsmith.mail_notification = 'selected' |
297 @jsmith.notified_project_ids = [1] | 309 @jsmith.notified_project_ids = [1] |
298 @jsmith.save | 310 @jsmith.save |
299 @jsmith.reload | 311 @jsmith.reload |
300 assert Project.find(1).recipients.include?(@jsmith.mail) | 312 assert Project.find(1).recipients.include?(@jsmith.mail) |
301 end | 313 end |
302 | 314 |
303 def test_mail_notification_none | 315 def test_mail_notification_only_my_events |
304 @jsmith.mail_notification = false | 316 @jsmith.mail_notification = 'only_my_events' |
305 @jsmith.notified_project_ids = [] | 317 @jsmith.notified_project_ids = [] |
306 @jsmith.save | 318 @jsmith.save |
307 @jsmith.reload | 319 @jsmith.reload |
308 assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) | 320 assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) |
309 end | 321 end |
380 | 392 |
381 should "authorize normal users depending on their roles" do | 393 should "authorize normal users depending on their roles" do |
382 project = Project.find(1) | 394 project = Project.find(1) |
383 assert @jsmith.allowed_to?(:delete_messages, project) #Manager | 395 assert @jsmith.allowed_to?(:delete_messages, project) #Manager |
384 assert ! @dlopper.allowed_to?(:delete_messages, project) #Developper | 396 assert ! @dlopper.allowed_to?(:delete_messages, project) #Developper |
397 end | |
398 end | |
399 | |
400 context "with multiple projects" do | |
401 should "return false if array is empty" do | |
402 assert ! @admin.allowed_to?(:view_project, []) | |
403 end | |
404 | |
405 should "return true only if user has permission on all these projects" do | |
406 assert @admin.allowed_to?(:view_project, Project.all) | |
407 assert ! @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2) | |
408 assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere | |
409 assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers | |
410 end | |
411 | |
412 should "behave correctly with arrays of 1 project" do | |
413 assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first]) | |
385 end | 414 end |
386 end | 415 end |
387 | 416 |
388 context "with options[:global]" do | 417 context "with options[:global]" do |
389 should "authorize if user has at least one role that has this permission" do | 418 should "authorize if user has at least one role that has this permission" do |
396 assert @anonymous.allowed_to?(:view_issues, nil, :global => true) | 425 assert @anonymous.allowed_to?(:view_issues, nil, :global => true) |
397 end | 426 end |
398 end | 427 end |
399 end | 428 end |
400 | 429 |
430 context "User#notify_about?" do | |
431 context "Issues" do | |
432 setup do | |
433 @project = Project.find(1) | |
434 @author = User.generate_with_protected! | |
435 @assignee = User.generate_with_protected! | |
436 @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) | |
437 end | |
438 | |
439 should "be true for a user with :all" do | |
440 @author.update_attribute(:mail_notification, :all) | |
441 assert @author.notify_about?(@issue) | |
442 end | |
443 | |
444 should "be false for a user with :none" do | |
445 @author.update_attribute(:mail_notification, :none) | |
446 assert ! @author.notify_about?(@issue) | |
447 end | |
448 | |
449 should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do | |
450 @user = User.generate_with_protected!(:mail_notification => :only_my_events) | |
451 assert ! @user.notify_about?(@issue) | |
452 end | |
453 | |
454 should "be true for a user with :only_my_events and is the author" do | |
455 @author.update_attribute(:mail_notification, :only_my_events) | |
456 assert @author.notify_about?(@issue) | |
457 end | |
458 | |
459 should "be true for a user with :only_my_events and is the assignee" do | |
460 @assignee.update_attribute(:mail_notification, :only_my_events) | |
461 assert @assignee.notify_about?(@issue) | |
462 end | |
463 | |
464 should "be true for a user with :only_assigned and is the assignee" do | |
465 @assignee.update_attribute(:mail_notification, :only_assigned) | |
466 assert @assignee.notify_about?(@issue) | |
467 end | |
468 | |
469 should "be false for a user with :only_assigned and is not the assignee" do | |
470 @author.update_attribute(:mail_notification, :only_assigned) | |
471 assert ! @author.notify_about?(@issue) | |
472 end | |
473 | |
474 should "be true for a user with :only_owner and is the author" do | |
475 @author.update_attribute(:mail_notification, :only_owner) | |
476 assert @author.notify_about?(@issue) | |
477 end | |
478 | |
479 should "be false for a user with :only_owner and is not the author" do | |
480 @assignee.update_attribute(:mail_notification, :only_owner) | |
481 assert ! @assignee.notify_about?(@issue) | |
482 end | |
483 | |
484 should "be false if the mail_notification is anything else" do | |
485 @assignee.update_attribute(:mail_notification, :somthing_else) | |
486 assert ! @assignee.notify_about?(@issue) | |
487 end | |
488 | |
489 end | |
490 | |
491 context "other events" do | |
492 should 'be added and tested' | |
493 end | |
494 end | |
495 | |
401 if Object.const_defined?(:OpenID) | 496 if Object.const_defined?(:OpenID) |
402 | 497 |
403 def test_setting_identity_url | 498 def test_setting_identity_url |
404 normalized_open_id_url = 'http://example.com/' | 499 normalized_open_id_url = 'http://example.com/' |
405 u = User.new( :identity_url => 'http://example.com/' ) | 500 u = User.new( :identity_url => 'http://example.com/' ) |