You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

watcher_test.rb 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # redMine - project management software
  2. # Copyright (C) 2006-2007 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. require File.dirname(__FILE__) + '/../test_helper'
  18. class WatcherTest < Test::Unit::TestCase
  19. fixtures :issues, :users
  20. def setup
  21. @user = User.find(1)
  22. @issue = Issue.find(1)
  23. end
  24. def test_watch
  25. assert @issue.add_watcher(@user)
  26. @issue.reload
  27. assert @issue.watchers.detect { |w| w.user == @user }
  28. end
  29. def test_cant_watch_twice
  30. assert @issue.add_watcher(@user)
  31. assert !@issue.add_watcher(@user)
  32. end
  33. def test_watched_by
  34. assert @issue.add_watcher(@user)
  35. @issue.reload
  36. assert @issue.watched_by?(@user)
  37. assert Issue.watched_by(@user).include?(@issue)
  38. end
  39. def test_recipients
  40. @issue.watchers.delete_all
  41. @issue.reload
  42. assert @issue.watcher_recipients.empty?
  43. assert @issue.add_watcher(@user)
  44. @user.mail_notification = true
  45. @user.save
  46. @issue.reload
  47. assert @issue.watcher_recipients.include?(@user.mail)
  48. @user.mail_notification = false
  49. @user.save
  50. @issue.reload
  51. assert @issue.watcher_recipients.include?(@user.mail)
  52. end
  53. def test_unwatch
  54. assert @issue.add_watcher(@user)
  55. @issue.reload
  56. assert_equal 1, @issue.remove_watcher(@user)
  57. end
  58. end