From 6dbdd4ba7ab71a70e7ba87b3eefe035a69d8d001 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 21 Jan 2014 13:39:34 +0100 Subject: [PATCH 1/4] Adds specs --- .../work_packages/moves_controller_spec.rb | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/spec/controllers/work_packages/moves_controller_spec.rb b/spec/controllers/work_packages/moves_controller_spec.rb index 3de231e83e..882698e6af 100644 --- a/spec/controllers/work_packages/moves_controller_spec.rb +++ b/spec/controllers/work_packages/moves_controller_spec.rb @@ -219,22 +219,40 @@ describe WorkPackages::MovesController do end end - context "with given note" do - let(:note) { "Moving two work packages" } + shared_examples_for 'single note for moved work package' do + it { expect(moved_work_package.journals.count).to eq(2) } - before do - post :create, - :ids => [work_package.id, work_package_2.id], - :notes => note + it { expect(moved_work_package.journals.sort_by(&:id).last.notes).to eq(note) } + end - work_package.reload - work_package_2.reload + describe "move with given note" do + let(:note) { "Moving a work package" } + + context "w/o work package changes" do + before do + post :create, + ids: [work_package.id], + notes: note + end + + it_behaves_like 'single note for moved work package' do + let(:moved_work_package) { work_package.reload } + end end - it "adds note to work packages" do - work_package.journals.sort_by(&:id).last.notes.should eq(note) - work_package_2.journals.sort_by(&:id).last.notes.should eq(note) + context "w/o work package changes" do + before do + post :create, + ids: [work_package.id], + notes: note, + priority_id: target_priority.id + end + + it_behaves_like 'single note for moved work package' do + let(:moved_work_package) { work_package.reload } + end end + end describe '©' do @@ -330,6 +348,23 @@ describe WorkPackages::MovesController do end end end + + context "with given note" do + let(:note) { "Copying a work package" } + + before do + post :create, + ids: [work_package.id], + copy: '', + notes: note + end + + subject { WorkPackage.all(limit: 1, order: 'id desc').last.journals } + + it { expect(subject.count).to eq(2) } + + it { expect(subject.sort_by(&:id).last.notes).to eq(note) } + end end end end From 24ad6d03afc536e62b5142e5f1273f7e78ecc736 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 21 Jan 2014 13:44:58 +0100 Subject: [PATCH 2/4] Fixes duplicated journal notes on move --- app/controllers/work_packages/moves_controller.rb | 6 +++--- app/models/work_package.rb | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/work_packages/moves_controller.rb b/app/controllers/work_packages/moves_controller.rb index 506a0612b0..b1cc22832f 100644 --- a/app/controllers/work_packages/moves_controller.rb +++ b/app/controllers/work_packages/moves_controller.rb @@ -46,8 +46,6 @@ class WorkPackages::MovesController < ApplicationController @work_packages.each do |work_package| work_package.reload - JournalManager.add_journal work_package, User.current, @notes || "" - call_hook(:controller_work_packages_move_before_save, { :params => params, :work_package => work_package, :target_project => @target_project, :copy => !!@copy }) permitted_params = params.permit(:copy, @@ -62,7 +60,9 @@ class WorkPackages::MovesController < ApplicationController ids:[], status_id:[]) - if r = work_package.move_to_project(@target_project, new_type, {:copy => @copy, :attributes => permitted_params}) + if r = work_package.move_to_project(@target_project, new_type, { copy: @copy, + attributes: permitted_params, + journal_note: @notes }) moved_work_packages << r else unsaved_work_package_ids << work_package.id diff --git a/app/models/work_package.rb b/app/models/work_package.rb index a6293bd7a3..ec2c2c2d7c 100644 --- a/app/models/work_package.rb +++ b/app/models/work_package.rb @@ -664,6 +664,8 @@ class WorkPackage < ActiveRecord::Base else self.status end + else + work_package.add_journal User.current, options[:journal_note] if options[:journal_note] end if work_package.save From cecb5ad88724695e4c50e4590b3d956d731c17cb Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 21 Jan 2014 13:45:39 +0100 Subject: [PATCH 3/4] Fixes missing journal notes on copy --- app/models/work_package.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/work_package.rb b/app/models/work_package.rb index ec2c2c2d7c..10a42114fe 100644 --- a/app/models/work_package.rb +++ b/app/models/work_package.rb @@ -669,7 +669,9 @@ class WorkPackage < ActiveRecord::Base end if work_package.save - unless options[:copy] + if options[:copy] + create_and_save_journal_note work_package, options[:journal_note] + else # Manually update project_id on related time entries TimeEntry.update_all("project_id = #{new_project.id}", {:work_package_id => id}) @@ -1009,4 +1011,11 @@ class WorkPackage < ActiveRecord::Base errors.messages[:attachments].first << " - #{invalid_attachment.errors.full_messages.first}" end end + + def create_and_save_journal_note(work_package, journal_note) + if work_package && journal_note + work_package.add_journal User.current, journal_note + work_package.save! + end + end end From e1e97b8bca6f2a3af179784291ec51606ea4be65 Mon Sep 17 00:00:00 2001 From: Johannes Wollert Date: Wed, 22 Jan 2014 15:45:23 +0100 Subject: [PATCH 4/4] Adds changelog entry Conflicts: doc/CHANGELOG.md --- doc/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 910087ce63..e3e2038855 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -44,12 +44,14 @@ See doc/COPYRIGHT.rdoc for more details. * `#3120` Implement a test suite the spikes can be developed against * `#3251` [Timelines] Filtering for Responsible filters everything * `#3393` [Timelines] Filter Work Packages by Assignee +* `#3401` [Work package tracking] Notes are not saved when copying a work package * `#3409` New Layout for fallback Login page * `#3453` Highlight project in bread crumb * `#3546` Better icon for Timelines Module * `#3547` Change color of Apply button in Activity * `#3667` Better icon for Roadmap * `#3065` Fixed internal error when selecting costs-columns and displaying sums in work package list +* `#3863` Strange additional journal entry when moving work package ## 3.0.0pre42