]> source.dussan.org Git - redmine.git/commitdiff
Save an @Issue#save@.
authorEtienne Massip <etienne.massip@gmail.com>
Wed, 14 Dec 2011 20:31:34 +0000 (20:31 +0000)
committerEtienne Massip <etienne.massip@gmail.com>
Wed, 14 Dec 2011 20:31:34 +0000 (20:31 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8212 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issue_moves_controller.rb
app/models/issue.rb
test/unit/issue_test.rb

index 06997183eb67bb6cd664c123676f5d9ddcc2a15d..234d4d72e7a05c981cd525dca834e216e74c0f55 100644 (file)
@@ -36,10 +36,8 @@ class IssueMovesController < ApplicationController
       moved_issues = []
       @issues.each do |issue|
         issue.reload
-        issue.init_journal(User.current)
-        issue.current_journal.notes = @notes if @notes.present?
         call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
-        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
+        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params), :notes => @notes})
           moved_issues << r
         else
           unsaved_issue_ids << issue.id
index 5ccd40ee9d3a7a31918127c51d31507ef298d034..dcafade151741081fe0ed08ecee906951e8b3968 100644 (file)
@@ -152,7 +152,13 @@ class Issue < ActiveRecord::Base
 
   def move_to_project_without_transaction(new_project, new_tracker = nil, options = {})
     options ||= {}
-    issue = options[:copy] ? self.class.new.copy_from(self) : self
+
+    if options[:copy]
+      issue = self.class.new.copy_from(self)
+    else
+      issue = self
+      issue.init_journal(User.current, options[:notes]) 
+    end
 
     if new_project && issue.project_id != new_project.id
       # delete issue relations
@@ -190,14 +196,12 @@ class Issue < ActiveRecord::Base
     if options[:attributes]
       issue.attributes = options[:attributes]
     end
+    if options[:copy] && options[:notes].present?
+      issue.init_journal(User.current, options[:notes])
+      issue.current_journal.notify = false
+    end
     if issue.save
-      if options[:copy]
-        if current_journal && current_journal.notes.present?
-          issue.init_journal(current_journal.user, current_journal.notes)
-          issue.current_journal.notify = false
-          issue.save
-        end
-      else
+      unless options[:copy]
         # Manually update project_id on related time entries
         TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
 
index f973d32ceae49d8ff9ea7f02a79139017323360d..524fb45b169252352221c06cd1a9b5eec2ef1946 100644 (file)
@@ -634,12 +634,10 @@ class IssueTest < ActiveSupport::TestCase
         assert_equal User.current, @copy.author
       end
 
-      should "keep journal notes" do
+      should "create a journal with notes" do
         date = Date.today
         notes = "Notes added when copying"
-        User.current = User.find(9)
-        @issue.init_journal(User.current, notes)
-        @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}})
+        @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :notes => notes, :attributes => {:start_date => date}})
 
         assert_equal 1, @copy.journals.size
         journal = @copy.journals.first