annotate test/unit/watcher_test.rb @ 862:9e5828c6e55d bug_169

Close obsolete branch bug_169
author Chris Cannam
date Tue, 07 Jun 2011 13:31:44 +0100
parents 513646585e45
children af80e5618e9b
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19
Chris@0 20 class WatcherTest < ActiveSupport::TestCase
Chris@0 21 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules,
Chris@0 22 :issues,
Chris@0 23 :boards, :messages,
Chris@0 24 :wikis, :wiki_pages,
Chris@0 25 :watchers
Chris@0 26
Chris@0 27 def setup
Chris@0 28 @user = User.find(1)
Chris@0 29 @issue = Issue.find(1)
Chris@0 30 end
Chris@0 31
Chris@0 32 def test_watch
Chris@0 33 assert @issue.add_watcher(@user)
Chris@0 34 @issue.reload
Chris@0 35 assert @issue.watchers.detect { |w| w.user == @user }
Chris@0 36 end
Chris@0 37
Chris@0 38 def test_cant_watch_twice
Chris@0 39 assert @issue.add_watcher(@user)
Chris@0 40 assert !@issue.add_watcher(@user)
Chris@0 41 end
Chris@0 42
Chris@0 43 def test_watched_by
Chris@0 44 assert @issue.add_watcher(@user)
Chris@0 45 @issue.reload
Chris@0 46 assert @issue.watched_by?(@user)
Chris@0 47 assert Issue.watched_by(@user).include?(@issue)
Chris@0 48 end
Chris@0 49
Chris@0 50 def test_watcher_user_ids
Chris@0 51 issue = Issue.new
Chris@0 52 issue.watcher_user_ids = ['1', '3']
Chris@0 53 assert issue.watched_by?(User.find(1))
Chris@0 54 end
Chris@0 55
Chris@0 56 def test_recipients
Chris@0 57 @issue.watchers.delete_all
Chris@0 58 @issue.reload
Chris@0 59
Chris@0 60 assert @issue.watcher_recipients.empty?
Chris@0 61 assert @issue.add_watcher(@user)
Chris@0 62
Chris@0 63 @user.mail_notification = true
Chris@0 64 @user.save
Chris@0 65 @issue.reload
Chris@0 66 assert @issue.watcher_recipients.include?(@user.mail)
Chris@0 67
Chris@0 68 @user.mail_notification = false
Chris@0 69 @user.save
Chris@0 70 @issue.reload
Chris@0 71 assert @issue.watcher_recipients.include?(@user.mail)
Chris@0 72 end
Chris@0 73
Chris@0 74 def test_unwatch
Chris@0 75 assert @issue.add_watcher(@user)
Chris@0 76 @issue.reload
Chris@0 77 assert_equal 1, @issue.remove_watcher(@user)
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_prune
Chris@0 81 Watcher.delete_all("user_id = 9")
Chris@0 82 user = User.find(9)
Chris@0 83
Chris@0 84 # public
Chris@0 85 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@0 86 Watcher.create!(:watchable => Issue.find(2), :user => user)
Chris@0 87 Watcher.create!(:watchable => Message.find(1), :user => user)
Chris@0 88 Watcher.create!(:watchable => Wiki.find(1), :user => user)
Chris@0 89 Watcher.create!(:watchable => WikiPage.find(2), :user => user)
Chris@0 90
Chris@0 91 # private project (id: 2)
Chris@0 92 Member.create!(:project => Project.find(2), :principal => user, :role_ids => [1])
Chris@0 93 Watcher.create!(:watchable => Issue.find(4), :user => user)
Chris@0 94 Watcher.create!(:watchable => Message.find(7), :user => user)
Chris@0 95 Watcher.create!(:watchable => Wiki.find(2), :user => user)
Chris@0 96 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
Chris@0 97
Chris@0 98 assert_no_difference 'Watcher.count' do
Chris@0 99 Watcher.prune(:user => User.find(9))
Chris@0 100 end
Chris@0 101
Chris@0 102 Member.delete_all
Chris@0 103
Chris@0 104 assert_difference 'Watcher.count', -4 do
Chris@0 105 Watcher.prune(:user => User.find(9))
Chris@0 106 end
Chris@0 107
Chris@0 108 assert Issue.find(1).watched_by?(user)
Chris@0 109 assert !Issue.find(4).watched_by?(user)
Chris@0 110 end
Chris@0 111 end