Commit b04d6c63 authored by jplang's avatar jplang

When creating issues by receiving an email, watchers created via CC in the...

When creating issues by receiving an email, watchers created via CC in the mail don't get an email notification (#23278).

git-svn-id: https://svn.redmine.org/redmine/trunk@15609 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 7f06014e
...@@ -40,12 +40,16 @@ module Redmine ...@@ -40,12 +40,16 @@ module Redmine
# Adds user as a watcher # Adds user as a watcher
def add_watcher(user) def add_watcher(user)
# Rails does not reset the has_many :through association
watcher_users.reset
self.watchers << Watcher.new(:user => user) self.watchers << Watcher.new(:user => user)
end end
# Removes user from the watchers list # Removes user from the watchers list
def remove_watcher(user) def remove_watcher(user)
return nil unless user && user.is_a?(User) return nil unless user && user.is_a?(User)
# Rails does not reset the has_many :through association
watcher_users.reset
watchers.where(:user_id => user.id).delete_all watchers.where(:user_id => user.id).delete_all
end end
......
...@@ -277,12 +277,13 @@ class MailHandlerTest < ActiveSupport::TestCase ...@@ -277,12 +277,13 @@ class MailHandlerTest < ActiveSupport::TestCase
end end
def test_add_issue_should_add_cc_as_watchers def test_add_issue_should_add_cc_as_watchers
user = User.find_by_mail('dlopper@somenet.foo')
issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'}) issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
assert issue.is_a?(Issue) assert issue.is_a?(Issue)
assert !issue.new_record? assert !issue.new_record?
issue.reload assert issue.watched_by?(user)
assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
assert_equal 1, issue.watcher_user_ids.size assert_equal 1, issue.watcher_user_ids.size
assert_include user, issue.watcher_users.to_a
end end
def test_add_issue_from_additional_email_address def test_add_issue_from_additional_email_address
......
...@@ -60,6 +60,15 @@ class WatcherTest < ActiveSupport::TestCase ...@@ -60,6 +60,15 @@ class WatcherTest < ActiveSupport::TestCase
assert_kind_of User, watcher_users.first assert_kind_of User, watcher_users.first
end end
def test_watcher_users_should_be_reloaded_after_adding_a_watcher
issue = Issue.find(2)
user = User.generate!
assert_difference 'issue.watcher_users.to_a.size' do
issue.add_watcher user
end
end
def test_watcher_users_should_not_validate_user def test_watcher_users_should_not_validate_user
User.where(:id => 1).update_all("firstname = ''") User.where(:id => 1).update_all("firstname = ''")
@user.reload @user.reload
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment