comparison test/unit/watcher_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 class WatcherTest < ActiveSupport::TestCase 20 class WatcherTest < ActiveSupport::TestCase
21 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, 21 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules,
22 :issues, 22 :issues, :issue_statuses, :enumerations, :trackers, :projects_trackers,
23 :boards, :messages, 23 :boards, :messages,
24 :wikis, :wiki_pages, 24 :wikis, :wiki_pages,
25 :watchers 25 :watchers
26 26
27 def setup 27 def setup
28 @user = User.find(1) 28 @user = User.find(1)
29 @issue = Issue.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
30 end 37 end
31 38
32 def test_watch 39 def test_watch
33 assert @issue.add_watcher(@user) 40 assert @issue.add_watcher(@user)
34 @issue.reload 41 @issue.reload
70 77
71 def test_watcher_user_ids= 78 def test_watcher_user_ids=
72 issue = Issue.new 79 issue = Issue.new
73 issue.watcher_user_ids = ['1', '3'] 80 issue.watcher_user_ids = ['1', '3']
74 assert issue.watched_by?(User.find(1)) 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
75 end 89 end
76 90
77 def test_addable_watcher_users 91 def test_addable_watcher_users
78 addable_watcher_users = @issue.addable_watcher_users 92 addable_watcher_users = @issue.addable_watcher_users
79 assert_kind_of Array, addable_watcher_users 93 assert_kind_of Array, addable_watcher_users
138 end 152 end
139 153
140 assert Issue.find(1).watched_by?(user) 154 assert Issue.find(1).watched_by?(user)
141 assert !Issue.find(4).watched_by?(user) 155 assert !Issue.find(4).watched_by?(user)
142 end 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
143 end 165 end