comparison test/unit/user_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 19
20 class UserTest < ActiveSupport::TestCase 20 class UserTest < ActiveSupport::TestCase
21 fixtures :users, :members, :projects, :roles, :member_roles, :auth_sources 21 fixtures :users, :members, :projects, :roles, :member_roles, :auth_sources
22 22
23 def setup 23 def setup
113 User.find(2).destroy 113 User.find(2).destroy
114 assert_nil User.find_by_id(2) 114 assert_nil User.find_by_id(2)
115 assert Member.find_all_by_user_id(2).empty? 115 assert Member.find_all_by_user_id(2).empty?
116 end 116 end
117 117
118 def test_validate 118 def test_validate_login_presence
119 @admin.login = "" 119 @admin.login = ""
120 assert !@admin.save 120 assert !@admin.save
121 assert_equal 1, @admin.errors.count 121 assert_equal 1, @admin.errors.count
122 end
123
124 def test_validate_mail_notification_inclusion
125 u = User.new
126 u.mail_notification = 'foo'
127 u.save
128 assert_not_nil u.errors.on(:mail_notification)
122 end 129 end
123 130
124 context "User#try_to_login" do 131 context "User#try_to_login" do
125 should "fall-back to case-insensitive if user login is not found as-typed." do 132 should "fall-back to case-insensitive if user login is not found as-typed." do
126 user = User.try_to_login("AdMin", "admin") 133 user = User.try_to_login("AdMin", "admin")
435 @assignee = User.generate_with_protected! 442 @assignee = User.generate_with_protected!
436 @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) 443 @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author)
437 end 444 end
438 445
439 should "be true for a user with :all" do 446 should "be true for a user with :all" do
440 @author.update_attribute(:mail_notification, :all) 447 @author.update_attribute(:mail_notification, 'all')
441 assert @author.notify_about?(@issue) 448 assert @author.notify_about?(@issue)
442 end 449 end
443 450
444 should "be false for a user with :none" do 451 should "be false for a user with :none" do
445 @author.update_attribute(:mail_notification, :none) 452 @author.update_attribute(:mail_notification, 'none')
446 assert ! @author.notify_about?(@issue) 453 assert ! @author.notify_about?(@issue)
447 end 454 end
448 455
449 should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do 456 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) 457 @user = User.generate_with_protected!(:mail_notification => 'only_my_events')
451 assert ! @user.notify_about?(@issue) 458 assert ! @user.notify_about?(@issue)
452 end 459 end
453 460
454 should "be true for a user with :only_my_events and is the author" do 461 should "be true for a user with :only_my_events and is the author" do
455 @author.update_attribute(:mail_notification, :only_my_events) 462 @author.update_attribute(:mail_notification, 'only_my_events')
456 assert @author.notify_about?(@issue) 463 assert @author.notify_about?(@issue)
457 end 464 end
458 465
459 should "be true for a user with :only_my_events and is the assignee" do 466 should "be true for a user with :only_my_events and is the assignee" do
460 @assignee.update_attribute(:mail_notification, :only_my_events) 467 @assignee.update_attribute(:mail_notification, 'only_my_events')
461 assert @assignee.notify_about?(@issue) 468 assert @assignee.notify_about?(@issue)
462 end 469 end
463 470
464 should "be true for a user with :only_assigned and is the assignee" do 471 should "be true for a user with :only_assigned and is the assignee" do
465 @assignee.update_attribute(:mail_notification, :only_assigned) 472 @assignee.update_attribute(:mail_notification, 'only_assigned')
466 assert @assignee.notify_about?(@issue) 473 assert @assignee.notify_about?(@issue)
467 end 474 end
468 475
469 should "be false for a user with :only_assigned and is not the assignee" do 476 should "be false for a user with :only_assigned and is not the assignee" do
470 @author.update_attribute(:mail_notification, :only_assigned) 477 @author.update_attribute(:mail_notification, 'only_assigned')
471 assert ! @author.notify_about?(@issue) 478 assert ! @author.notify_about?(@issue)
472 end 479 end
473 480
474 should "be true for a user with :only_owner and is the author" do 481 should "be true for a user with :only_owner and is the author" do
475 @author.update_attribute(:mail_notification, :only_owner) 482 @author.update_attribute(:mail_notification, 'only_owner')
476 assert @author.notify_about?(@issue) 483 assert @author.notify_about?(@issue)
477 end 484 end
478 485
479 should "be false for a user with :only_owner and is not the author" do 486 should "be false for a user with :only_owner and is not the author" do
480 @assignee.update_attribute(:mail_notification, :only_owner) 487 @assignee.update_attribute(:mail_notification, 'only_owner')
481 assert ! @assignee.notify_about?(@issue) 488 assert ! @assignee.notify_about?(@issue)
482 end 489 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 end
490 491
491 context "other events" do 492 context "other events" do
492 should 'be added and tested' 493 should 'be added and tested'
493 end 494 end