The requested changes are too big and content was truncated. Show full diff
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,247 +1,265 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 | require 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | class IssuesControllerTransactionTest < ActionController::TestCase |
|
21 | class IssuesControllerTransactionTest < ActionController::TestCase | |
22 | fixtures :projects, |
|
22 | fixtures :projects, | |
23 | :users, |
|
23 | :users, | |
24 | :roles, |
|
24 | :roles, | |
25 | :members, |
|
25 | :members, | |
26 | :member_roles, |
|
26 | :member_roles, | |
27 | :issues, |
|
27 | :issues, | |
28 | :issue_statuses, |
|
28 | :issue_statuses, | |
29 | :versions, |
|
29 | :versions, | |
30 | :trackers, |
|
30 | :trackers, | |
31 | :projects_trackers, |
|
31 | :projects_trackers, | |
32 | :issue_categories, |
|
32 | :issue_categories, | |
33 | :enabled_modules, |
|
33 | :enabled_modules, | |
34 | :enumerations, |
|
34 | :enumerations, | |
35 | :attachments, |
|
35 | :attachments, | |
36 | :workflows, |
|
36 | :workflows, | |
37 | :custom_fields, |
|
37 | :custom_fields, | |
38 | :custom_values, |
|
38 | :custom_values, | |
39 | :custom_fields_projects, |
|
39 | :custom_fields_projects, | |
40 | :custom_fields_trackers, |
|
40 | :custom_fields_trackers, | |
41 | :time_entries, |
|
41 | :time_entries, | |
42 | :journals, |
|
42 | :journals, | |
43 | :journal_details, |
|
43 | :journal_details, | |
44 | :queries |
|
44 | :queries | |
45 |
|
45 | |||
46 | self.use_transactional_fixtures = false |
|
46 | self.use_transactional_fixtures = false | |
47 |
|
47 | |||
48 | def setup |
|
48 | def setup | |
49 | @controller = IssuesController.new |
|
49 | @controller = IssuesController.new | |
50 | @request = ActionController::TestRequest.new |
|
50 | @request = ActionController::TestRequest.new | |
51 | @response = ActionController::TestResponse.new |
|
51 | @response = ActionController::TestResponse.new | |
52 | User.current = nil |
|
52 | User.current = nil | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_update_stale_issue_should_not_update_the_issue |
|
55 | def test_update_stale_issue_should_not_update_the_issue | |
56 | issue = Issue.find(2) |
|
56 | issue = Issue.find(2) | |
57 | @request.session[:user_id] = 2 |
|
57 | @request.session[:user_id] = 2 | |
58 |
|
58 | |||
59 | assert_no_difference 'Journal.count' do |
|
59 | assert_no_difference 'Journal.count' do | |
60 | assert_no_difference 'TimeEntry.count' do |
|
60 | assert_no_difference 'TimeEntry.count' do | |
61 | put :update, |
|
61 | put :update, | |
62 | :id => issue.id, |
|
62 | :id => issue.id, | |
63 | :issue => { |
|
63 | :issue => { | |
64 | :fixed_version_id => 4, |
|
64 | :fixed_version_id => 4, | |
65 | :notes => 'My notes', |
|
65 | :notes => 'My notes', | |
66 | :lock_version => (issue.lock_version - 1) |
|
66 | :lock_version => (issue.lock_version - 1) | |
67 | }, |
|
67 | }, | |
68 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
68 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
69 | end |
|
69 | end | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | assert_response :success |
|
72 | assert_response :success | |
73 | assert_template 'edit' |
|
73 | assert_template 'edit' | |
74 |
|
74 | |||
75 | assert_select 'div.conflict' |
|
75 | assert_select 'div.conflict' | |
76 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' |
|
76 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' | |
77 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' |
|
77 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' | |
78 | assert_select 'label' do |
|
78 | assert_select 'label' do | |
79 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' |
|
79 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' | |
80 | assert_select 'a[href=/issues/2]' |
|
80 | assert_select 'a[href=/issues/2]' | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_update_stale_issue_should_save_attachments |
|
84 | def test_update_stale_issue_should_save_attachments | |
85 | set_tmp_attachments_directory |
|
85 | set_tmp_attachments_directory | |
86 | issue = Issue.find(2) |
|
86 | issue = Issue.find(2) | |
87 | @request.session[:user_id] = 2 |
|
87 | @request.session[:user_id] = 2 | |
88 |
|
88 | |||
89 | assert_no_difference 'Journal.count' do |
|
89 | assert_no_difference 'Journal.count' do | |
90 | assert_no_difference 'TimeEntry.count' do |
|
90 | assert_no_difference 'TimeEntry.count' do | |
91 | assert_difference 'Attachment.count' do |
|
91 | assert_difference 'Attachment.count' do | |
92 | put :update, |
|
92 | put :update, | |
93 | :id => issue.id, |
|
93 | :id => issue.id, | |
94 | :issue => { |
|
94 | :issue => { | |
95 | :fixed_version_id => 4, |
|
95 | :fixed_version_id => 4, | |
96 | :notes => 'My notes', |
|
96 | :notes => 'My notes', | |
97 | :lock_version => (issue.lock_version - 1) |
|
97 | :lock_version => (issue.lock_version - 1) | |
98 | }, |
|
98 | }, | |
99 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, |
|
99 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, | |
100 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
100 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
101 | end |
|
101 | end | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | assert_response :success |
|
105 | assert_response :success | |
106 | assert_template 'edit' |
|
106 | assert_template 'edit' | |
107 | attachment = Attachment.first(:order => 'id DESC') |
|
107 | attachment = Attachment.first(:order => 'id DESC') | |
108 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
108 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
109 | assert_tag 'span', :content => /testfile.txt/ |
|
109 | assert_tag 'span', :content => /testfile.txt/ | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option |
|
112 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option | |
113 | issue = Issue.find(2) |
|
113 | issue = Issue.find(2) | |
114 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
115 |
|
115 | |||
116 | put :update, :id => issue.id, |
|
116 | put :update, :id => issue.id, | |
117 | :issue => { |
|
117 | :issue => { | |
118 | :fixed_version_id => 4, |
|
118 | :fixed_version_id => 4, | |
119 | :notes => '', |
|
119 | :notes => '', | |
120 | :lock_version => (issue.lock_version - 1) |
|
120 | :lock_version => (issue.lock_version - 1) | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | assert_tag 'div', :attributes => {:class => 'conflict'} |
|
123 | assert_tag 'div', :attributes => {:class => 'conflict'} | |
124 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} |
|
124 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} | |
125 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'} |
|
125 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'} | |
126 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'} |
|
126 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'} | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def test_update_stale_issue_should_show_conflicting_journals |
|
129 | def test_update_stale_issue_should_show_conflicting_journals | |
130 | @request.session[:user_id] = 2 |
|
130 | @request.session[:user_id] = 2 | |
131 |
|
131 | |||
132 | put :update, :id => 1, |
|
132 | put :update, :id => 1, | |
133 | :issue => { |
|
133 | :issue => { | |
134 | :fixed_version_id => 4, |
|
134 | :fixed_version_id => 4, | |
135 | :notes => '', |
|
135 | :notes => '', | |
136 | :lock_version => 2 |
|
136 | :lock_version => 2 | |
137 | }, |
|
137 | }, | |
138 | :last_journal_id => 1 |
|
138 | :last_journal_id => 1 | |
139 |
|
139 | |||
140 | assert_not_nil assigns(:conflict_journals) |
|
140 | assert_not_nil assigns(:conflict_journals) | |
141 | assert_equal 1, assigns(:conflict_journals).size |
|
141 | assert_equal 1, assigns(:conflict_journals).size | |
142 | assert_equal 2, assigns(:conflict_journals).first.id |
|
142 | assert_equal 2, assigns(:conflict_journals).first.id | |
143 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
143 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
144 | :descendant => {:content => /Some notes with Redmine links/} |
|
144 | :descendant => {:content => /Some notes with Redmine links/} | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_update_stale_issue_without_previous_journal_should_show_all_journals |
|
147 | def test_update_stale_issue_without_previous_journal_should_show_all_journals | |
148 | @request.session[:user_id] = 2 |
|
148 | @request.session[:user_id] = 2 | |
149 |
|
149 | |||
150 | put :update, :id => 1, |
|
150 | put :update, :id => 1, | |
151 | :issue => { |
|
151 | :issue => { | |
152 | :fixed_version_id => 4, |
|
152 | :fixed_version_id => 4, | |
153 | :notes => '', |
|
153 | :notes => '', | |
154 | :lock_version => 2 |
|
154 | :lock_version => 2 | |
155 | }, |
|
155 | }, | |
156 | :last_journal_id => '' |
|
156 | :last_journal_id => '' | |
157 |
|
157 | |||
158 | assert_not_nil assigns(:conflict_journals) |
|
158 | assert_not_nil assigns(:conflict_journals) | |
159 | assert_equal 2, assigns(:conflict_journals).size |
|
159 | assert_equal 2, assigns(:conflict_journals).size | |
160 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
160 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
161 | :descendant => {:content => /Some notes with Redmine links/} |
|
161 | :descendant => {:content => /Some notes with Redmine links/} | |
162 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
162 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
163 | :descendant => {:content => /Journal notes/} |
|
163 | :descendant => {:content => /Journal notes/} | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def test_update_stale_issue_should_show_private_journals_with_permission_only |
|
166 | def test_update_stale_issue_should_show_private_journals_with_permission_only | |
167 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
167 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) | |
168 |
|
168 | |||
169 | @request.session[:user_id] = 2 |
|
169 | @request.session[:user_id] = 2 | |
170 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' |
|
170 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' | |
171 | assert_include journal, assigns(:conflict_journals) |
|
171 | assert_include journal, assigns(:conflict_journals) | |
172 |
|
172 | |||
173 | Role.find(1).remove_permission! :view_private_notes |
|
173 | Role.find(1).remove_permission! :view_private_notes | |
174 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' |
|
174 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' | |
175 | assert_not_include journal, assigns(:conflict_journals) |
|
175 | assert_not_include journal, assigns(:conflict_journals) | |
176 | end |
|
176 | end | |
177 |
|
177 | |||
178 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update |
|
178 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update | |
179 | @request.session[:user_id] = 2 |
|
179 | @request.session[:user_id] = 2 | |
180 |
|
180 | |||
181 | assert_difference 'Journal.count' do |
|
181 | assert_difference 'Journal.count' do | |
182 | put :update, :id => 1, |
|
182 | put :update, :id => 1, | |
183 | :issue => { |
|
183 | :issue => { | |
184 | :fixed_version_id => 4, |
|
184 | :fixed_version_id => 4, | |
185 | :notes => 'overwrite_conflict_resolution', |
|
185 | :notes => 'overwrite_conflict_resolution', | |
186 | :lock_version => 2 |
|
186 | :lock_version => 2 | |
187 | }, |
|
187 | }, | |
188 | :conflict_resolution => 'overwrite' |
|
188 | :conflict_resolution => 'overwrite' | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | assert_response 302 |
|
191 | assert_response 302 | |
192 | issue = Issue.find(1) |
|
192 | issue = Issue.find(1) | |
193 | assert_equal 4, issue.fixed_version_id |
|
193 | assert_equal 4, issue.fixed_version_id | |
194 | journal = Journal.first(:order => 'id DESC') |
|
194 | journal = Journal.first(:order => 'id DESC') | |
195 | assert_equal 'overwrite_conflict_resolution', journal.notes |
|
195 | assert_equal 'overwrite_conflict_resolution', journal.notes | |
196 | assert journal.details.any? |
|
196 | assert journal.details.any? | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update |
|
199 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update | |
200 | @request.session[:user_id] = 2 |
|
200 | @request.session[:user_id] = 2 | |
201 |
|
201 | |||
202 | assert_difference 'Journal.count' do |
|
202 | assert_difference 'Journal.count' do | |
203 | put :update, :id => 1, |
|
203 | put :update, :id => 1, | |
204 | :issue => { |
|
204 | :issue => { | |
205 | :fixed_version_id => 4, |
|
205 | :fixed_version_id => 4, | |
206 | :notes => 'add_notes_conflict_resolution', |
|
206 | :notes => 'add_notes_conflict_resolution', | |
207 | :lock_version => 2 |
|
207 | :lock_version => 2 | |
208 | }, |
|
208 | }, | |
209 | :conflict_resolution => 'add_notes' |
|
209 | :conflict_resolution => 'add_notes' | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | assert_response 302 |
|
212 | assert_response 302 | |
213 | issue = Issue.find(1) |
|
213 | issue = Issue.find(1) | |
214 | assert_nil issue.fixed_version_id |
|
214 | assert_nil issue.fixed_version_id | |
215 | journal = Journal.first(:order => 'id DESC') |
|
215 | journal = Journal.first(:order => 'id DESC') | |
216 | assert_equal 'add_notes_conflict_resolution', journal.notes |
|
216 | assert_equal 'add_notes_conflict_resolution', journal.notes | |
217 | assert journal.details.empty? |
|
217 | assert journal.details.empty? | |
218 | end |
|
218 | end | |
219 |
|
219 | |||
220 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating |
|
220 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating | |
221 | @request.session[:user_id] = 2 |
|
221 | @request.session[:user_id] = 2 | |
222 |
|
222 | |||
223 | assert_no_difference 'Journal.count' do |
|
223 | assert_no_difference 'Journal.count' do | |
224 | put :update, :id => 1, |
|
224 | put :update, :id => 1, | |
225 | :issue => { |
|
225 | :issue => { | |
226 | :fixed_version_id => 4, |
|
226 | :fixed_version_id => 4, | |
227 | :notes => 'add_notes_conflict_resolution', |
|
227 | :notes => 'add_notes_conflict_resolution', | |
228 | :lock_version => 2 |
|
228 | :lock_version => 2 | |
229 | }, |
|
229 | }, | |
230 | :conflict_resolution => 'cancel' |
|
230 | :conflict_resolution => 'cancel' | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | assert_redirected_to '/issues/1' |
|
233 | assert_redirected_to '/issues/1' | |
234 | issue = Issue.find(1) |
|
234 | issue = Issue.find(1) | |
235 | assert_nil issue.fixed_version_id |
|
235 | assert_nil issue.fixed_version_id | |
236 | end |
|
236 | end | |
237 |
|
237 | |||
|
238 | def test_put_update_with_spent_time_and_failure_should_not_add_spent_time | |||
|
239 | @request.session[:user_id] = 2 | |||
|
240 | ||||
|
241 | assert_no_difference('TimeEntry.count') do | |||
|
242 | put :update, | |||
|
243 | :id => 1, | |||
|
244 | :issue => { :subject => '' }, | |||
|
245 | :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id } | |||
|
246 | assert_response :success | |||
|
247 | end | |||
|
248 | ||||
|
249 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5' | |||
|
250 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added' | |||
|
251 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |||
|
252 | assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id | |||
|
253 | end | |||
|
254 | end | |||
|
255 | ||||
238 | def test_index_should_rescue_invalid_sql_query |
|
256 | def test_index_should_rescue_invalid_sql_query | |
239 | Query.any_instance.stubs(:statement).returns("INVALID STATEMENT") |
|
257 | Query.any_instance.stubs(:statement).returns("INVALID STATEMENT") | |
240 |
|
258 | |||
241 | get :index |
|
259 | get :index | |
242 | assert_response 500 |
|
260 | assert_response 500 | |
243 | assert_tag 'p', :content => /An error occurred/ |
|
261 | assert_tag 'p', :content => /An error occurred/ | |
244 | assert_nil session[:query] |
|
262 | assert_nil session[:query] | |
245 | assert_nil session[:issues_index_sort] |
|
263 | assert_nil session[:issues_index_sort] | |
246 | end |
|
264 | end | |
247 | end |
|
265 | end |
General Comments 0
You need to be logged in to leave comments.
Login now