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