@@ -1,124 +1,124 | |||||
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 |
|
43 | context "#create via bulk move" do | |
44 | setup do |
|
44 | setup do | |
45 | @request.session[:user_id] = 2 |
|
45 | @request.session[:user_id] = 2 | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | should "allow changing the issue priority" do |
|
48 | should "allow changing the issue priority" do | |
49 | post :create, :ids => [1, 2], :priority_id => 6 |
|
49 | post :create, :ids => [1, 2], :priority_id => 6 | |
50 |
|
50 | |||
51 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
51 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
52 | assert_equal 6, Issue.find(1).priority_id |
|
52 | assert_equal 6, Issue.find(1).priority_id | |
53 | assert_equal 6, Issue.find(2).priority_id |
|
53 | assert_equal 6, Issue.find(2).priority_id | |
54 |
|
54 | |||
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | should "allow adding a note when moving" do |
|
57 | should "allow adding a note when moving" do | |
58 | post :create, :ids => [1, 2], :notes => 'Moving two issues' |
|
58 | post :create, :ids => [1, 2], :notes => 'Moving two issues' | |
59 |
|
59 | |||
60 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
60 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
61 | assert_equal 'Moving two issues', Issue.find(1).journals.last.notes |
|
61 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes | |
62 | assert_equal 'Moving two issues', Issue.find(2).journals.last.notes |
|
62 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes | |
63 |
|
63 | |||
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_bulk_copy_to_another_project |
|
68 | def test_bulk_copy_to_another_project | |
69 | @request.session[:user_id] = 2 |
|
69 | @request.session[:user_id] = 2 | |
70 | assert_difference 'Issue.count', 2 do |
|
70 | assert_difference 'Issue.count', 2 do | |
71 | assert_no_difference 'Project.find(1).issues.count' do |
|
71 | assert_no_difference 'Project.find(1).issues.count' do | |
72 | post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} |
|
72 | post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 | assert_redirected_to '/projects/ecookbook/issues' |
|
75 | assert_redirected_to '/projects/ecookbook/issues' | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | context "#create via bulk copy" do |
|
78 | context "#create via bulk copy" do | |
79 | should "allow not changing the issue's attributes" do |
|
79 | should "allow not changing the issue's attributes" do | |
80 | @request.session[:user_id] = 2 |
|
80 | @request.session[:user_id] = 2 | |
81 | issue_before_move = Issue.find(1) |
|
81 | issue_before_move = Issue.find(1) | |
82 | assert_difference 'Issue.count', 1 do |
|
82 | assert_difference 'Issue.count', 1 do | |
83 | assert_no_difference 'Project.find(1).issues.count' do |
|
83 | assert_no_difference 'Project.find(1).issues.count' do | |
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 => '' |
|
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 => '' | |
85 | end |
|
85 | end | |
86 | end |
|
86 | end | |
87 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) |
|
87 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) | |
88 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id |
|
88 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id | |
89 | assert_equal issue_before_move.status_id, issue_after_move.status_id |
|
89 | assert_equal issue_before_move.status_id, issue_after_move.status_id | |
90 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id |
|
90 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | should "allow changing the issue's attributes" do |
|
93 | should "allow changing the issue's attributes" do | |
94 | # Fixes random test failure with Mysql |
|
94 | # Fixes random test failure with Mysql | |
95 | # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results |
|
95 | # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results | |
96 | Issue.delete_all("project_id=2") |
|
96 | Issue.delete_all("project_id=2") | |
97 |
|
97 | |||
98 | @request.session[:user_id] = 2 |
|
98 | @request.session[:user_id] = 2 | |
99 | assert_difference 'Issue.count', 2 do |
|
99 | assert_difference 'Issue.count', 2 do | |
100 | assert_no_difference 'Project.find(1).issues.count' do |
|
100 | assert_no_difference 'Project.find(1).issues.count' do | |
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' |
|
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' | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) |
|
105 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) | |
106 | assert_equal 2, copied_issues.size |
|
106 | assert_equal 2, copied_issues.size | |
107 | copied_issues.each do |issue| |
|
107 | copied_issues.each do |issue| | |
108 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
108 | assert_equal 2, issue.project_id, "Project is incorrect" | |
109 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
109 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" | |
110 | assert_equal 3, issue.status_id, "Status is incorrect" |
|
110 | assert_equal 3, issue.status_id, "Status is incorrect" | |
111 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
111 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" | |
112 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
112 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def test_copy_to_another_project_should_follow_when_needed |
|
117 | def test_copy_to_another_project_should_follow_when_needed | |
118 | @request.session[:user_id] = 2 |
|
118 | @request.session[:user_id] = 2 | |
119 | post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' |
|
119 | post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' | |
120 | issue = Issue.first(:order => 'id DESC') |
|
120 | issue = Issue.first(:order => 'id DESC') | |
121 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
121 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | end |
|
124 | end |
General Comments 0
You need to be logged in to leave comments.
Login now