@@ -225,7 +225,11 class IssuesController < ApplicationController | |||
|
225 | 225 | end |
|
226 | 226 | target_projects ||= @projects |
|
227 | 227 | |
|
228 | @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) | |
|
228 | if @copy | |
|
229 | @available_statuses = [IssueStatus.default] | |
|
230 | else | |
|
231 | @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) | |
|
232 | end | |
|
229 | 233 | @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) |
|
230 | 234 | @assignables = target_projects.map(&:assignable_users).reduce(:&) |
|
231 | 235 | @trackers = target_projects.map(&:trackers).reduce(:&) |
@@ -511,24 +511,28 class Issue < ActiveRecord::Base | |||
|
511 | 511 | |
|
512 | 512 | # Returns an array of statuses that user is able to apply |
|
513 | 513 | def new_statuses_allowed_to(user=User.current, include_default=false) |
|
514 | initial_status = nil | |
|
515 | if new_record? | |
|
516 | initial_status = IssueStatus.default | |
|
517 | elsif status_id_was | |
|
518 | initial_status = IssueStatus.find_by_id(status_id_was) | |
|
514 | if new_record? && @copied_from | |
|
515 | [IssueStatus.default, @copied_from.status].compact.uniq.sort | |
|
516 | else | |
|
517 | initial_status = nil | |
|
518 | if new_record? | |
|
519 | initial_status = IssueStatus.default | |
|
520 | elsif status_id_was | |
|
521 | initial_status = IssueStatus.find_by_id(status_id_was) | |
|
522 | end | |
|
523 | initial_status ||= status | |
|
524 | ||
|
525 | statuses = initial_status.find_new_statuses_allowed_to( | |
|
526 | user.admin ? Role.all : user.roles_for_project(project), | |
|
527 | tracker, | |
|
528 | author == user, | |
|
529 | assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id | |
|
530 | ) | |
|
531 | statuses << initial_status unless statuses.empty? | |
|
532 | statuses << IssueStatus.default if include_default | |
|
533 | statuses = statuses.compact.uniq.sort | |
|
534 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses | |
|
519 | 535 | end |
|
520 | initial_status ||= status | |
|
521 | ||
|
522 | statuses = initial_status.find_new_statuses_allowed_to( | |
|
523 | user.admin ? Role.all : user.roles_for_project(project), | |
|
524 | tracker, | |
|
525 | author == user, | |
|
526 | assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id | |
|
527 | ) | |
|
528 | statuses << initial_status unless statuses.empty? | |
|
529 | statuses << IssueStatus.default if include_default | |
|
530 | statuses = statuses.compact.uniq.sort | |
|
531 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses | |
|
532 | 536 | end |
|
533 | 537 | |
|
534 | 538 | def assigned_to_was |
@@ -3065,24 +3065,38 class IssuesControllerTest < ActionController::TestCase | |||
|
3065 | 3065 | end |
|
3066 | 3066 | end |
|
3067 | 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 | 3073 | end |
|
3069 | 3074 | |
|
3070 | 3075 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes |
|
3071 | 3076 | @request.session[:user_id] = 2 |
|
3072 | issue_before_move = Issue.find(1) | |
|
3073 | assert_difference 'Issue.count', 1 do | |
|
3074 | assert_no_difference 'Project.find(1).issues.count' do | |
|
3075 | post :bulk_update, :ids => [1], :copy => '1', | |
|
3076 | :issue => { | |
|
3077 | :project_id => '2', :tracker_id => '', :assigned_to_id => '', | |
|
3078 | :status_id => '', :start_date => '', :due_date => '' | |
|
3079 |
|
|
|
3080 | end | |
|
3077 | issues = [ | |
|
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), | |
|
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) | |
|
3080 | ] | |
|
3081 | ||
|
3082 | assert_difference 'Issue.count', issues.size do | |
|
3083 | post :bulk_update, :ids => issues.map(&:id), :copy => '1', | |
|
3084 | :issue => { | |
|
3085 | :project_id => '', :tracker_id => '', :assigned_to_id => '', | |
|
3086 | :status_id => '', :start_date => '', :due_date => '' | |
|
3087 | } | |
|
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 | 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 | 3100 | end |
|
3087 | 3101 | |
|
3088 | 3102 | def test_bulk_copy_should_allow_changing_the_issue_attributes |
@@ -3097,7 +3111,7 class IssuesControllerTest < ActionController::TestCase | |||
|
3097 | 3111 | post :bulk_update, :ids => [1, 2], :copy => '1', |
|
3098 | 3112 | :issue => { |
|
3099 | 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 | 3116 | end |
|
3103 | 3117 | end |
@@ -3107,7 +3121,7 class IssuesControllerTest < ActionController::TestCase | |||
|
3107 | 3121 | copied_issues.each do |issue| |
|
3108 | 3122 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
3109 | 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 | 3125 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
3112 | 3126 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
3113 | 3127 | end |
@@ -395,6 +395,14 class IssueTest < ActiveSupport::TestCase | |||
|
395 | 395 | assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) |
|
396 | 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 | 406 | def test_copy |
|
399 | 407 | issue = Issue.new.copy_from(1) |
|
400 | 408 | assert issue.copy? |
General Comments 0
You need to be logged in to leave comments.
Login now