Feature #33002 » 33002-include-attachments-in-news-added-notifications.patch
| app/views/mailer/news_added.html.erb | ||
|---|---|---|
|
<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 -%>
|
||
| app/views/mailer/news_added.text.erb | ||
|---|---|---|
|
<%= @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 -%>
|
||
| test/functional/news_controller_test.rb | ||
|---|---|---|
|
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
|
||
| test/unit/mailer_test.rb | ||
|---|---|---|
|
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
|
||