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