##// END OF EJS Templates
Deprecated Issue#move_to_project....
Jean-Philippe Lang -
r8419:165373575883
parent child
Show More
@@ -241,7 +241,7 class IssuesController < ApplicationController
241 241 @issues.each do |issue|
242 242 issue.reload
243 243 if @copy
244 issue = Issue.new.copy_from(issue)
244 issue = issue.copy
245 245 end
246 246 journal = issue.init_journal(User.current, params[:notes])
247 247 issue.safe_attributes = attributes
@@ -136,11 +136,20 class Issue < ActiveRecord::Base
136 136 self
137 137 end
138 138
139 # Returns an unsaved copy of the issue
140 def copy(attributes=nil)
141 copy = self.class.new.copy_from(self)
142 copy.attributes = attributes if attributes
143 copy
144 end
145
139 146 # Moves/copies an issue to a new project and tracker
140 147 # Returns the moved/copied issue on success, false on failure
141 148 def move_to_project(new_project, new_tracker=nil, options={})
149 ActiveSupport::Deprecation.warn "Issue#move_to_project is deprecated, use #project= instead."
150
142 151 if options[:copy]
143 issue = self.class.new.copy_from(self)
152 issue = self.copy
144 153 else
145 154 issue = self
146 155 end
@@ -139,7 +139,9 class IssueNestedSetTest < ActiveSupport::TestCase
139 139 child = create_issue!(:parent_issue_id => parent1.id)
140 140 grandchild = create_issue!(:parent_issue_id => child.id)
141 141
142 assert child.reload.move_to_project(Project.find(2))
142 child.reload
143 child.project = Project.find(2)
144 assert child.save
143 145 child.reload
144 146 grandchild.reload
145 147 parent1.reload
@@ -159,7 +161,9 class IssueNestedSetTest < ActiveSupport::TestCase
159 161 assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
160 162
161 163 # child can not be moved to Project 2 because its child is on a disabled tracker
162 assert_equal false, Issue.find(child.id).move_to_project(Project.find(2))
164 child = Issue.find(child.id)
165 child.project = Project.find(2)
166 assert !child.save
163 167 child.reload
164 168 grandchild.reload
165 169 parent1.reload
@@ -522,7 +522,8 class IssueTest < ActiveSupport::TestCase
522 522
523 523 def test_move_to_another_project_with_same_category
524 524 issue = Issue.find(1)
525 assert issue.move_to_project(Project.find(2))
525 issue.project = Project.find(2)
526 assert issue.save
526 527 issue.reload
527 528 assert_equal 2, issue.project_id
528 529 # Category changes
@@ -533,7 +534,8 class IssueTest < ActiveSupport::TestCase
533 534
534 535 def test_move_to_another_project_without_same_category
535 536 issue = Issue.find(2)
536 assert issue.move_to_project(Project.find(2))
537 issue.project = Project.find(2)
538 assert issue.save
537 539 issue.reload
538 540 assert_equal 2, issue.project_id
539 541 # Category cleared
@@ -543,7 +545,8 class IssueTest < ActiveSupport::TestCase
543 545 def test_move_to_another_project_should_clear_fixed_version_when_not_shared
544 546 issue = Issue.find(1)
545 547 issue.update_attribute(:fixed_version_id, 1)
546 assert issue.move_to_project(Project.find(2))
548 issue.project = Project.find(2)
549 assert issue.save
547 550 issue.reload
548 551 assert_equal 2, issue.project_id
549 552 # Cleared fixed_version
@@ -553,7 +556,8 class IssueTest < ActiveSupport::TestCase
553 556 def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project
554 557 issue = Issue.find(1)
555 558 issue.update_attribute(:fixed_version_id, 4)
556 assert issue.move_to_project(Project.find(5))
559 issue.project = Project.find(5)
560 assert issue.save
557 561 issue.reload
558 562 assert_equal 5, issue.project_id
559 563 # Keep fixed_version
@@ -563,7 +567,8 class IssueTest < ActiveSupport::TestCase
563 567 def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project
564 568 issue = Issue.find(1)
565 569 issue.update_attribute(:fixed_version_id, 1)
566 assert issue.move_to_project(Project.find(5))
570 issue.project = Project.find(5)
571 assert issue.save
567 572 issue.reload
568 573 assert_equal 5, issue.project_id
569 574 # Cleared fixed_version
@@ -573,7 +578,8 class IssueTest < ActiveSupport::TestCase
573 578 def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide
574 579 issue = Issue.find(1)
575 580 issue.update_attribute(:fixed_version_id, 7)
576 assert issue.move_to_project(Project.find(2))
581 issue.project = Project.find(2)
582 assert issue.save
577 583 issue.reload
578 584 assert_equal 2, issue.project_id
579 585 # Keep fixed_version
@@ -585,16 +591,18 class IssueTest < ActiveSupport::TestCase
585 591 target = Project.find(2)
586 592 target.tracker_ids = [3]
587 593 target.save
588 assert_equal false, issue.move_to_project(target)
594 issue.project = target
595 assert issue.save
589 596 issue.reload
590 assert_equal 1, issue.project_id
597 assert_equal 2, issue.project_id
598 assert_equal 3, issue.tracker_id
591 599 end
592 600
593 601 def test_copy_to_the_same_project
594 602 issue = Issue.find(1)
595 copy = nil
603 copy = issue.copy
596 604 assert_difference 'Issue.count' do
597 copy = issue.move_to_project(issue.project, nil, :copy => true)
605 copy.save!
598 606 end
599 607 assert_kind_of Issue, copy
600 608 assert_equal issue.project, copy.project
@@ -603,9 +611,9 class IssueTest < ActiveSupport::TestCase
603 611
604 612 def test_copy_to_another_project_and_tracker
605 613 issue = Issue.find(1)
606 copy = nil
614 copy = issue.copy(:project_id => 3, :tracker_id => 2)
607 615 assert_difference 'Issue.count' do
608 copy = issue.move_to_project(Project.find(3), Tracker.find(2), :copy => true)
616 copy.save!
609 617 end
610 618 copy.reload
611 619 assert_kind_of Issue, copy
@@ -615,66 +623,64 class IssueTest < ActiveSupport::TestCase
615 623 assert_nil copy.custom_value_for(2)
616 624 end
617 625
618 context "#move_to_project" do
619 context "as a copy" do
620 setup do
621 @issue = Issue.find(1)
622 @copy = nil
623 end
624
625 should "not create a journal" do
626 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
627 assert_equal 0, @copy.reload.journals.size
628 end
629
630 should "allow assigned_to changes" do
631 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
632 assert_equal 3, @copy.assigned_to_id
633 end
634
635 should "allow status changes" do
636 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}})
637 assert_equal 2, @copy.status_id
638 end
626 context "#copy" do
627 setup do
628 @issue = Issue.find(1)
629 end
639 630
640 should "allow start date changes" do
641 date = Date.today
642 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}})
643 assert_equal date, @copy.start_date
644 end
631 should "not create a journal" do
632 copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
633 copy.save!
634 assert_equal 0, copy.reload.journals.size
635 end
645 636
646 should "allow due date changes" do
647 date = Date.today
648 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}})
637 should "allow assigned_to changes" do
638 copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
639 assert_equal 3, copy.assigned_to_id
640 end
649 641
650 assert_equal date, @copy.due_date
651 end
642 should "allow status changes" do
643 copy = @issue.copy(:project_id => 3, :tracker_id => 2, :status_id => 2)
644 assert_equal 2, copy.status_id
645 end
652 646
653 should "set current user as author" do
654 User.current = User.find(9)
655 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {}})
647 should "allow start date changes" do
648 date = Date.today
649 copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date)
650 assert_equal date, copy.start_date
651 end
656 652
657 assert_equal User.current, @copy.author
658 end
653 should "allow due date changes" do
654 date = Date.today
655 copy = @issue.copy(:project_id => 3, :tracker_id => 2, :due_date => date)
656 assert_equal date, copy.due_date
657 end
659 658
660 should "create a journal with notes" do
661 date = Date.today
662 notes = "Notes added when copying"
663 @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :notes => notes, :attributes => {:start_date => date}})
659 should "set current user as author" do
660 User.current = User.find(9)
661 copy = @issue.copy(:project_id => 3, :tracker_id => 2)
662 assert_equal User.current, copy.author
663 end
664 664
665 assert_equal 1, @copy.journals.size
666 journal = @copy.journals.first
667 assert_equal 0, journal.details.size
668 assert_equal notes, journal.notes
669 end
665 should "create a journal with notes" do
666 date = Date.today
667 notes = "Notes added when copying"
668 copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date)
669 copy.init_journal(User.current, notes)
670 copy.save!
671
672 assert_equal 1, copy.journals.size
673 journal = copy.journals.first
674 assert_equal 0, journal.details.size
675 assert_equal notes, journal.notes
670 676 end
671 677 end
672 678
673 679 def test_recipients_should_not_include_users_that_cannot_view_the_issue
674 680 issue = Issue.find(12)
675 681 assert issue.recipients.include?(issue.author.mail)
676 # move the issue to a private project
677 copy = issue.move_to_project(Project.find(5), Tracker.find(2), :copy => true)
682 # copy the issue to a private project
683 copy = issue.copy(:project_id => 5, :tracker_id => 2)
678 684 # author is not a member of project anymore
679 685 assert !copy.recipients.include?(copy.author.mail)
680 686 end
General Comments 0
You need to be logged in to leave comments. Login now