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