]> source.dussan.org Git - redmine.git/commitdiff
Added missing tests for notify_about?
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 24 Nov 2014 21:08:03 +0000 (21:08 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 24 Nov 2014 21:08:03 +0000 (21:08 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13650 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/unit/user_test.rb

index 0ebbb532e2fdd3422d451acccf315448e4070a45..b41703ec1b98808897368208403af430831aea40 100644 (file)
@@ -1084,7 +1084,7 @@ class UserTest < ActiveSupport::TestCase
     assert_equal true, @anonymous.allowed_to_globally?(:view_issues)
   end
 
-  def test_notify_about_for_issue
+  def test_notify_about_issue
     project = Project.find(1)
     author = User.generate!
     assignee = User.generate!
@@ -1092,32 +1092,35 @@ class UserTest < ActiveSupport::TestCase
     Member.create!(:user => member, :project => project, :role_ids => [1])
     issue = Issue.generate!(:project => project, :assigned_to => assignee, :author => author)
 
-    author.mail_notification = 'all'
-    assert author.notify_about?(issue)
-    author.mail_notification = 'only_my_events'
-    assert author.notify_about?(issue)
-    author.mail_notification = 'only_owner'
-    assert author.notify_about?(issue)
-    author.mail_notification = 'selected'
-    assert author.notify_about?(issue)
-    author.mail_notification = 'none'
-    assert !author.notify_about?(issue)
-
-    assignee.mail_notification = 'only_my_events'
-    assert assignee.notify_about?(issue)
-    assignee.mail_notification = 'only_owner'
-    assert !assignee.notify_about?(issue)
-    assignee.mail_notification = 'only_assigned'
+    tests = {
+      author => %w(all only_my_events only_owner selected),
+      assignee => %w(all only_my_events only_assigned selected),
+      member => %w(all)
+    }
+
+    tests.each do |user, expected|
+      User::MAIL_NOTIFICATION_OPTIONS.map(&:first).each do |option|
+        user.mail_notification = option
+        assert_equal expected.include?(option), user.notify_about?(issue)
+      end
+    end
+  end
+
+  def test_notify_about_issue_for_previous_assignee
+    assignee = User.generate!(:mail_notification => 'only_assigned')
+    new_assignee = User.generate!(:mail_notification => 'only_assigned')
+    issue = Issue.generate!(:assigned_to => assignee)
+
     assert assignee.notify_about?(issue)
-    assignee.mail_notification = 'selected'
+    assert !new_assignee.notify_about?(issue)
+
+    issue.assigned_to = new_assignee
     assert assignee.notify_about?(issue)
+    assert new_assignee.notify_about?(issue)
 
-    member.mail_notification = 'only_my_events'
-    assert !member.notify_about?(issue)
-    member.mail_notification = 'only_assigned'
-    assert !member.notify_about?(issue)
-    member.mail_notification = 'selected'
-    assert !member.notify_about?(issue)
+    issue.save!
+    assert !assignee.notify_about?(issue)
+    assert new_assignee.notify_about?(issue)
   end
 
   def test_notify_about_news