annotate .svn/pristine/42/42446df37f366c2f6600d52141458db7f2c89dcc.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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