diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-13 12:39:22 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-13 12:39:22 +0000 |
commit | f33231181f9591ee67577e229a8bf6de24516ba0 (patch) | |
tree | 57bbc4338b9cf35cecf323565fefbf549ecfd14f /test/unit/watcher_test.rb | |
parent | c31a6719735114c371e5da68eb3787b8713c5360 (diff) | |
download | redmine-f33231181f9591ee67577e229a8bf6de24516ba0.tar.gz redmine-f33231181f9591ee67577e229a8bf6de24516ba0.zip |
Makes user unwatch what he can no longer view after its permissions have changed (#3589).
A rake task (redmine:watchers:prune) is also added to prune existing watchers.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3167 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/watcher_test.rb')
-rw-r--r-- | test/unit/watcher_test.rb | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index f49365edf..db73f8ccc 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2009 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,7 +18,11 @@ require File.dirname(__FILE__) + '/../test_helper' class WatcherTest < ActiveSupport::TestCase - fixtures :issues, :users + fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, + :issues, + :boards, :messages, + :wikis, :wiki_pages, + :watchers def setup @user = User.find(1) @@ -66,4 +70,36 @@ class WatcherTest < ActiveSupport::TestCase @issue.reload assert_equal 1, @issue.remove_watcher(@user) end + + def test_prune + Watcher.delete_all("user_id = 9") + user = User.find(9) + + # public + Watcher.create!(:watchable => Issue.find(1), :user => user) + Watcher.create!(:watchable => Issue.find(2), :user => user) + Watcher.create!(:watchable => Message.find(1), :user => user) + Watcher.create!(:watchable => Wiki.find(1), :user => user) + Watcher.create!(:watchable => WikiPage.find(2), :user => user) + + # private project (id: 2) + Member.create!(:project => Project.find(2), :principal => user, :role_ids => [1]) + Watcher.create!(:watchable => Issue.find(4), :user => user) + Watcher.create!(:watchable => Message.find(7), :user => user) + Watcher.create!(:watchable => Wiki.find(2), :user => user) + Watcher.create!(:watchable => WikiPage.find(3), :user => user) + + assert_no_difference 'Watcher.count' do + Watcher.prune(:user => User.find(9)) + end + + Member.delete_all + + assert_difference 'Watcher.count', -4 do + Watcher.prune(:user => User.find(9)) + end + + assert Issue.find(1).watched_by?(user) + assert !Issue.find(4).watched_by?(user) + end end |