diff 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
line wrap: on
line diff
--- a/test/unit/watcher_test.rb	Wed Jun 27 14:54:18 2012 +0100
+++ b/test/unit/watcher_test.rb	Mon Jan 07 12:01:42 2013 +0000
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  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
@@ -19,7 +19,7 @@
 
 class WatcherTest < ActiveSupport::TestCase
   fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules,
-           :issues,
+           :issues, :issue_statuses, :enumerations, :trackers, :projects_trackers,
            :boards, :messages,
            :wikis, :wiki_pages,
            :watchers
@@ -29,6 +29,13 @@
     @issue = Issue.find(1)
   end
 
+  def test_validate
+    user = User.find(5)
+    assert !user.active?
+    watcher = Watcher.new(:user_id => user.id)
+    assert !watcher.save
+  end
+
   def test_watch
     assert @issue.add_watcher(@user)
     @issue.reload
@@ -74,6 +81,13 @@
     assert issue.watched_by?(User.find(1))
   end
 
+  def test_watcher_user_ids_should_make_ids_uniq
+    issue = Issue.new(:project => Project.find(1), :tracker_id => 1, :subject => "test", :author => User.find(2))
+    issue.watcher_user_ids = ['1', '3', '1']
+    issue.save!
+    assert_equal 2, issue.watchers.count
+  end
+
   def test_addable_watcher_users
     addable_watcher_users = @issue.addable_watcher_users
     assert_kind_of Array, addable_watcher_users
@@ -140,4 +154,12 @@
     assert Issue.find(1).watched_by?(user)
     assert !Issue.find(4).watched_by?(user)
   end
+
+  def test_prune_all
+    user = User.find(9)
+    Watcher.new(:watchable => Issue.find(4), :user => User.find(9)).save(:validate => false)
+
+    assert Watcher.prune > 0
+    assert !Issue.find(4).watched_by?(user)
+  end
 end