diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 4356ea06..eb5799db 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -85,7 +85,7 @@ class DocumentsController < ApplicationController if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') # TODO: refactor - attachments.first.container.recipients.each do |recipient| + @document.recipients.each do |recipient| Mailer.deliver_attachments_added(attachments[:files], recipient) end end diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb index 441f5ab7..66278a0f 100644 --- a/test/functional/documents_controller_test.rb +++ b/test/functional/documents_controller_test.rb @@ -147,6 +147,28 @@ LOREM end end + context "#add_attachment" do + setup do + @request.session[:user_id] = 2 + set_tmp_attachments_directory + @document = Document.generate!(:project => Project.find('ecookbook'), + :title => 'Test') + end + + should "send a notification mail" do + ActionMailer::Base.deliveries.clear + Setting.notified_events = Setting.notified_events.dup << 'document_added' + + post :add_attachment, + :id => @document.id, + :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} + + @document.reload + assert_not_nil @document + assert_equal 2, ActionMailer::Base.deliveries.size + end + end + def test_destroy @request.session[:user_id] = 2 post :destroy, :id => 1