Project

General

Profile

Defect #10721 » 10721-fixed.patch

Yuichi HARADA, 2020-05-26 04:20

View differences:

app/models/mail_handler.rb
209 209

  
210 210
    # add To and Cc as watchers before saving so the watchers can reply to Redmine
211 211
    add_watchers(issue)
212
    issue.save!
213 212
    add_attachments(issue)
213
    issue.save!
214 214
    logger&.info "MailHandler: issue ##{issue.id} created by #{user}"
215 215
    issue
216 216
  end
......
245 245

  
246 246
    # add To and Cc as watchers before saving so the watchers can reply to Redmine
247 247
    add_watchers(issue)
248
    issue.save!
249 248
    add_attachments(issue)
249
    issue.save!
250 250
    logger&.info "MailHandler: issue ##{issue.id} updated by #{user}"
251 251
    journal
252 252
  end
......
284 284
                          :content => cleaned_up_text_body)
285 285
      reply.author = user
286 286
      reply.board = message.board
287
      message.children << reply
288 287
      add_attachments(reply)
288
      message.children << reply
289 289
      reply
290 290
    else
291 291
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a locked topic"
......
297 297
      email.attachments.each do |attachment|
298 298
        next unless accept_attachment?(attachment)
299 299
        next unless attachment.body.decoded.size > 0
300
        obj.attachments << Attachment.create(:container => obj,
300
        obj.saved_attachments << Attachment.create(
301 301
                          :file => attachment.body.decoded,
302 302
                          :filename => attachment.filename,
303 303
                          :author => user,
test/unit/mail_handler_test.rb
906 906
  def test_update_issue_with_attachment
907 907
    assert_difference 'Journal.count' do
908 908
      assert_difference 'JournalDetail.count' do
909
        assert_difference 'Attachment.count' do
909
        assert_difference ->{Attachment.where(:container_type => 'Issue', :container_id => 2).count} do
910 910
          assert_no_difference 'Issue.count' do
911 911
            journal = submit_email('ticket_with_attachment.eml') do |raw|
912 912
              raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
......
928 928
    Issue.any_instance.stubs(:valid?).returns(false)
929 929
    assert_no_difference 'Journal.count' do
930 930
      assert_no_difference 'JournalDetail.count' do
931
        assert_no_difference 'Attachment.count' do
931
        assert_no_difference ->{Attachment.where(:container_type => 'Issue', :container_id => 2).count} do
932 932
          assert_no_difference 'Issue.count' do
933 933
            journal = submit_email('ticket_with_attachment.eml') do |raw|
934 934
              raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
(3-3/3)