From 31bbdd754618e76ec51c8116e8ee1b437ad42700 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sun, 7 Nov 2021 08:13:56 +0100 Subject: [PATCH] Allow users to be mentioned using "@". diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index 5c60d9d37..747215450 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -60,6 +60,19 @@ class AutoCompletesController < ApplicationController render json: format_wiki_pages_json(wiki_pages) end + def users + users = [] + q = (params[:q] || params[:term]).to_s.strip + scope = nil + if params[:q].blank? && @project.present? + scope = @project.users + else + scope = User.all.limit(10) + end + users = scope.active.visible.sorted.like(params[:q]).to_a + render :json => format_users_json(users) + end + private def find_project @@ -89,4 +102,14 @@ class AutoCompletesController < ApplicationController } end end + + def format_users_json(users) + users.map {|user| { + 'firstname' => user.firstname, + 'lastname' => user.lastname, + 'name' => user.name, + 'login' => user.login + } + } + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0e3f56c2c..ba45ac63f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1822,7 +1822,8 @@ module ApplicationHelper def autocomplete_data_sources(project) { issues: auto_complete_issues_path(:project_id => project, :q => ''), - wiki_pages: auto_complete_wiki_pages_path(:project_id => project, :q => '') + wiki_pages: auto_complete_wiki_pages_path(:project_id => project, :q => ''), + users: auto_complete_users_path(:project_id => @project, :q => '') } end diff --git a/app/models/issue.rb b/app/models/issue.rb index 02aaff33b..ab9f794db 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -54,6 +54,8 @@ class Issue < ActiveRecord::Base acts_as_activity_provider :scope => proc {preload(:project, :author, :tracker, :status)}, :author_key => :author_id + acts_as_mentionable :attributes => ['description'] + DONE_RATIO_OPTIONS = %w(issue_field issue_status) attr_reader :transition_warning diff --git a/app/models/journal.rb b/app/models/journal.rb index 333441204..d13ed41a6 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -58,6 +58,7 @@ class Journal < ActiveRecord::Base " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct end ) + acts_as_mentionable :attributes => ['notes'] before_create :split_private_notes after_create_commit :send_notification @@ -172,9 +173,13 @@ class Journal < ActiveRecord::Base def notified_watchers notified = journalized.notified_watchers - if private_notes? - notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)} - end + notified = select_journal_visible_user(notified) + notified + end + + def notified_mentions + notified = super + notified = select_journal_visible_user(notified) notified end @@ -337,4 +342,11 @@ class Journal < ActiveRecord::Base Mailer.deliver_issue_edit(self) end end + + def select_journal_visible_user(notified) + if private_notes? + notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)} + end + notified + end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 17518a18a..a19836977 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -94,7 +94,7 @@ class Mailer < ActionMailer::Base # Example: # Mailer.deliver_issue_add(issue) def self.deliver_issue_add(issue) - users = issue.notified_users | issue.notified_watchers + users = issue.notified_users | issue.notified_watchers | issue.notified_mentions users.each do |user| issue_add(user, issue).deliver_later end @@ -129,7 +129,7 @@ class Mailer < ActionMailer::Base # Example: # Mailer.deliver_issue_edit(journal) def self.deliver_issue_edit(journal) - users = journal.notified_users | journal.notified_watchers + users = journal.notified_users | journal.notified_watchers | journal.notified_mentions | journal.journalized.notified_mentions users.select! do |user| journal.notes? || journal.visible_details(user).any? end @@ -222,7 +222,7 @@ class Mailer < ActionMailer::Base # Example: # Mailer.deliver_news_added(news) def self.deliver_news_added(news) - users = news.notified_users | news.notified_watchers_for_added_news + users = news.notified_users | news.notified_watchers_for_added_news | news.notified_mentions users.each do |user| news_added(user, news).deliver_later end @@ -306,7 +306,7 @@ class Mailer < ActionMailer::Base # Example: # Mailer.deliver_wiki_content_added(wiki_content) def self.deliver_wiki_content_added(wiki_content) - users = wiki_content.notified_users | wiki_content.page.wiki.notified_watchers + users = wiki_content.notified_users | wiki_content.page.wiki.notified_watchers | wiki_content.notified_mentions users.each do |user| wiki_content_added(user, wiki_content).deliver_later end @@ -343,6 +343,7 @@ class Mailer < ActionMailer::Base users = wiki_content.notified_users users |= wiki_content.page.notified_watchers users |= wiki_content.page.wiki.notified_watchers + users |= wiki_content.notified_mentions users.each do |user| wiki_content_updated(user, wiki_content).deliver_later diff --git a/app/models/news.rb b/app/models/news.rb index fd24157c9..3193471b1 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -35,6 +35,7 @@ class News < ActiveRecord::Base acts_as_activity_provider :scope => proc {preload(:project, :author)}, :author_key => :author_id acts_as_watchable + acts_as_mentionable :attributes => ['description'] after_create :add_author_as_watcher after_create_commit :send_notification diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index ba16b7e29..7fa61560f 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -24,6 +24,9 @@ class WikiContent < ActiveRecord::Base belongs_to :page, :class_name => 'WikiPage' belongs_to :author, :class_name => 'User' has_many :versions, :class_name => 'WikiContentVersion', :dependent => :delete_all + + acts_as_mentionable :attributes => ['text'] + validates_presence_of :text validates_length_of :comments, :maximum => 1024, :allow_nil => true diff --git a/config/routes.rb b/config/routes.rb index 9e17c65d9..031d9ea99 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,9 +46,10 @@ Rails.application.routes.draw do post 'boards/:board_id/topics/:id/edit', :to => 'messages#edit' post 'boards/:board_id/topics/:id/destroy', :to => 'messages#destroy' - # Auto complate routes + # Auto complete routes match '/issues/auto_complete', :to => 'auto_completes#issues', :via => :get, :as => 'auto_complete_issues' match '/wiki_pages/auto_complete', :to => 'auto_completes#wiki_pages', :via => :get, :as => 'auto_complete_wiki_pages' + match '/users/auto_complete', :to => 'auto_completes#users', :via => :get, :as => 'auto_complete_users' # Misc issue routes. TODO: move into resources match '/issues/context_menu', :to => 'context_menus#issues', :as => 'issues_context_menu', :via => [:get, :post] diff --git a/lib/redmine.rb b/lib/redmine.rb index 98b089cac..1bf70f695 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -36,4 +36,5 @@ rescue LoadError end module Redmine + end diff --git a/lib/redmine/acts/mentionable.rb b/lib/redmine/acts/mentionable.rb new file mode 100644 index 000000000..b080bd1b7 --- /dev/null +++ b/lib/redmine/acts/mentionable.rb @@ -0,0 +1,109 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2022 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module Redmine + module Acts + module Mentionable + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def acts_as_mentionable(options = {}) + class_attribute :mentionable_attributes + self.mentionable_attributes = options[:attributes] + + attr_accessor :mentioned_users + + send :include, Redmine::Acts::Mentionable::InstanceMethods + + after_save :parse_mentions + end + end + + module InstanceMethods + def self.included(base) + base.extend ClassMethods + end + + def notified_mentions + notified = mentioned_users.to_a + notified.reject! {|user| user.mail.blank? || user.mail_notification == 'none'} + if respond_to?(:visible?) + notified.reject! {|user| !visible?(user)} + end + notified + end + + private + + def parse_mentions + mentionable_attrs = self.mentionable_attributes + saved_mentionable_attrs = self.saved_changes.select{|a| mentionable_attrs.include?(a)} + + saved_mentionable_attrs.each do |key, attr| + old_value, new_value = attr + get_mentioned_users(old_value, new_value) + end + end + + def get_mentioned_users(old_content, new_content) + self.mentioned_users = [] + + previous_matches = scan_for_mentioned_users(old_content) + current_matches = scan_for_mentioned_users(new_content) + new_matches = (current_matches - previous_matches).flatten + + if new_matches.any? + self.mentioned_users = User.visible.active.where(login: new_matches) + end + end + + def scan_for_mentioned_users(content) + return [] if content.nil? + + # remove quoted text + content = content.gsub(%r{\r\n(?:\>\s)+(.*?)\r\n}m, '') + + text_formatting = Setting.text_formatting + # Remove text wrapped in pre tags based on text formatting + if text_formatting == 'textile' + content = content.gsub(%r{
(.*?)
}m, '') + elsif text_formatting == 'markdown' || text_formatting == 'common_mark' + content = content.gsub(%r{(~~~|```)(.*?)(~~~|```)}m, '') + end + + users = content.scan(MentionPattern).flatten + end + + MentionPattern = / + (?:^|\W) # beginning of string or non-word char + @((?>[a-z0-9][a-z0-9-]*)) # @username + (?!\/) # without a trailing slash + (?= + \.+[ \t\W]| # dots followed by space or non-word character + \.+$| # dots at end of line + [^0-9a-zA-Z_.]| # non-word character except dot + $ # end of line + ) + /ix + end + end + end +end diff --git a/lib/redmine/preparation.rb b/lib/redmine/preparation.rb index 4c6b3afe6..a94a3c2cb 100644 --- a/lib/redmine/preparation.rb +++ b/lib/redmine/preparation.rb @@ -21,6 +21,7 @@ module Redmine module Preparation def self.prepare ActiveRecord::Base.include Redmine::Acts::Positioned + ActiveRecord::Base.include Redmine::Acts::Mentionable ActiveRecord::Base.include Redmine::I18n Scm::Base.add "Subversion" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a2707e435..c2db0485b 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1193,6 +1193,23 @@ function inlineAutoComplete(element) { noMatchTemplate: function () { return ''; } + }, + { + trigger: '@', + lookup: function (user, mentionText) { + return user.name + user.firstname + user.lastname + user.login; + }, + values: function (text, cb) { + remoteSearch(getDataSource('users') + text, function (users) { + return cb(users); + }); + }, + menuItemTemplate: function (user) { + return user.original.name; + }, + selectTemplate: function (user) { + return '@' + user.original.login; + } } ] }); diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb index adda40422..03d687cc4 100644 --- a/test/functional/auto_completes_controller_test.rb +++ b/test/functional/auto_completes_controller_test.rb @@ -79,7 +79,7 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_include "Bug #13", response.body end - def test_auto_complete_with_scope_all_should_search_other_projects + def test_issues_with_scope_all_should_search_other_projects get( :issues, :params => { @@ -92,13 +92,13 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_include "Bug #13", response.body end - def test_auto_complete_without_project_should_search_all_projects + def test_issues_without_project_should_search_all_projects get(:issues, :params => {:q => '13'}) assert_response :success assert_include "Bug #13", response.body end - def test_auto_complete_without_scope_all_should_not_search_other_projects + def test_issues_without_scope_all_should_not_search_other_projects get( :issues, :params => { @@ -128,7 +128,7 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_equal 'Bug #13: Subproject issue two', issue['label'] end - def test_auto_complete_with_status_o_should_return_open_issues_only + def test_issues_with_status_o_should_return_open_issues_only get( :issues, :params => { @@ -142,7 +142,7 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_not_include "closed", response.body end - def test_auto_complete_with_status_c_should_return_closed_issues_only + def test_issues_with_status_c_should_return_closed_issues_only get( :issues, :params => { @@ -156,7 +156,7 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_not_include "Issue due today", response.body end - def test_auto_complete_with_issue_id_should_not_return_that_issue + def test_issues_with_issue_id_should_not_return_that_issue get( :issues, :params => { @@ -182,7 +182,7 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_include 'application/json', response.headers['Content-Type'] end - def test_auto_complete_without_term_should_return_last_10_issues + def test_issue_without_term_should_return_last_10_issues # There are 9 issues generated by fixtures # and we need two more to test the 10 limit %w(1..2).each do @@ -269,4 +269,47 @@ class AutoCompletesControllerTest < Redmine::ControllerTest assert_equal 10, json.count assert_equal wiki.pages[-2].id, json.first['id'].to_i end + + def test_users_should_accept_case_insensitive_term_param + get :users, :params => { + :q => 'JoHN' + } + assert_response :success + assert_include "John Smith", response.body + end + + def test_users_should_return_json + get :users, :params => { + :q => 'john' + } + assert_response :success + json = ActiveSupport::JSON.decode(response.body) + assert_kind_of Array, json + user = json.first + assert_kind_of Hash, user + assert_equal 'John', user['firstname'] + assert_equal 'Smith', user['lastname'] + assert_equal 'John Smith', user['name'] + assert_equal 'jsmith', user['login'] + end + + def test_users_with_project_and_without_term_should_return_project_users + get :users, :params => { + :project_id => 'onlinestore' + } + assert_response :success + json = ActiveSupport::JSON.decode(response.body) + assert_equal 2, json.count + assert_equal 'jsmith', json.first['login'] + assert_equal 'miscuser8', json.last['login'] + end + + def test_users_without_project_and_with_term_should_search_in_all_users + get :users, :params => { + :q => 'm' + } + assert_response :success + assert_include "Redmine Admin", response.body + assert_include "Dave Lopper", response.body + end end diff --git a/test/unit/journal_test.rb b/test/unit/journal_test.rb index 0e0177917..f9c269291 100644 --- a/test/unit/journal_test.rb +++ b/test/unit/journal_test.rb @@ -236,4 +236,12 @@ class JournalTest < ActiveSupport::TestCase assert_equal "image#{i}.png", attachment.filename end end + + def test_notified_mentions_should_not_include_users_who_cannot_view_private_notes + journal = Journal.generate!(journalized: Issue.find(2), user: User.find(1), private_notes: true, notes: 'Hello @dlopper, @jsmith and @admin.') + + # User "dlopper" has "Developer" role on project "eCookbook" + # Role "Developer" does not have the "View private notes" permission + assert_equal [1, 2], journal.notified_mentions.map(&:id) + end end diff --git a/test/unit/lib/redmine/acts/mentionable_test.rb b/test/unit/lib/redmine/acts/mentionable_test.rb new file mode 100644 index 000000000..9badcd6d2 --- /dev/null +++ b/test/unit/lib/redmine/acts/mentionable_test.rb @@ -0,0 +1,146 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2022 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 +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../../../test_helper', __FILE__) + +class Redmine::Acts::MentionableTest < ActiveSupport::TestCase + fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, + :groups_users, + :trackers, :projects_trackers, + :enabled_modules, + :issue_statuses, :issue_categories, :issue_relations, :workflows, + :enumerations, + :issues + + def test_mentioned_users_with_user_mention + issue = Issue.generate!(project_id: 1, description: '@dlopper') + + assert_equal [User.find(3)], issue.mentioned_users + end + + def test_mentioned_users_with_multiple_mentions + issue = Issue.generate!(project_id: 1, description: 'Hello @dlopper, @jsmith.') + + assert_equal [User.find(2), User.find(3)], issue.mentioned_users + end + + def test_mentioned_users_should_not_mention_same_user_multiple_times + issue = Issue.generate!(project_id: 1, description: '@dlopper @jsmith @dlopper') + + assert_equal [User.find(2), User.find(3)], issue.mentioned_users + end + + def test_mentioned_users_should_include_only_active_users + # disable dlopper account + user = User.find(3) + user.status = User::STATUS_LOCKED + user.save + + issue = Issue.generate!(project_id: 1, description: '@dlopper @jsmith') + + assert_equal [User.find(2)], issue.mentioned_users + end + + def test_mentioned_users_should_include_only_visible_users + User.current = nil + Role.non_member.update! users_visibility: 'members_of_visible_projects' + Role.anonymous.update! users_visibility: 'members_of_visible_projects' + user = User.generate! + + issue = Issue.generate!(project_id: 1, description: "@jsmith @#{user.login}") + + assert_equal [User.find(2)], issue.mentioned_users + end + + def test_mentioned_users_should_not_include_mentioned_users_in_existing_content + issue = Issue.generate!(project_id: 1, description: 'Hello @dlopper') + + assert issue.save + assert_equal [User.find(3)], issue.mentioned_users + + issue.description = 'Hello @dlopper and @jsmith' + issue.save + + assert_equal [User.find(2)], issue.mentioned_users + end + + def test_mentioned_users_should_not_include_users_wrapped_in_pre_tags_for_textile + description = <<~STR +
+      Hello @jsmith
+      
+ STR + + with_settings text_formatting: 'textile' do + issue = Issue.generate!(project_id: 1, description: description) + + assert_equal [], issue.mentioned_users + end + end + + def test_mentioned_users_should_not_include_users_wrapped_in_pre_tags_for_markdown + description = <<~STR + ``` + Hello @jsmith + ``` + STR + + with_settings text_formatting: 'markdown' do + issue = Issue.generate!(project_id: 1, description: description) + + assert_equal [], issue.mentioned_users + end + end + + def test_mentioned_users_should_not_include_users_wrapped_in_pre_tags_for_common_mark + description = <<~STR + ``` + Hello @jsmith + ``` + STR + + with_settings text_formatting: 'common_mark' do + issue = Issue.generate!(project_id: 1, description: description) + + assert_equal [], issue.mentioned_users + end + end + + def test_notified_mentions + issue = Issue.generate!(project_id: 1, description: 'Hello @dlopper, @jsmith.') + + assert_equal [User.find(2), User.find(3)], issue.notified_mentions + end + + def test_notified_mentions_should_not_include_users_who_out_of_all_email + User.find(3).update!(mail_notification: :none) + issue = Issue.generate!(project_id: 1, description: "Hello @dlopper, @jsmith.") + + assert_equal [User.find(2)], issue.notified_mentions + end + + def test_notified_mentions_should_not_include_users_who_cannot_view_the_object + user = User.find(3) + + # User dlopper does not have access to project "Private child of eCookbook" + issue = Issue.generate!(project_id: 5, description: "Hello @dlopper, @jsmith.") + + assert !issue.notified_mentions.include?(user) + end +end diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 4e75ef874..1d218a544 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -464,6 +464,19 @@ class MailerTest < ActiveSupport::TestCase assert_not_include user.mail, recipients end + def test_issue_add_should_notify_mentioned_users_in_issue_description + User.find(1).mail_notification = 'only_my_events' + + issue = Issue.generate!(project_id: 1, description: 'Hello @dlopper and @admin.') + + assert Mailer.deliver_issue_add(issue) + # @jsmith and @dlopper are members of the project + # admin is mentioned + # @dlopper won't receive duplicated notifications + assert_equal 3, ActionMailer::Base.deliveries.size + assert_include User.find(1).mail, recipients + end + def test_issue_add_should_include_enabled_fields issue = Issue.find(2) assert Mailer.deliver_issue_add(issue) @@ -608,6 +621,39 @@ class MailerTest < ActiveSupport::TestCase end end + def test_issue_edit_should_notify_mentioned_users_in_issue_updated_description + User.find(1).mail_notification = 'only_my_events' + + issue = Issue.find(3) + issue.init_journal(User.current) + issue.update(description: "Hello @admin") + journal = issue.journals.last + + ActionMailer::Base.deliveries.clear + Mailer.deliver_issue_edit(journal) + + # @jsmith and @dlopper are members of the project + # admin is mentioned in the updated description + # @dlopper won't receive duplicated notifications + assert_equal 3, ActionMailer::Base.deliveries.size + assert_include User.find(1).mail, recipients + end + + def test_issue_edit_should_notify_mentioned_users_in_notes + User.find(1).mail_notification = 'only_my_events' + + journal = Journal.generate!(journalized: Issue.find(3), user: User.find(1), notes: 'Hello @admin.') + + ActionMailer::Base.deliveries.clear + Mailer.deliver_issue_edit(journal) + + # @jsmith and @dlopper are members of the project + # admin is mentioned in the notes + # @dlopper won't receive duplicated notifications + assert_equal 3, ActionMailer::Base.deliveries.size + assert_include User.find(1).mail, recipients + end + def test_issue_should_send_email_notification_with_suppress_empty_fields ActionMailer::Base.deliveries.clear with_settings :notified_events => %w(issue_added) do @@ -691,6 +737,20 @@ class MailerTest < ActiveSupport::TestCase end end + def test_news_added_should_notify_mentioned_users_in_news_description + news = News.new(title: 'Test news', description: 'Hello @admin.', author: User.first, project_id: 1) + news.save! + + ActionMailer::Base.deliveries.clear + Mailer.deliver_news_added(news) + + # @jsmith and @dlopper are members of the project + # admin is mentioned in the notes + # @dlopper won't receive duplicated notifications + assert_equal 3, ActionMailer::Base.deliveries.size + assert_include User.find(1).mail, recipients + end + def test_wiki_content_added content = WikiContent.find(1) assert_difference 'ActionMailer::Base.deliveries.size', 2 do @@ -703,6 +763,20 @@ class MailerTest < ActiveSupport::TestCase end end + def test_wiki_content_added_should_notify_mentioned_users_in_content + content = WikiContent.new(text: 'Hello @admin.', author_id: 1, page_id: 1) + content.save! + + ActionMailer::Base.deliveries.clear + Mailer.deliver_wiki_content_added(content) + + # @jsmith and @dlopper are members of the project + # admin is mentioned in the notes + # @dlopper won't receive duplicated notifications + assert_equal 3, ActionMailer::Base.deliveries.size + assert_include User.find(1).mail, recipients + end + def test_wiki_content_updated content = WikiContent.find(1) assert Mailer.deliver_wiki_content_updated(content) @@ -713,6 +787,21 @@ class MailerTest < ActiveSupport::TestCase end end + def test_wiki_content_updated_should_notify_mentioned_users_in_updated_content + content = WikiContent.find(1) + content.update(text: 'Hello @admin.') + content.save! + + ActionMailer::Base.deliveries.clear + Mailer.deliver_wiki_content_updated(content) + + # @jsmith and @dlopper are members of the project + # admin is mentioned in the notes + # @dlopper won't receive duplicated notifications + assert_equal 3, ActionMailer::Base.deliveries.size + assert_include User.find(1).mail, recipients + end + def test_register token = Token.find(1) assert Mailer.deliver_register(token.user, token) -- 2.32.0 (Apple Git-132)