Feature #33002 » 33002-include-attachments-in-news-added-notifications.patch
| app/views/mailer/news_added.html.erb | ||
|---|---|---|
| 2 | 2 |
<em><%= @news.author.name %></em> |
| 3 | 3 | |
| 4 | 4 |
<%= textilizable(@news, :description, :only_path => false) %> |
| 5 | ||
| 6 |
<% if @news.attachments.any? -%> |
|
| 7 |
<fieldset class="attachments"><legend><%= l(:label_attachment_plural) %></legend> |
|
| 8 |
<% @news.attachments.each do |attachment| -%> |
|
| 9 |
<%= link_to_attachment attachment, :download => true, :only_path => false %> (<%= number_to_human_size(attachment.filesize) %>)<br /> |
|
| 10 |
<% end -%> |
|
| 11 |
</fieldset> |
|
| 12 |
<% end -%> |
|
| app/views/mailer/news_added.text.erb | ||
|---|---|---|
| 3 | 3 |
<%= @news.author.name %> |
| 4 | 4 | |
| 5 | 5 |
<%= @news.description %> |
| 6 | ||
| 7 |
<% if @news.attachments.any? -%> |
|
| 8 |
---<%= l(:label_attachment_plural).ljust(37, '-') %> |
|
| 9 |
<% @news.attachments.each do |attachment| -%> |
|
| 10 |
<%= attachment.filename %> (<%= number_to_human_size(attachment.filesize) %>) |
|
| 11 |
<% end -%> |
|
| 12 |
<% end -%> |
|
| test/functional/news_controller_test.rb | ||
|---|---|---|
| 123 | 123 | |
| 124 | 124 |
def test_post_create_with_attachment |
| 125 | 125 |
set_tmp_attachments_directory |
| 126 |
ActionMailer::Base.deliveries.clear |
|
| 126 | 127 |
@request.session[:user_id] = 2 |
| 127 | 128 |
assert_difference 'News.count' do |
| 128 | 129 |
assert_difference 'Attachment.count' do |
| 129 |
post( |
|
| 130 |
:create, |
|
| 131 |
:params => {
|
|
| 132 |
:project_id => 1, |
|
| 133 |
:news => {
|
|
| 134 |
:title => 'Test', |
|
| 135 |
:description => 'This is the description' |
|
| 136 |
}, |
|
| 137 |
:attachments => {
|
|
| 138 |
'1' => {
|
|
| 139 |
'file' => uploaded_test_file('testfile.txt', 'text/plain')
|
|
| 130 |
with_settings :notified_events => %w(news_added) do |
|
| 131 |
post( |
|
| 132 |
:create, |
|
| 133 |
:params => {
|
|
| 134 |
:project_id => 1, |
|
| 135 |
:news => {
|
|
| 136 |
:title => 'Test', |
|
| 137 |
:description => 'This is the description' |
|
| 138 |
}, |
|
| 139 |
:attachments => {
|
|
| 140 |
'1' => {
|
|
| 141 |
'file' => uploaded_test_file('testfile.txt', 'text/plain')
|
|
| 142 |
} |
|
| 140 | 143 |
} |
| 141 | 144 |
} |
| 142 |
}
|
|
| 143 |
)
|
|
| 145 |
)
|
|
| 146 |
end
|
|
| 144 | 147 |
end |
| 145 | 148 |
end |
| 146 | 149 |
attachment = Attachment.order('id DESC').first
|
| 147 | 150 |
news = News.order('id DESC').first
|
| 148 | 151 |
assert_equal news, attachment.container |
| 152 |
assert_select_email do |
|
| 153 |
# link to the attachments download |
|
| 154 |
assert_select 'fieldset.attachments' do |
|
| 155 |
assert_select 'a[href=?]', |
|
| 156 |
"http://localhost:3000/attachments/download/#{attachment.id}/testfile.txt",
|
|
| 157 |
:text => 'testfile.txt' |
|
| 158 |
end |
|
| 159 |
end |
|
| 149 | 160 |
end |
| 150 | 161 | |
| 151 | 162 |
def test_post_create_with_validation_failure |
| test/unit/mailer_test.rb | ||
|---|---|---|
| 613 | 613 |
end |
| 614 | 614 | |
| 615 | 615 |
def test_news_added_should_notify_project_news_watchers |
| 616 |
set_tmp_attachments_directory |
|
| 616 | 617 |
user1 = User.generate! |
| 617 | 618 |
user2 = User.generate! |
| 618 | 619 |
news = News.find(1) |
| 619 | 620 |
news.project.enabled_module('news').add_watcher(user1)
|
| 621 |
attachment = Attachment.generate!( |
|
| 622 |
:container => news, |
|
| 623 |
:file => uploaded_test_file('testfile.txt', 'text/plain')
|
|
| 624 |
) |
|
| 620 | 625 | |
| 621 | 626 |
Mailer.deliver_news_added(news) |
| 622 | 627 |
assert_include user1.mail, recipients |
| 623 | 628 |
assert_not_include user2.mail, recipients |
| 629 |
assert_select_email do |
|
| 630 |
# link to the attachments download |
|
| 631 |
assert_select 'fieldset.attachments' do |
|
| 632 |
assert_select 'a[href=?]', |
|
| 633 |
"http://localhost:3000/attachments/download/#{attachment.id}/testfile.txt",
|
|
| 634 |
:text => 'testfile.txt' |
|
| 635 |
end |
|
| 636 |
end |
|
| 624 | 637 |
end |
| 625 | 638 | |
| 626 | 639 |
def test_wiki_content_added |