annotate .svn/pristine/98/98a5258051109b3158da9d70775bc4f9d0d7e352.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class WatcherTest < ActiveSupport::TestCase
Chris@1296 21 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules,
Chris@1296 22 :issues, :issue_statuses, :enumerations, :trackers, :projects_trackers,
Chris@1296 23 :boards, :messages,
Chris@1296 24 :wikis, :wiki_pages,
Chris@1296 25 :watchers
Chris@1296 26
Chris@1296 27 def setup
Chris@1296 28 @user = User.find(1)
Chris@1296 29 @issue = Issue.find(1)
Chris@1296 30 end
Chris@1296 31
Chris@1296 32 def test_validate
Chris@1296 33 user = User.find(5)
Chris@1296 34 assert !user.active?
Chris@1296 35 watcher = Watcher.new(:user_id => user.id)
Chris@1296 36 assert !watcher.save
Chris@1296 37 end
Chris@1296 38
Chris@1296 39 def test_watch
Chris@1296 40 assert @issue.add_watcher(@user)
Chris@1296 41 @issue.reload
Chris@1296 42 assert @issue.watchers.detect { |w| w.user == @user }
Chris@1296 43 end
Chris@1296 44
Chris@1296 45 def test_cant_watch_twice
Chris@1296 46 assert @issue.add_watcher(@user)
Chris@1296 47 assert !@issue.add_watcher(@user)
Chris@1296 48 end
Chris@1296 49
Chris@1296 50 def test_watched_by
Chris@1296 51 assert @issue.add_watcher(@user)
Chris@1296 52 @issue.reload
Chris@1296 53 assert @issue.watched_by?(@user)
Chris@1296 54 assert Issue.watched_by(@user).include?(@issue)
Chris@1296 55 end
Chris@1296 56
Chris@1296 57 def test_watcher_users
Chris@1296 58 watcher_users = Issue.find(2).watcher_users
Chris@1296 59 assert_kind_of Array, watcher_users
Chris@1296 60 assert_kind_of User, watcher_users.first
Chris@1296 61 end
Chris@1296 62
Chris@1296 63 def test_watcher_users_should_not_validate_user
Chris@1296 64 User.update_all("firstname = ''", "id=1")
Chris@1296 65 @user.reload
Chris@1296 66 assert !@user.valid?
Chris@1296 67
Chris@1296 68 issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2))
Chris@1296 69 issue.watcher_users << @user
Chris@1296 70 issue.save!
Chris@1296 71 assert issue.watched_by?(@user)
Chris@1296 72 end
Chris@1296 73
Chris@1296 74 def test_watcher_user_ids
Chris@1296 75 assert_equal [1, 3], Issue.find(2).watcher_user_ids.sort
Chris@1296 76 end
Chris@1296 77
Chris@1296 78 def test_watcher_user_ids=
Chris@1296 79 issue = Issue.new
Chris@1296 80 issue.watcher_user_ids = ['1', '3']
Chris@1296 81 assert issue.watched_by?(User.find(1))
Chris@1296 82 end
Chris@1296 83
Chris@1296 84 def test_watcher_user_ids_should_make_ids_uniq
Chris@1296 85 issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2))
Chris@1296 86 issue.watcher_user_ids = ['1', '3', '1']
Chris@1296 87 issue.save!
Chris@1296 88 assert_equal 2, issue.watchers.count
Chris@1296 89 end
Chris@1296 90
Chris@1296 91 def test_addable_watcher_users
Chris@1296 92 addable_watcher_users = @issue.addable_watcher_users
Chris@1296 93 assert_kind_of Array, addable_watcher_users
Chris@1296 94 assert_kind_of User, addable_watcher_users.first
Chris@1296 95 end
Chris@1296 96
Chris@1296 97 def test_addable_watcher_users_should_not_include_user_that_cannot_view_the_object
Chris@1296 98 issue = Issue.new(:project => Project.find(1), :is_private => true)
Chris@1296 99 assert_nil issue.addable_watcher_users.detect {|user| !issue.visible?(user)}
Chris@1296 100 end
Chris@1296 101
Chris@1296 102 def test_recipients
Chris@1296 103 @issue.watchers.delete_all
Chris@1296 104 @issue.reload
Chris@1296 105
Chris@1296 106 assert @issue.watcher_recipients.empty?
Chris@1296 107 assert @issue.add_watcher(@user)
Chris@1296 108
Chris@1296 109 @user.mail_notification = 'all'
Chris@1296 110 @user.save!
Chris@1296 111 @issue.reload
Chris@1296 112 assert @issue.watcher_recipients.include?(@user.mail)
Chris@1296 113
Chris@1296 114 @user.mail_notification = 'none'
Chris@1296 115 @user.save!
Chris@1296 116 @issue.reload
Chris@1296 117 assert !@issue.watcher_recipients.include?(@user.mail)
Chris@1296 118 end
Chris@1296 119
Chris@1296 120 def test_unwatch
Chris@1296 121 assert @issue.add_watcher(@user)
Chris@1296 122 @issue.reload
Chris@1296 123 assert_equal 1, @issue.remove_watcher(@user)
Chris@1296 124 end
Chris@1296 125
Chris@1296 126 def test_prune
Chris@1296 127 Watcher.delete_all("user_id = 9")
Chris@1296 128 user = User.find(9)
Chris@1296 129
Chris@1296 130 # public
Chris@1296 131 Watcher.create!(:watchable => Issue.find(1), :user => user)
Chris@1296 132 Watcher.create!(:watchable => Issue.find(2), :user => user)
Chris@1296 133 Watcher.create!(:watchable => Message.find(1), :user => user)
Chris@1296 134 Watcher.create!(:watchable => Wiki.find(1), :user => user)
Chris@1296 135 Watcher.create!(:watchable => WikiPage.find(2), :user => user)
Chris@1296 136
Chris@1296 137 # private project (id: 2)
Chris@1296 138 Member.create!(:project => Project.find(2), :principal => user, :role_ids => [1])
Chris@1296 139 Watcher.create!(:watchable => Issue.find(4), :user => user)
Chris@1296 140 Watcher.create!(:watchable => Message.find(7), :user => user)
Chris@1296 141 Watcher.create!(:watchable => Wiki.find(2), :user => user)
Chris@1296 142 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
Chris@1296 143
Chris@1296 144 assert_no_difference 'Watcher.count' do
Chris@1296 145 Watcher.prune(:user => User.find(9))
Chris@1296 146 end
Chris@1296 147
Chris@1296 148 Member.delete_all
Chris@1296 149
Chris@1296 150 assert_difference 'Watcher.count', -4 do
Chris@1296 151 Watcher.prune(:user => User.find(9))
Chris@1296 152 end
Chris@1296 153
Chris@1296 154 assert Issue.find(1).watched_by?(user)
Chris@1296 155 assert !Issue.find(4).watched_by?(user)
Chris@1296 156 end
Chris@1296 157
Chris@1296 158 def test_prune_all
Chris@1296 159 user = User.find(9)
Chris@1296 160 Watcher.new(:watchable => Issue.find(4), :user => User.find(9)).save(:validate => false)
Chris@1296 161
Chris@1296 162 assert Watcher.prune > 0
Chris@1296 163 assert !Issue.find(4).watched_by?(user)
Chris@1296 164 end
Chris@1296 165 end