@@ -1,156 +1,165 | |||
|
1 | 1 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 2 | |
|
3 | 3 | class IssueMovesControllerTest < ActionController::TestCase |
|
4 | fixtures :all | |
|
4 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
|
5 | :enumerations, :users, :issue_categories, | |
|
6 | :projects_trackers, | |
|
7 | :roles, | |
|
8 | :member_roles, | |
|
9 | :members, | |
|
10 | :enabled_modules, | |
|
11 | :workflows, | |
|
12 | :journals, :journal_details, | |
|
13 | :issues, :issue_statuses, :issue_categories | |
|
5 | 14 | |
|
6 | 15 | def setup |
|
7 | 16 | User.current = nil |
|
8 | 17 | end |
|
9 | 18 | |
|
10 | 19 | def test_get_issue_moves_new |
|
11 | 20 | @request.session[:user_id] = 2 |
|
12 | 21 | get :new, :id => 1 |
|
13 | 22 | |
|
14 | 23 | assert_tag :tag => 'option', :content => 'eCookbook', |
|
15 | 24 | :attributes => { :value => '1', :selected => 'selected' } |
|
16 | 25 | %w(new_tracker_id status_id priority_id assigned_to_id).each do |field| |
|
17 | 26 | assert_tag :tag => 'option', :content => '(No change)', :attributes => { :value => '' }, |
|
18 | 27 | :parent => {:tag => 'select', :attributes => {:id => field}} |
|
19 | 28 | assert_no_tag :tag => 'option', :attributes => {:selected => 'selected'}, |
|
20 | 29 | :parent => {:tag => 'select', :attributes => {:id => field}} |
|
21 | 30 | end |
|
22 | 31 | |
|
23 | 32 | # Be sure we don't include inactive enumerations |
|
24 | 33 | assert ! IssuePriority.find(15).active? |
|
25 | 34 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
26 | 35 | :parent => {:tag => 'select', :attributes => {:id => 'priority_id'} } |
|
27 | 36 | end |
|
28 | 37 | |
|
29 | 38 | def test_create_one_issue_to_another_project |
|
30 | 39 | @request.session[:user_id] = 2 |
|
31 | 40 | post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' |
|
32 | 41 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
33 | 42 | assert_equal 2, Issue.find(1).project_id |
|
34 | 43 | end |
|
35 | 44 | |
|
36 | 45 | def test_create_one_issue_to_another_project_should_follow_when_needed |
|
37 | 46 | @request.session[:user_id] = 2 |
|
38 | 47 | post :create, :id => 1, :new_project_id => 2, :follow => '1' |
|
39 | 48 | assert_redirected_to '/issues/1' |
|
40 | 49 | end |
|
41 | 50 | |
|
42 | 51 | def test_bulk_create_to_another_project |
|
43 | 52 | @request.session[:user_id] = 2 |
|
44 | 53 | post :create, :ids => [1, 2], :new_project_id => 2 |
|
45 | 54 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
46 | 55 | # Issues moved to project 2 |
|
47 | 56 | assert_equal 2, Issue.find(1).project_id |
|
48 | 57 | assert_equal 2, Issue.find(2).project_id |
|
49 | 58 | # No tracker change |
|
50 | 59 | assert_equal 1, Issue.find(1).tracker_id |
|
51 | 60 | assert_equal 2, Issue.find(2).tracker_id |
|
52 | 61 | end |
|
53 | 62 | |
|
54 | 63 | def test_bulk_create_to_another_tracker |
|
55 | 64 | @request.session[:user_id] = 2 |
|
56 | 65 | post :create, :ids => [1, 2], :new_tracker_id => 2 |
|
57 | 66 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
58 | 67 | assert_equal 2, Issue.find(1).tracker_id |
|
59 | 68 | assert_equal 2, Issue.find(2).tracker_id |
|
60 | 69 | end |
|
61 | 70 | |
|
62 | 71 | context "#create via bulk move" do |
|
63 | 72 | setup do |
|
64 | 73 | @request.session[:user_id] = 2 |
|
65 | 74 | end |
|
66 | 75 | |
|
67 | 76 | should "allow changing the issue priority" do |
|
68 | 77 | post :create, :ids => [1, 2], :priority_id => 6 |
|
69 | 78 | |
|
70 | 79 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
71 | 80 | assert_equal 6, Issue.find(1).priority_id |
|
72 | 81 | assert_equal 6, Issue.find(2).priority_id |
|
73 | 82 | |
|
74 | 83 | end |
|
75 | 84 | |
|
76 | 85 | should "allow adding a note when moving" do |
|
77 | 86 | post :create, :ids => [1, 2], :notes => 'Moving two issues' |
|
78 | 87 | |
|
79 | 88 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
80 | 89 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes |
|
81 | 90 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes |
|
82 | 91 | |
|
83 | 92 | end |
|
84 | 93 | |
|
85 | 94 | end |
|
86 | 95 | |
|
87 | 96 | def test_bulk_copy_to_another_project |
|
88 | 97 | @request.session[:user_id] = 2 |
|
89 | 98 | assert_difference 'Issue.count', 2 do |
|
90 | 99 | assert_no_difference 'Project.find(1).issues.count' do |
|
91 | 100 | post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} |
|
92 | 101 | end |
|
93 | 102 | end |
|
94 | 103 | assert_redirected_to '/projects/ecookbook/issues' |
|
95 | 104 | end |
|
96 | 105 | |
|
97 | 106 | context "#create via bulk copy" do |
|
98 | 107 | should "allow not changing the issue's attributes" do |
|
99 | 108 | @request.session[:user_id] = 2 |
|
100 | 109 | issue_before_move = Issue.find(1) |
|
101 | 110 | assert_difference 'Issue.count', 1 do |
|
102 | 111 | assert_no_difference 'Project.find(1).issues.count' do |
|
103 | 112 | post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' |
|
104 | 113 | end |
|
105 | 114 | end |
|
106 | 115 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) |
|
107 | 116 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id |
|
108 | 117 | assert_equal issue_before_move.status_id, issue_after_move.status_id |
|
109 | 118 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id |
|
110 | 119 | end |
|
111 | 120 | |
|
112 | 121 | should "allow changing the issue's attributes" do |
|
113 | 122 | # Fixes random test failure with Mysql |
|
114 | 123 | # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results |
|
115 | 124 | Issue.delete_all("project_id=2") |
|
116 | 125 | |
|
117 | 126 | @request.session[:user_id] = 2 |
|
118 | 127 | assert_difference 'Issue.count', 2 do |
|
119 | 128 | assert_no_difference 'Project.find(1).issues.count' do |
|
120 | 129 | 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' |
|
121 | 130 | end |
|
122 | 131 | end |
|
123 | 132 | |
|
124 | 133 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) |
|
125 | 134 | assert_equal 2, copied_issues.size |
|
126 | 135 | copied_issues.each do |issue| |
|
127 | 136 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
128 | 137 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
129 | 138 | assert_equal 3, issue.status_id, "Status is incorrect" |
|
130 | 139 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
131 | 140 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
132 | 141 | end |
|
133 | 142 | end |
|
134 | 143 | |
|
135 | 144 | should "allow adding a note when copying" do |
|
136 | 145 | @request.session[:user_id] = 2 |
|
137 | 146 | assert_difference 'Issue.count', 1 do |
|
138 | 147 | post :create, :ids => [1], :copy_options => {:copy => '1'}, :notes => 'Copying one issue', :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
139 | 148 | end |
|
140 | 149 | |
|
141 | 150 | issue = Issue.first(:order => 'id DESC') |
|
142 | 151 | assert_equal 1, issue.journals.size |
|
143 | 152 | journal = issue.journals.first |
|
144 | 153 | assert_equal 0, journal.details.size |
|
145 | 154 | assert_equal 'Copying one issue', journal.notes |
|
146 | 155 | end |
|
147 | 156 | end |
|
148 | 157 | |
|
149 | 158 | def test_copy_to_another_project_should_follow_when_needed |
|
150 | 159 | @request.session[:user_id] = 2 |
|
151 | 160 | post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' |
|
152 | 161 | issue = Issue.first(:order => 'id DESC') |
|
153 | 162 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
154 | 163 | end |
|
155 | 164 | |
|
156 | 165 | end |
General Comments 0
You need to be logged in to leave comments.
Login now