]> source.dussan.org Git - redmine.git/commitdiff
Fix: Attachments are added even if validation fails when updating an issue via email...
authorGo MAEDA <maeda@farend.jp>
Fri, 23 Nov 2018 06:07:32 +0000 (06:07 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 23 Nov 2018 06:07:32 +0000 (06:07 +0000)
Patch by Takenori TAKAKI.

git-svn-id: http://svn.redmine.org/redmine/trunk@17630 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index bd0d81ba9aac1642efbd1401b268a0b0af93ef3d..073e0dcc01fa984422aa22609e23e53c4beddf43 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 e63ab09581360f0fe40ff1284eae6ebccfc5e5aa..5c3a570b71319816cd1aac133b4c2d425f6a86cc 100644 (file)
@@ -890,6 +890,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)