##// END OF EJS Templates
Merged r4292 from trunk....
Eric Davis -
r4216:1ee7954f44d6
parent child
Show More
@@ -1,65 +1,68
1 1 class IssueMovesController < ApplicationController
2 2 default_search_scope :issues
3 3 before_filter :find_issues
4 4 before_filter :authorize
5 5
6 6 def new
7 7 prepare_for_issue_move
8 8 render :layout => false if request.xhr?
9 9 end
10 10
11 11 def create
12 12 prepare_for_issue_move
13 13
14 14 if request.post?
15 15 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
16 16 unsaved_issue_ids = []
17 17 moved_issues = []
18 18 @issues.each do |issue|
19 19 issue.reload
20 20 issue.init_journal(User.current)
21 issue.current_journal.notes = @notes if @notes.present?
21 22 call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
22 23 if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
23 24 moved_issues << r
24 25 else
25 26 unsaved_issue_ids << issue.id
26 27 end
27 28 end
28 29 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
29 30
30 31 if params[:follow]
31 32 if @issues.size == 1 && moved_issues.size == 1
32 33 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
33 34 else
34 35 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
35 36 end
36 37 else
37 38 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
38 39 end
39 40 return
40 41 end
41 42 end
42 43
43 44 private
44 45
45 46 def prepare_for_issue_move
46 47 @issues.sort!
47 48 @copy = params[:copy_options] && params[:copy_options][:copy]
48 49 @allowed_projects = Issue.allowed_target_projects_on_move
49 50 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
50 51 @target_project ||= @project
51 52 @trackers = @target_project.trackers
52 53 @available_statuses = Workflow.available_statuses(@project)
54 @notes = params[:notes]
55 @notes ||= ''
53 56 end
54 57
55 58 def extract_changed_attributes_for_move(params)
56 59 changed_attributes = {}
57 60 [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
58 61 unless params[valid_attribute].blank?
59 62 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
60 63 end
61 64 end
62 65 changed_attributes
63 66 end
64 67
65 68 end
@@ -1,62 +1,67
1 1 <h2><%= @copy ? l(:button_copy) : l(:button_move) %></h2>
2 2
3 3 <ul>
4 4 <% @issues.each do |issue| -%>
5 5 <li><%= link_to_issue issue %></li>
6 6 <% end -%>
7 7 </ul>
8 8
9 9 <% form_tag({:action => 'create'}, :id => 'move_form') do %>
10 10 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
11 11
12 12 <div class="box tabular">
13 13 <p><label for="new_project_id"><%=l(:field_project)%>:</label>
14 14 <%= select_tag "new_project_id",
15 15 project_tree_options_for_select(@allowed_projects, :selected => @target_project),
16 16 :onchange => remote_function(:url => { :action => 'new' },
17 17 :method => :get,
18 18 :update => 'content',
19 19 :with => "Form.serialize('move_form')") %></p>
20 20
21 21 <p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
22 22 <%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
23 23
24 24 <p>
25 25 <label><%= l(:field_assigned_to) %></label>
26 26 <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
27 27 content_tag('option', l(:label_nobody), :value => 'none') +
28 28 options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
29 29 </p>
30 30
31 31 <p>
32 32 <label><%= l(:field_status) %></label>
33 33 <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
34 34 </p>
35 35
36 36 <p>
37 37 <label><%= l(:field_priority) %></label>
38 38 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.all, :id, :name)) %>
39 39 </p>
40 40
41 41 <p>
42 42 <label><%= l(:field_start_date) %></label>
43 43 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
44 44 </p>
45 45
46 46 <p>
47 47 <label><%= l(:field_due_date) %></label>
48 48 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
49 49 </p>
50 50
51 <fieldset><legend><%= l(:field_notes) %></legend>
52 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
53 <%= wikitoolbar_for 'notes' %>
54 </fieldset>
55
51 56 <%= call_hook(:view_issues_move_bottom, :issues => @issues, :target_project => @target_project, :copy => !!@copy) %>
52 57 </div>
53 58
54 59 <% if @copy %>
55 60 <%= hidden_field_tag("copy_options[copy]", "1") %>
56 61 <%= submit_tag l(:button_copy) %>
57 62 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
58 63 <% else %>
59 64 <%= submit_tag l(:button_move) %>
60 65 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
61 66 <% end %>
62 67 <% end %>
@@ -1,112 +1,124
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 3 class IssueMovesControllerTest < ActionController::TestCase
4 4 fixtures :all
5 5
6 6 def setup
7 7 User.current = nil
8 8 end
9 9
10 10 def test_create_one_issue_to_another_project
11 11 @request.session[:user_id] = 2
12 12 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
13 13 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
14 14 assert_equal 2, Issue.find(1).project_id
15 15 end
16 16
17 17 def test_create_one_issue_to_another_project_should_follow_when_needed
18 18 @request.session[:user_id] = 2
19 19 post :create, :id => 1, :new_project_id => 2, :follow => '1'
20 20 assert_redirected_to '/issues/1'
21 21 end
22 22
23 23 def test_bulk_create_to_another_project
24 24 @request.session[:user_id] = 2
25 25 post :create, :ids => [1, 2], :new_project_id => 2
26 26 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
27 27 # Issues moved to project 2
28 28 assert_equal 2, Issue.find(1).project_id
29 29 assert_equal 2, Issue.find(2).project_id
30 30 # No tracker change
31 31 assert_equal 1, Issue.find(1).tracker_id
32 32 assert_equal 2, Issue.find(2).tracker_id
33 33 end
34 34
35 35 def test_bulk_create_to_another_tracker
36 36 @request.session[:user_id] = 2
37 37 post :create, :ids => [1, 2], :new_tracker_id => 2
38 38 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
39 39 assert_equal 2, Issue.find(1).tracker_id
40 40 assert_equal 2, Issue.find(2).tracker_id
41 41 end
42 42
43 43 context "#create via bulk move" do
44 should "allow changing the issue priority" do
44 setup do
45 45 @request.session[:user_id] = 2
46 end
47
48 should "allow changing the issue priority" do
46 49 post :create, :ids => [1, 2], :priority_id => 6
47 50
48 51 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
49 52 assert_equal 6, Issue.find(1).priority_id
50 53 assert_equal 6, Issue.find(2).priority_id
51 54
52 55 end
56
57 should "allow adding a note when moving" do
58 post :create, :ids => [1, 2], :notes => 'Moving two issues'
59
60 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
61 assert_equal 'Moving two issues', Issue.find(1).journals.last.notes
62 assert_equal 'Moving two issues', Issue.find(2).journals.last.notes
63
64 end
53 65
54 66 end
55 67
56 68 def test_bulk_copy_to_another_project
57 69 @request.session[:user_id] = 2
58 70 assert_difference 'Issue.count', 2 do
59 71 assert_no_difference 'Project.find(1).issues.count' do
60 72 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
61 73 end
62 74 end
63 75 assert_redirected_to 'projects/ecookbook/issues'
64 76 end
65 77
66 78 context "#create via bulk copy" do
67 79 should "allow not changing the issue's attributes" do
68 80 @request.session[:user_id] = 2
69 81 issue_before_move = Issue.find(1)
70 82 assert_difference 'Issue.count', 1 do
71 83 assert_no_difference 'Project.find(1).issues.count' do
72 84 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
73 85 end
74 86 end
75 87 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
76 88 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
77 89 assert_equal issue_before_move.status_id, issue_after_move.status_id
78 90 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
79 91 end
80 92
81 93 should "allow changing the issue's attributes" do
82 94 # Fixes random test failure with Mysql
83 95 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
84 96 Issue.delete_all("project_id=2")
85 97
86 98 @request.session[:user_id] = 2
87 99 assert_difference 'Issue.count', 2 do
88 100 assert_no_difference 'Project.find(1).issues.count' do
89 101 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
90 102 end
91 103 end
92 104
93 105 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
94 106 assert_equal 2, copied_issues.size
95 107 copied_issues.each do |issue|
96 108 assert_equal 2, issue.project_id, "Project is incorrect"
97 109 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
98 110 assert_equal 3, issue.status_id, "Status is incorrect"
99 111 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
100 112 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
101 113 end
102 114 end
103 115 end
104 116
105 117 def test_copy_to_another_project_should_follow_when_needed
106 118 @request.session[:user_id] = 2
107 119 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
108 120 issue = Issue.first(:order => 'id DESC')
109 121 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
110 122 end
111 123
112 124 end
General Comments 0
You need to be logged in to leave comments. Login now