##// END OF EJS Templates
Fixed: MailHandler does not include JournalDetail for attached files (#7966)....
Jean-Philippe Lang -
r6192:49900051ea2b
parent child
Show More
@@ -149,7 +149,8 class Attachment < ActiveRecord::Base
149 149 :file => file,
150 150 :description => attachment['description'].to_s.strip,
151 151 :author => User.current)
152
152 obj.attachments << a
153
153 154 if a.new_record?
154 155 obj.unsaved_attachments ||= []
155 156 obj.unsaved_attachments << a
@@ -35,7 +35,7 class Issue < ActiveRecord::Base
35 35 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
36 36
37 37 acts_as_nested_set :scope => 'root_id', :dependent => :destroy
38 acts_as_attachable :after_remove => :attachment_removed
38 acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
39 39 acts_as_customizable
40 40 acts_as_watchable
41 41 acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
@@ -612,8 +612,6 class Issue < ActiveRecord::Base
612 612
613 613 if valid?
614 614 attachments = Attachment.attach_files(self, params[:attachments])
615
616 attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
617 615 # TODO: Rename hook
618 616 Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
619 617 begin
@@ -842,6 +840,13 class Issue < ActiveRecord::Base
842 840 end
843 841 end
844 842 end
843
844 # Callback on attachment deletion
845 def attachment_added(obj)
846 if @current_journal && !obj.new_record?
847 @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :value => obj.filename)
848 end
849 end
845 850
846 851 # Callback on attachment deletion
847 852 def attachment_removed(obj)
@@ -200,7 +200,7 class MailHandler < ActionMailer::Base
200 200 def add_attachments(obj)
201 201 if email.has_attachments?
202 202 email.attachments.each do |attachment|
203 Attachment.create(:container => obj,
203 obj.attachments << Attachment.create(:container => obj,
204 204 :file => attachment,
205 205 :author => user,
206 206 :content_type => attachment.content_type)
@@ -307,7 +307,7 class MailHandlerTest < ActiveSupport::TestCase
307 307 assert_equal 1, ActionMailer::Base.deliveries.size
308 308 end
309 309
310 def test_add_issue_note
310 def test_update_issue
311 311 journal = submit_email('ticket_reply.eml')
312 312 assert journal.is_a?(Journal)
313 313 assert_equal User.find_by_login('jsmith'), journal.user
@@ -316,7 +316,7 class MailHandlerTest < ActiveSupport::TestCase
316 316 assert_equal 'Feature request', journal.issue.tracker.name
317 317 end
318 318
319 def test_add_issue_note_with_attribute_changes
319 def test_update_issue_with_attribute_changes
320 320 # This email contains: 'Status: Resolved'
321 321 journal = submit_email('ticket_reply_with_status.eml')
322 322 assert journal.is_a?(Journal)
@@ -334,15 +334,36 class MailHandlerTest < ActiveSupport::TestCase
334 334 assert !journal.notes.match(/^Status:/i)
335 335 assert !journal.notes.match(/^Start Date:/i)
336 336 end
337
338 def test_update_issue_with_attachment
339 assert_difference 'Journal.count' do
340 assert_difference 'JournalDetail.count' do
341 assert_difference 'Attachment.count' do
342 assert_no_difference 'Issue.count' do
343 journal = submit_email('ticket_with_attachment.eml') do |raw|
344 raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
345 end
346 end
347 end
348 end
349 end
350 journal = Journal.first(:order => 'id DESC')
351 assert_equal Issue.find(2), journal.journalized
352 assert_equal 1, journal.details.size
353
354 detail = journal.details.first
355 assert_equal 'attachment', detail.property
356 assert_equal 'Paella.jpg', detail.value
357 end
337 358
338 def test_add_issue_note_should_send_email_notification
359 def test_update_issue_should_send_email_notification
339 360 ActionMailer::Base.deliveries.clear
340 361 journal = submit_email('ticket_reply.eml')
341 362 assert journal.is_a?(Journal)
342 363 assert_equal 1, ActionMailer::Base.deliveries.size
343 364 end
344 365
345 def test_add_issue_note_should_not_set_defaults
366 def test_update_issue_should_not_set_defaults
346 367 journal = submit_email('ticket_reply.eml', :issue => {:tracker => 'Support request', :priority => 'High'})
347 368 assert journal.is_a?(Journal)
348 369 assert_match /This is reply/, journal.notes
General Comments 0
You need to be logged in to leave comments. Login now