annotate .svn/pristine/0b/0bc8b19a332c3f8ffc74fbaa182a97b748ff7feb.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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