comparison test/unit/watcher_test.rb @ 524:1248a47e81b3 feature_36

Merge from branch "luisf"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:39:38 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
519:3be6bc3c2a17 524:1248a47e81b3
13 # 13 #
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.dirname(__FILE__) + '/../test_helper' 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,
23 :boards, :messages, 23 :boards, :messages,
45 @issue.reload 45 @issue.reload
46 assert @issue.watched_by?(@user) 46 assert @issue.watched_by?(@user)
47 assert Issue.watched_by(@user).include?(@issue) 47 assert Issue.watched_by(@user).include?(@issue)
48 end 48 end
49 49
50 def test_watcher_users
51 watcher_users = Issue.find(2).watcher_users
52 assert_kind_of Array, watcher_users
53 assert_kind_of User, watcher_users.first
54 end
55
56 def test_watcher_users_should_not_validate_user
57 User.update_all("firstname = ''", "id=1")
58 @user.reload
59 assert !@user.valid?
60
61 issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2))
62 issue.watcher_users << @user
63 issue.save!
64 assert issue.watched_by?(@user)
65 end
66
50 def test_watcher_user_ids 67 def test_watcher_user_ids
68 assert_equal [1, 3], Issue.find(2).watcher_user_ids.sort
69 end
70
71 def test_watcher_user_ids=
51 issue = Issue.new 72 issue = Issue.new
52 issue.watcher_user_ids = ['1', '3'] 73 issue.watcher_user_ids = ['1', '3']
53 assert issue.watched_by?(User.find(1)) 74 assert issue.watched_by?(User.find(1))
75 end
76
77 def test_addable_watcher_users
78 addable_watcher_users = @issue.addable_watcher_users
79 assert_kind_of Array, addable_watcher_users
80 assert_kind_of User, addable_watcher_users.first
81 end
82
83 def test_addable_watcher_users_should_not_include_user_that_cannot_view_the_object
84 issue = Issue.new(:project => Project.find(1), :is_private => true)
85 assert_nil issue.addable_watcher_users.detect {|user| !issue.visible?(user)}
54 end 86 end
55 87
56 def test_recipients 88 def test_recipients
57 @issue.watchers.delete_all 89 @issue.watchers.delete_all
58 @issue.reload 90 @issue.reload
59 91
60 assert @issue.watcher_recipients.empty? 92 assert @issue.watcher_recipients.empty?
61 assert @issue.add_watcher(@user) 93 assert @issue.add_watcher(@user)
62 94
63 @user.mail_notification = true 95 @user.mail_notification = 'all'
64 @user.save 96 @user.save!
65 @issue.reload 97 @issue.reload
66 assert @issue.watcher_recipients.include?(@user.mail) 98 assert @issue.watcher_recipients.include?(@user.mail)
67 99
68 @user.mail_notification = false 100 @user.mail_notification = 'none'
69 @user.save 101 @user.save!
70 @issue.reload 102 @issue.reload
71 assert @issue.watcher_recipients.include?(@user.mail) 103 assert !@issue.watcher_recipients.include?(@user.mail)
72 end 104 end
73 105
74 def test_unwatch 106 def test_unwatch
75 assert @issue.add_watcher(@user) 107 assert @issue.add_watcher(@user)
76 @issue.reload 108 @issue.reload