Mercurial > hg > soundsoftware-site
diff 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 |
line wrap: on
line diff
--- a/test/unit/.svn/text-base/user_test.rb.svn-base Fri Sep 24 14:06:04 2010 +0100 +++ b/test/unit/.svn/text-base/user_test.rb.svn-base Fri Nov 19 13:24:41 2010 +0000 @@ -60,6 +60,18 @@ user.password, user.password_confirmation = "password", "password" assert user.save end + + context "User#before_create" do + should "set the mail_notification to the default Setting" do + @user1 = User.generate_with_protected! + assert_equal 'only_my_events', @user1.mail_notification + + with_settings :default_notification_option => 'all' do + @user2 = User.generate_with_protected! + assert_equal 'all', @user2.mail_notification + end + end + end context "User.login" do should "be case-insensitive." do @@ -285,7 +297,7 @@ end def test_mail_notification_all - @jsmith.mail_notification = true + @jsmith.mail_notification = 'all' @jsmith.notified_project_ids = [] @jsmith.save @jsmith.reload @@ -293,15 +305,15 @@ end def test_mail_notification_selected - @jsmith.mail_notification = false + @jsmith.mail_notification = 'selected' @jsmith.notified_project_ids = [1] @jsmith.save @jsmith.reload assert Project.find(1).recipients.include?(@jsmith.mail) end - def test_mail_notification_none - @jsmith.mail_notification = false + def test_mail_notification_only_my_events + @jsmith.mail_notification = 'only_my_events' @jsmith.notified_project_ids = [] @jsmith.save @jsmith.reload @@ -384,6 +396,23 @@ assert ! @dlopper.allowed_to?(:delete_messages, project) #Developper end end + + context "with multiple projects" do + should "return false if array is empty" do + assert ! @admin.allowed_to?(:view_project, []) + end + + should "return true only if user has permission on all these projects" do + assert @admin.allowed_to?(:view_project, Project.all) + assert ! @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2) + assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere + assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers + end + + should "behave correctly with arrays of 1 project" do + assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first]) + end + end context "with options[:global]" do should "authorize if user has at least one role that has this permission" do @@ -398,6 +427,72 @@ end end + context "User#notify_about?" do + context "Issues" do + setup do + @project = Project.find(1) + @author = User.generate_with_protected! + @assignee = User.generate_with_protected! + @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) + end + + should "be true for a user with :all" do + @author.update_attribute(:mail_notification, :all) + assert @author.notify_about?(@issue) + end + + should "be false for a user with :none" do + @author.update_attribute(:mail_notification, :none) + assert ! @author.notify_about?(@issue) + end + + should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do + @user = User.generate_with_protected!(:mail_notification => :only_my_events) + assert ! @user.notify_about?(@issue) + end + + should "be true for a user with :only_my_events and is the author" do + @author.update_attribute(:mail_notification, :only_my_events) + assert @author.notify_about?(@issue) + end + + should "be true for a user with :only_my_events and is the assignee" do + @assignee.update_attribute(:mail_notification, :only_my_events) + assert @assignee.notify_about?(@issue) + end + + should "be true for a user with :only_assigned and is the assignee" do + @assignee.update_attribute(:mail_notification, :only_assigned) + assert @assignee.notify_about?(@issue) + end + + should "be false for a user with :only_assigned and is not the assignee" do + @author.update_attribute(:mail_notification, :only_assigned) + assert ! @author.notify_about?(@issue) + end + + should "be true for a user with :only_owner and is the author" do + @author.update_attribute(:mail_notification, :only_owner) + assert @author.notify_about?(@issue) + end + + should "be false for a user with :only_owner and is not the author" do + @assignee.update_attribute(:mail_notification, :only_owner) + assert ! @assignee.notify_about?(@issue) + end + + should "be false if the mail_notification is anything else" do + @assignee.update_attribute(:mail_notification, :somthing_else) + assert ! @assignee.notify_about?(@issue) + end + + end + + context "other events" do + should 'be added and tested' + end + end + if Object.const_defined?(:OpenID) def test_setting_identity_url