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 @@ <%= @news.author.name %> <%= textilizable(@news, :description, :only_path => false) %> + +<% if @news.attachments.any? -%> +
<%= l(:label_attachment_plural) %> +<% @news.attachments.each do |attachment| -%> + <%= link_to_attachment attachment, :download => true, :only_path => false %> (<%= number_to_human_size(attachment.filesize) %>)
+<% end -%> +
+<% 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