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