@@ -763,12 +763,17 class Project < ActiveRecord::Base | |||||
763 | end |
|
763 | end | |
764 |
|
764 | |||
765 | # Copies issues from +project+ |
|
765 | # Copies issues from +project+ | |
766 | # Note: issues assigned to a closed version won't be copied due to validation rules |
|
|||
767 | def copy_issues(project) |
|
766 | def copy_issues(project) | |
768 | # Stores the source issue id as a key and the copied issues as the |
|
767 | # Stores the source issue id as a key and the copied issues as the | |
769 | # value. Used to map the two togeather for issue relations. |
|
768 | # value. Used to map the two togeather for issue relations. | |
770 | issues_map = {} |
|
769 | issues_map = {} | |
771 |
|
770 | |||
|
771 | # Store status and reopen locked/closed versions | |||
|
772 | version_statuses = versions.reject(&:open?).map {|version| [version, version.status]} | |||
|
773 | version_statuses.each do |version, status| | |||
|
774 | version.update_attribute :status, 'open' | |||
|
775 | end | |||
|
776 | ||||
772 | # Get issues sorted by root_id, lft so that parent issues |
|
777 | # Get issues sorted by root_id, lft so that parent issues | |
773 | # get copied before their children |
|
778 | # get copied before their children | |
774 | project.issues.find(:all, :order => 'root_id, lft').each do |issue| |
|
779 | project.issues.find(:all, :order => 'root_id, lft').each do |issue| | |
@@ -798,6 +803,11 class Project < ActiveRecord::Base | |||||
798 | end |
|
803 | end | |
799 | end |
|
804 | end | |
800 |
|
805 | |||
|
806 | # Restore locked/closed version statuses | |||
|
807 | version_statuses.each do |version, status| | |||
|
808 | version.update_attribute :status, status | |||
|
809 | end | |||
|
810 | ||||
801 | # Relations after in case issues related each other |
|
811 | # Relations after in case issues related each other | |
802 | project.issues.each do |issue| |
|
812 | project.issues.each do |issue| | |
803 | new_issue = issues_map[issue.id] |
|
813 | new_issue = issues_map[issue.id] |
@@ -823,6 +823,27 class ProjectTest < ActiveSupport::TestCase | |||||
823 | assert_equal "Closed", copied_issue.status.name |
|
823 | assert_equal "Closed", copied_issue.status.name | |
824 | end |
|
824 | end | |
825 |
|
825 | |||
|
826 | should "copy issues assigned to a locked version" do | |||
|
827 | User.current = User.find(1) | |||
|
828 | assigned_version = Version.generate!(:name => "Assigned Issues") | |||
|
829 | @source_project.versions << assigned_version | |||
|
830 | Issue.generate_for_project!(@source_project, | |||
|
831 | :fixed_version_id => assigned_version.id, | |||
|
832 | :subject => "copy issues assigned to a locked version", | |||
|
833 | :tracker_id => 1, | |||
|
834 | :project_id => @source_project.id) | |||
|
835 | assigned_version.update_attribute :status, 'locked' | |||
|
836 | ||||
|
837 | assert @project.copy(@source_project) | |||
|
838 | @project.reload | |||
|
839 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issues assigned to a locked version"}) | |||
|
840 | ||||
|
841 | assert copied_issue | |||
|
842 | assert copied_issue.fixed_version | |||
|
843 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name | |||
|
844 | assert_equal 'locked', copied_issue.fixed_version.status | |||
|
845 | end | |||
|
846 | ||||
826 | should "change the new issues to use the copied version" do |
|
847 | should "change the new issues to use the copied version" do | |
827 | User.current = User.find(1) |
|
848 | User.current = User.find(1) | |
828 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') |
|
849 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') |
General Comments 0
You need to be logged in to leave comments.
Login now