summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2020-02-24 03:19:00 +0000
committerGo MAEDA <maeda@farend.jp>2020-02-24 03:19:00 +0000
commit6095186e975bad3a1c0a71f778a2b46b618f934d (patch)
treec2fd8d313524bd93321be7d853961f6e96d9eec6
parent3c45dfaad766f16fb082e68c8d4c8d6370b2fd47 (diff)
downloadredmine-6095186e975bad3a1c0a71f778a2b46b618f934d.tar.gz
redmine-6095186e975bad3a1c0a71f778a2b46b618f934d.zip
Include attachments in news post notifications (#33002).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@19528 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/views/mailer/news_added.html.erb8
-rw-r--r--app/views/mailer/news_added.text.erb7
-rw-r--r--test/functional/news_controller_test.rb37
-rw-r--r--test/unit/mailer_test.rb13
4 files changed, 52 insertions, 13 deletions
diff --git a/app/views/mailer/news_added.html.erb b/app/views/mailer/news_added.html.erb
index daf250adf..992321930 100644
--- a/app/views/mailer/news_added.html.erb
+++ b/app/views/mailer/news_added.html.erb
@@ -2,3 +2,11 @@
<em><%= @news.author.name %></em>
<%= textilizable(@news, :description, :only_path => false) %>
+
+<% if @news.attachments.any? -%>
+<fieldset class="attachments"><legend><%= l(:label_attachment_plural) %></legend>
+<% @news.attachments.each do |attachment| -%>
+ <%= link_to_attachment attachment, :download => true, :only_path => false %> (<%= number_to_human_size(attachment.filesize) %>)<br />
+<% end -%>
+</fieldset>
+<% end -%> \ No newline at end of file
diff --git a/app/views/mailer/news_added.text.erb b/app/views/mailer/news_added.text.erb
index c8ae3035f..65e6a404f 100644
--- a/app/views/mailer/news_added.text.erb
+++ b/app/views/mailer/news_added.text.erb
@@ -3,3 +3,10 @@
<%= @news.author.name %>
<%= @news.description %>
+
+<% if @news.attachments.any? -%>
+---<%= l(:label_attachment_plural).ljust(37, '-') %>
+<% @news.attachments.each do |attachment| -%>
+<%= attachment.filename %> (<%= number_to_human_size(attachment.filesize) %>)
+<% end -%>
+<% end -%> \ No newline at end of file
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index 93a0208d6..f3d736b8e 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -123,29 +123,40 @@ class NewsControllerTest < Redmine::ControllerTest
def test_post_create_with_attachment
set_tmp_attachments_directory
+ ActionMailer::Base.deliveries.clear
@request.session[:user_id] = 2
assert_difference 'News.count' do
assert_difference 'Attachment.count' do
- post(
- :create,
- :params => {
- :project_id => 1,
- :news => {
- :title => 'Test',
- :description => 'This is the description'
- },
- :attachments => {
- '1' => {
- 'file' => uploaded_test_file('testfile.txt', 'text/plain')
+ with_settings :notified_events => %w(news_added) do
+ post(
+ :create,
+ :params => {
+ :project_id => 1,
+ :news => {
+ :title => 'Test',
+ :description => 'This is the description'
+ },
+ :attachments => {
+ '1' => {
+ 'file' => uploaded_test_file('testfile.txt', 'text/plain')
+ }
}
}
- }
- )
+ )
+ end
end
end
attachment = Attachment.order('id DESC').first
news = News.order('id DESC').first
assert_equal news, attachment.container
+ assert_select_email do
+ # link to the attachments download
+ assert_select 'fieldset.attachments' do
+ assert_select 'a[href=?]',
+ "http://localhost:3000/attachments/download/#{attachment.id}/testfile.txt",
+ :text => 'testfile.txt'
+ end
+ end
end
def test_post_create_with_validation_failure
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index 6e7fc84a7..ace7d6ff9 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -613,14 +613,27 @@ class MailerTest < ActiveSupport::TestCase
end
def test_news_added_should_notify_project_news_watchers
+ set_tmp_attachments_directory
user1 = User.generate!
user2 = User.generate!
news = News.find(1)
news.project.enabled_module('news').add_watcher(user1)
+ attachment = Attachment.generate!(
+ :container => news,
+ :file => uploaded_test_file('testfile.txt', 'text/plain')
+ )
Mailer.deliver_news_added(news)
assert_include user1.mail, recipients
assert_not_include user2.mail, recipients
+ assert_select_email do
+ # link to the attachments download
+ assert_select 'fieldset.attachments' do
+ assert_select 'a[href=?]',
+ "http://localhost:3000/attachments/download/#{attachment.id}/testfile.txt",
+ :text => 'testfile.txt'
+ end
+ end
end
def test_wiki_content_added