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

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

index 652efd7c40d8059d6dae3e311ef32e5784f25bb0..fef2beb8b062ab716fe848e1c20711d5c397c7e9 100644 (file)
@@ -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 dd4b60d5022b7d3216745d4adbebed281dd349e1..7752cd386987c0677eb2774e1fc2d4e40f344881 100644 (file)
@@ -832,6 +832,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)