From ee8e7a4e33616e6a0d2c881213c648eaf9a67713 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 24 Nov 2014 21:08:03 +0000 Subject: [PATCH] Added missing tests for notify_about? git-svn-id: http://svn.redmine.org/redmine/trunk@13650 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/user_test.rb | 51 ++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 0ebbb532e..b41703ec1 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -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 -- 2.39.5