@@ -225,7 +225,11 class IssuesController < ApplicationController | |||||
225 | end |
|
225 | end | |
226 | target_projects ||= @projects |
|
226 | target_projects ||= @projects | |
227 |
|
227 | |||
|
228 | if @copy | |||
|
229 | @available_statuses = [IssueStatus.default] | |||
|
230 | else | |||
228 | @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) |
|
231 | @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) | |
|
232 | end | |||
229 | @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) |
|
233 | @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) | |
230 | @assignables = target_projects.map(&:assignable_users).reduce(:&) |
|
234 | @assignables = target_projects.map(&:assignable_users).reduce(:&) | |
231 | @trackers = target_projects.map(&:trackers).reduce(:&) |
|
235 | @trackers = target_projects.map(&:trackers).reduce(:&) |
@@ -511,6 +511,9 class Issue < ActiveRecord::Base | |||||
511 |
|
511 | |||
512 | # Returns an array of statuses that user is able to apply |
|
512 | # Returns an array of statuses that user is able to apply | |
513 | def new_statuses_allowed_to(user=User.current, include_default=false) |
|
513 | def new_statuses_allowed_to(user=User.current, include_default=false) | |
|
514 | if new_record? && @copied_from | |||
|
515 | [IssueStatus.default, @copied_from.status].compact.uniq.sort | |||
|
516 | else | |||
514 | initial_status = nil |
|
517 | initial_status = nil | |
515 | if new_record? |
|
518 | if new_record? | |
516 | initial_status = IssueStatus.default |
|
519 | initial_status = IssueStatus.default | |
@@ -530,6 +533,7 class Issue < ActiveRecord::Base | |||||
530 | statuses = statuses.compact.uniq.sort |
|
533 | statuses = statuses.compact.uniq.sort | |
531 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses |
|
534 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses | |
532 | end |
|
535 | end | |
|
536 | end | |||
533 |
|
537 | |||
534 | def assigned_to_was |
|
538 | def assigned_to_was | |
535 | if assigned_to_id_changed? && assigned_to_id_was.present? |
|
539 | if assigned_to_id_changed? && assigned_to_id_was.present? |
@@ -3065,24 +3065,38 class IssuesControllerTest < ActionController::TestCase | |||||
3065 | end |
|
3065 | end | |
3066 | end |
|
3066 | end | |
3067 | assert_redirected_to '/projects/ecookbook/issues' |
|
3067 | assert_redirected_to '/projects/ecookbook/issues' | |
|
3068 | ||||
|
3069 | copies = Issue.all(:order => 'id DESC', :limit => issues.size) | |||
|
3070 | copies.each do |copy| | |||
|
3071 | assert_equal 2, copy.project_id | |||
|
3072 | end | |||
3068 | end |
|
3073 | end | |
3069 |
|
3074 | |||
3070 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes |
|
3075 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes | |
3071 | @request.session[:user_id] = 2 |
|
3076 | @request.session[:user_id] = 2 | |
3072 | issue_before_move = Issue.find(1) |
|
3077 | issues = [ | |
3073 | assert_difference 'Issue.count', 1 do |
|
3078 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil), | |
3074 | assert_no_difference 'Project.find(1).issues.count' do |
|
3079 | Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3) | |
3075 | post :bulk_update, :ids => [1], :copy => '1', |
|
3080 | ] | |
|
3081 | ||||
|
3082 | assert_difference 'Issue.count', issues.size do | |||
|
3083 | post :bulk_update, :ids => issues.map(&:id), :copy => '1', | |||
3076 |
|
|
3084 | :issue => { | |
3077 |
|
|
3085 | :project_id => '', :tracker_id => '', :assigned_to_id => '', | |
3078 |
|
|
3086 | :status_id => '', :start_date => '', :due_date => '' | |
3079 |
|
|
3087 | } | |
3080 |
|
|
3088 | end | |
|
3089 | ||||
|
3090 | copies = Issue.all(:order => 'id DESC', :limit => issues.size) | |||
|
3091 | issues.each do |orig| | |||
|
3092 | copy = copies.detect {|c| c.subject == orig.subject} | |||
|
3093 | assert_not_nil copy | |||
|
3094 | assert_equal orig.project_id, copy.project_id | |||
|
3095 | assert_equal orig.tracker_id, copy.tracker_id | |||
|
3096 | assert_equal orig.status_id, copy.status_id | |||
|
3097 | assert_equal orig.assigned_to_id, copy.assigned_to_id | |||
|
3098 | assert_equal orig.priority_id, copy.priority_id | |||
3081 | end |
|
3099 | end | |
3082 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) |
|
|||
3083 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id |
|
|||
3084 | assert_equal issue_before_move.status_id, issue_after_move.status_id |
|
|||
3085 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id |
|
|||
3086 | end |
|
3100 | end | |
3087 |
|
3101 | |||
3088 | def test_bulk_copy_should_allow_changing_the_issue_attributes |
|
3102 | def test_bulk_copy_should_allow_changing_the_issue_attributes | |
@@ -3097,7 +3111,7 class IssuesControllerTest < ActionController::TestCase | |||||
3097 | post :bulk_update, :ids => [1, 2], :copy => '1', |
|
3111 | post :bulk_update, :ids => [1, 2], :copy => '1', | |
3098 | :issue => { |
|
3112 | :issue => { | |
3099 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', |
|
3113 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', | |
3100 |
:status_id => ' |
|
3114 | :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' | |
3101 | } |
|
3115 | } | |
3102 | end |
|
3116 | end | |
3103 | end |
|
3117 | end | |
@@ -3107,7 +3121,7 class IssuesControllerTest < ActionController::TestCase | |||||
3107 | copied_issues.each do |issue| |
|
3121 | copied_issues.each do |issue| | |
3108 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
3122 | assert_equal 2, issue.project_id, "Project is incorrect" | |
3109 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
3123 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" | |
3110 |
assert_equal |
|
3124 | assert_equal 1, issue.status_id, "Status is incorrect" | |
3111 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
3125 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" | |
3112 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
3126 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" | |
3113 | end |
|
3127 | end |
@@ -395,6 +395,14 class IssueTest < ActiveSupport::TestCase | |||||
395 | assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) |
|
395 | assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) | |
396 | end |
|
396 | end | |
397 |
|
397 | |||
|
398 | def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying | |||
|
399 | issue = Issue.find(1).copy | |||
|
400 | assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id) | |||
|
401 | ||||
|
402 | issue = Issue.find(2).copy | |||
|
403 | assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id) | |||
|
404 | end | |||
|
405 | ||||
398 | def test_copy |
|
406 | def test_copy | |
399 | issue = Issue.new.copy_from(1) |
|
407 | issue = Issue.new.copy_from(1) | |
400 | assert issue.copy? |
|
408 | assert issue.copy? |
General Comments 0
You need to be logged in to leave comments.
Login now