]> source.dussan.org Git - redmine.git/commitdiff
Merged r17630 from trunk to 3.4-stable (#28576).
authorGo MAEDA <maeda@farend.jp>
Sat, 24 Nov 2018 11:20:00 +0000 (11:20 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 24 Nov 2018 11:20:00 +0000 (11:20 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@17631 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/unit/mail_handler_test.rb

index 9377e00d9939bcbf91d0972822f05419966ace19..aa0ea1e4599f7cf35e9c4d9d406079628c9c8a48 100755 (executable)
@@ -250,8 +250,8 @@ class MailHandler < ActionMailer::Base
 
     # add To and Cc as watchers before saving so the watchers can reply to Redmine
     add_watchers(issue)
-    add_attachments(issue)
     issue.save!
+    add_attachments(issue)
     if logger
       logger.info "MailHandler: issue ##{issue.id} updated by #{user}"
     end
index 2d02cf0ed42f07f3297ddf9d1037a89f1e3d736b..79405b5d606cff413d3e33e3a2845c0f73c3c715 100644 (file)
@@ -866,6 +866,21 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_equal 'Paella.jpg', detail.value
   end
 
+  def test_update_issue_should_discard_all_changes_on_validation_failure
+    Issue.any_instance.stubs(:valid?).returns(false)
+    assert_no_difference 'Journal.count' do
+      assert_no_difference 'JournalDetail.count' do
+        assert_no_difference 'Attachment.count' do
+          assert_no_difference 'Issue.count' do
+            journal = submit_email('ticket_with_attachment.eml') do |raw|
+              raw.gsub! /^Subject: .*$/, 'Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories'
+            end
+          end
+        end
+      end
+    end
+  end
+
   def test_update_issue_should_send_email_notification
     journal = submit_email('ticket_reply.eml')
     assert journal.is_a?(Journal)