@@ -40,12 +40,16 module Redmine | |||||
40 |
|
40 | |||
41 | # Adds user as a watcher |
|
41 | # Adds user as a watcher | |
42 | def add_watcher(user) |
|
42 | def add_watcher(user) | |
|
43 | # Rails does not reset the has_many :through association | |||
|
44 | watcher_users.reset | |||
43 | self.watchers << Watcher.new(:user => user) |
|
45 | self.watchers << Watcher.new(:user => user) | |
44 | end |
|
46 | end | |
45 |
|
47 | |||
46 | # Removes user from the watchers list |
|
48 | # Removes user from the watchers list | |
47 | def remove_watcher(user) |
|
49 | def remove_watcher(user) | |
48 | return nil unless user && user.is_a?(User) |
|
50 | return nil unless user && user.is_a?(User) | |
|
51 | # Rails does not reset the has_many :through association | |||
|
52 | watcher_users.reset | |||
49 | watchers.where(:user_id => user.id).delete_all |
|
53 | watchers.where(:user_id => user.id).delete_all | |
50 | end |
|
54 | end | |
51 |
|
55 |
@@ -277,12 +277,13 class MailHandlerTest < ActiveSupport::TestCase | |||||
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | def test_add_issue_should_add_cc_as_watchers |
|
279 | def test_add_issue_should_add_cc_as_watchers | |
|
280 | user = User.find_by_mail('dlopper@somenet.foo') | |||
280 | issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) |
|
281 | issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) | |
281 | assert issue.is_a?(Issue) |
|
282 | assert issue.is_a?(Issue) | |
282 | assert !issue.new_record? |
|
283 | assert !issue.new_record? | |
283 | issue.reload |
|
284 | assert issue.watched_by?(user) | |
284 | assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo')) |
|
|||
285 | assert_equal 1, issue.watcher_user_ids.size |
|
285 | assert_equal 1, issue.watcher_user_ids.size | |
|
286 | assert_include user, issue.watcher_users.to_a | |||
286 | end |
|
287 | end | |
287 |
|
288 | |||
288 | def test_add_issue_from_additional_email_address |
|
289 | def test_add_issue_from_additional_email_address |
@@ -60,6 +60,15 class WatcherTest < ActiveSupport::TestCase | |||||
60 | assert_kind_of User, watcher_users.first |
|
60 | assert_kind_of User, watcher_users.first | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
|
63 | def test_watcher_users_should_be_reloaded_after_adding_a_watcher | |||
|
64 | issue = Issue.find(2) | |||
|
65 | user = User.generate! | |||
|
66 | ||||
|
67 | assert_difference 'issue.watcher_users.to_a.size' do | |||
|
68 | issue.add_watcher user | |||
|
69 | end | |||
|
70 | end | |||
|
71 | ||||
63 | def test_watcher_users_should_not_validate_user |
|
72 | def test_watcher_users_should_not_validate_user | |
64 | User.where(:id => 1).update_all("firstname = ''") |
|
73 | User.where(:id => 1).update_all("firstname = ''") | |
65 | @user.reload |
|
74 | @user.reload |
General Comments 0
You need to be logged in to leave comments.
Login now