@@ -1,263 +1,263 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 | tests IssuesController |
|
22 | tests IssuesController | |
23 | fixtures :projects, |
|
23 | fixtures :projects, | |
24 | :users, |
|
24 | :users, | |
25 | :roles, |
|
25 | :roles, | |
26 | :members, |
|
26 | :members, | |
27 | :member_roles, |
|
27 | :member_roles, | |
28 | :issues, |
|
28 | :issues, | |
29 | :issue_statuses, |
|
29 | :issue_statuses, | |
30 | :versions, |
|
30 | :versions, | |
31 | :trackers, |
|
31 | :trackers, | |
32 | :projects_trackers, |
|
32 | :projects_trackers, | |
33 | :issue_categories, |
|
33 | :issue_categories, | |
34 | :enabled_modules, |
|
34 | :enabled_modules, | |
35 | :enumerations, |
|
35 | :enumerations, | |
36 | :attachments, |
|
36 | :attachments, | |
37 | :workflows, |
|
37 | :workflows, | |
38 | :custom_fields, |
|
38 | :custom_fields, | |
39 | :custom_values, |
|
39 | :custom_values, | |
40 | :custom_fields_projects, |
|
40 | :custom_fields_projects, | |
41 | :custom_fields_trackers, |
|
41 | :custom_fields_trackers, | |
42 | :time_entries, |
|
42 | :time_entries, | |
43 | :journals, |
|
43 | :journals, | |
44 | :journal_details, |
|
44 | :journal_details, | |
45 | :queries |
|
45 | :queries | |
46 |
|
46 | |||
47 | self.use_transactional_fixtures = false |
|
47 | self.use_transactional_fixtures = false | |
48 |
|
48 | |||
49 | def setup |
|
49 | def setup | |
50 | User.current = nil |
|
50 | User.current = nil | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_update_stale_issue_should_not_update_the_issue |
|
53 | def test_update_stale_issue_should_not_update_the_issue | |
54 | issue = Issue.find(2) |
|
54 | issue = Issue.find(2) | |
55 | @request.session[:user_id] = 2 |
|
55 | @request.session[:user_id] = 2 | |
56 |
|
56 | |||
57 | assert_no_difference 'Journal.count' do |
|
57 | assert_no_difference 'Journal.count' do | |
58 | assert_no_difference 'TimeEntry.count' do |
|
58 | assert_no_difference 'TimeEntry.count' do | |
59 | put :update, |
|
59 | put :update, | |
60 | :id => issue.id, |
|
60 | :id => issue.id, | |
61 | :issue => { |
|
61 | :issue => { | |
62 | :fixed_version_id => 4, |
|
62 | :fixed_version_id => 4, | |
63 | :notes => 'My notes', |
|
63 | :notes => 'My notes', | |
64 | :lock_version => (issue.lock_version - 1) |
|
64 | :lock_version => (issue.lock_version - 1) | |
65 | }, |
|
65 | }, | |
66 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
66 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | assert_response :success |
|
70 | assert_response :success | |
71 | assert_template 'edit' |
|
71 | assert_template 'edit' | |
72 |
|
72 | |||
73 | assert_select 'div.conflict' |
|
73 | assert_select 'div.conflict' | |
74 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' |
|
74 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' | |
75 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' |
|
75 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' | |
76 | assert_select 'label' do |
|
76 | assert_select 'label' do | |
77 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' |
|
77 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' | |
78 | assert_select 'a[href=/issues/2]' |
|
78 | assert_select 'a[href=/issues/2]' | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_update_stale_issue_should_save_attachments |
|
82 | def test_update_stale_issue_should_save_attachments | |
83 | set_tmp_attachments_directory |
|
83 | set_tmp_attachments_directory | |
84 | issue = Issue.find(2) |
|
84 | issue = Issue.find(2) | |
85 | @request.session[:user_id] = 2 |
|
85 | @request.session[:user_id] = 2 | |
86 |
|
86 | |||
87 | assert_no_difference 'Journal.count' do |
|
87 | assert_no_difference 'Journal.count' do | |
88 | assert_no_difference 'TimeEntry.count' do |
|
88 | assert_no_difference 'TimeEntry.count' do | |
89 | assert_difference 'Attachment.count' do |
|
89 | assert_difference 'Attachment.count' do | |
90 | put :update, |
|
90 | put :update, | |
91 | :id => issue.id, |
|
91 | :id => issue.id, | |
92 | :issue => { |
|
92 | :issue => { | |
93 | :fixed_version_id => 4, |
|
93 | :fixed_version_id => 4, | |
94 | :notes => 'My notes', |
|
94 | :notes => 'My notes', | |
95 | :lock_version => (issue.lock_version - 1) |
|
95 | :lock_version => (issue.lock_version - 1) | |
96 | }, |
|
96 | }, | |
97 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, |
|
97 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, | |
98 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
98 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | assert_response :success |
|
103 | assert_response :success | |
104 | assert_template 'edit' |
|
104 | assert_template 'edit' | |
105 |
attachment = Attachment. |
|
105 | attachment = Attachment.order('id DESC').first | |
106 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
106 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
107 | assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'} |
|
107 | assert_tag 'input', :attributes => {:name => 'attachments[p0][filename]', :value => 'testfile.txt'} | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option |
|
110 | def test_update_stale_issue_without_notes_should_not_show_add_notes_option | |
111 | issue = Issue.find(2) |
|
111 | issue = Issue.find(2) | |
112 | @request.session[:user_id] = 2 |
|
112 | @request.session[:user_id] = 2 | |
113 |
|
113 | |||
114 | put :update, :id => issue.id, |
|
114 | put :update, :id => issue.id, | |
115 | :issue => { |
|
115 | :issue => { | |
116 | :fixed_version_id => 4, |
|
116 | :fixed_version_id => 4, | |
117 | :notes => '', |
|
117 | :notes => '', | |
118 | :lock_version => (issue.lock_version - 1) |
|
118 | :lock_version => (issue.lock_version - 1) | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | assert_tag 'div', :attributes => {:class => 'conflict'} |
|
121 | assert_tag 'div', :attributes => {:class => 'conflict'} | |
122 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} |
|
122 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} | |
123 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'} |
|
123 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'} | |
124 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'} |
|
124 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'} | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_update_stale_issue_should_show_conflicting_journals |
|
127 | def test_update_stale_issue_should_show_conflicting_journals | |
128 | @request.session[:user_id] = 2 |
|
128 | @request.session[:user_id] = 2 | |
129 |
|
129 | |||
130 | put :update, :id => 1, |
|
130 | put :update, :id => 1, | |
131 | :issue => { |
|
131 | :issue => { | |
132 | :fixed_version_id => 4, |
|
132 | :fixed_version_id => 4, | |
133 | :notes => '', |
|
133 | :notes => '', | |
134 | :lock_version => 2 |
|
134 | :lock_version => 2 | |
135 | }, |
|
135 | }, | |
136 | :last_journal_id => 1 |
|
136 | :last_journal_id => 1 | |
137 |
|
137 | |||
138 | assert_not_nil assigns(:conflict_journals) |
|
138 | assert_not_nil assigns(:conflict_journals) | |
139 | assert_equal 1, assigns(:conflict_journals).size |
|
139 | assert_equal 1, assigns(:conflict_journals).size | |
140 | assert_equal 2, assigns(:conflict_journals).first.id |
|
140 | assert_equal 2, assigns(:conflict_journals).first.id | |
141 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
141 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
142 | :descendant => {:content => /Some notes with Redmine links/} |
|
142 | :descendant => {:content => /Some notes with Redmine links/} | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def test_update_stale_issue_without_previous_journal_should_show_all_journals |
|
145 | def test_update_stale_issue_without_previous_journal_should_show_all_journals | |
146 | @request.session[:user_id] = 2 |
|
146 | @request.session[:user_id] = 2 | |
147 |
|
147 | |||
148 | put :update, :id => 1, |
|
148 | put :update, :id => 1, | |
149 | :issue => { |
|
149 | :issue => { | |
150 | :fixed_version_id => 4, |
|
150 | :fixed_version_id => 4, | |
151 | :notes => '', |
|
151 | :notes => '', | |
152 | :lock_version => 2 |
|
152 | :lock_version => 2 | |
153 | }, |
|
153 | }, | |
154 | :last_journal_id => '' |
|
154 | :last_journal_id => '' | |
155 |
|
155 | |||
156 | assert_not_nil assigns(:conflict_journals) |
|
156 | assert_not_nil assigns(:conflict_journals) | |
157 | assert_equal 2, assigns(:conflict_journals).size |
|
157 | assert_equal 2, assigns(:conflict_journals).size | |
158 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
158 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
159 | :descendant => {:content => /Some notes with Redmine links/} |
|
159 | :descendant => {:content => /Some notes with Redmine links/} | |
160 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
160 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
161 | :descendant => {:content => /Journal notes/} |
|
161 | :descendant => {:content => /Journal notes/} | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def test_update_stale_issue_should_show_private_journals_with_permission_only |
|
164 | def test_update_stale_issue_should_show_private_journals_with_permission_only | |
165 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
165 | journal = Journal.create!(:journalized => Issue.find(1), :notes => 'Privates notes', :private_notes => true, :user_id => 1) | |
166 |
|
166 | |||
167 | @request.session[:user_id] = 2 |
|
167 | @request.session[:user_id] = 2 | |
168 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' |
|
168 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' | |
169 | assert_include journal, assigns(:conflict_journals) |
|
169 | assert_include journal, assigns(:conflict_journals) | |
170 |
|
170 | |||
171 | Role.find(1).remove_permission! :view_private_notes |
|
171 | Role.find(1).remove_permission! :view_private_notes | |
172 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' |
|
172 | put :update, :id => 1, :issue => {:fixed_version_id => 4, :lock_version => 2}, :last_journal_id => '' | |
173 | assert_not_include journal, assigns(:conflict_journals) |
|
173 | assert_not_include journal, assigns(:conflict_journals) | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update |
|
176 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update | |
177 | @request.session[:user_id] = 2 |
|
177 | @request.session[:user_id] = 2 | |
178 |
|
178 | |||
179 | assert_difference 'Journal.count' do |
|
179 | assert_difference 'Journal.count' do | |
180 | put :update, :id => 1, |
|
180 | put :update, :id => 1, | |
181 | :issue => { |
|
181 | :issue => { | |
182 | :fixed_version_id => 4, |
|
182 | :fixed_version_id => 4, | |
183 | :notes => 'overwrite_conflict_resolution', |
|
183 | :notes => 'overwrite_conflict_resolution', | |
184 | :lock_version => 2 |
|
184 | :lock_version => 2 | |
185 | }, |
|
185 | }, | |
186 | :conflict_resolution => 'overwrite' |
|
186 | :conflict_resolution => 'overwrite' | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | assert_response 302 |
|
189 | assert_response 302 | |
190 | issue = Issue.find(1) |
|
190 | issue = Issue.find(1) | |
191 | assert_equal 4, issue.fixed_version_id |
|
191 | assert_equal 4, issue.fixed_version_id | |
192 |
journal = Journal. |
|
192 | journal = Journal.order('id DESC').first | |
193 | assert_equal 'overwrite_conflict_resolution', journal.notes |
|
193 | assert_equal 'overwrite_conflict_resolution', journal.notes | |
194 | assert journal.details.any? |
|
194 | assert journal.details.any? | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update |
|
197 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update | |
198 | @request.session[:user_id] = 2 |
|
198 | @request.session[:user_id] = 2 | |
199 |
|
199 | |||
200 | assert_difference 'Journal.count' do |
|
200 | assert_difference 'Journal.count' do | |
201 | put :update, :id => 1, |
|
201 | put :update, :id => 1, | |
202 | :issue => { |
|
202 | :issue => { | |
203 | :fixed_version_id => 4, |
|
203 | :fixed_version_id => 4, | |
204 | :notes => 'add_notes_conflict_resolution', |
|
204 | :notes => 'add_notes_conflict_resolution', | |
205 | :lock_version => 2 |
|
205 | :lock_version => 2 | |
206 | }, |
|
206 | }, | |
207 | :conflict_resolution => 'add_notes' |
|
207 | :conflict_resolution => 'add_notes' | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | assert_response 302 |
|
210 | assert_response 302 | |
211 | issue = Issue.find(1) |
|
211 | issue = Issue.find(1) | |
212 | assert_nil issue.fixed_version_id |
|
212 | assert_nil issue.fixed_version_id | |
213 |
journal = Journal. |
|
213 | journal = Journal.order('id DESC').first | |
214 | assert_equal 'add_notes_conflict_resolution', journal.notes |
|
214 | assert_equal 'add_notes_conflict_resolution', journal.notes | |
215 | assert journal.details.empty? |
|
215 | assert journal.details.empty? | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating |
|
218 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating | |
219 | @request.session[:user_id] = 2 |
|
219 | @request.session[:user_id] = 2 | |
220 |
|
220 | |||
221 | assert_no_difference 'Journal.count' do |
|
221 | assert_no_difference 'Journal.count' do | |
222 | put :update, :id => 1, |
|
222 | put :update, :id => 1, | |
223 | :issue => { |
|
223 | :issue => { | |
224 | :fixed_version_id => 4, |
|
224 | :fixed_version_id => 4, | |
225 | :notes => 'add_notes_conflict_resolution', |
|
225 | :notes => 'add_notes_conflict_resolution', | |
226 | :lock_version => 2 |
|
226 | :lock_version => 2 | |
227 | }, |
|
227 | }, | |
228 | :conflict_resolution => 'cancel' |
|
228 | :conflict_resolution => 'cancel' | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | assert_redirected_to '/issues/1' |
|
231 | assert_redirected_to '/issues/1' | |
232 | issue = Issue.find(1) |
|
232 | issue = Issue.find(1) | |
233 | assert_nil issue.fixed_version_id |
|
233 | assert_nil issue.fixed_version_id | |
234 | end |
|
234 | end | |
235 |
|
235 | |||
236 | def test_put_update_with_spent_time_and_failure_should_not_add_spent_time |
|
236 | def test_put_update_with_spent_time_and_failure_should_not_add_spent_time | |
237 | @request.session[:user_id] = 2 |
|
237 | @request.session[:user_id] = 2 | |
238 |
|
238 | |||
239 | assert_no_difference('TimeEntry.count') do |
|
239 | assert_no_difference('TimeEntry.count') do | |
240 | put :update, |
|
240 | put :update, | |
241 | :id => 1, |
|
241 | :id => 1, | |
242 | :issue => { :subject => '' }, |
|
242 | :issue => { :subject => '' }, | |
243 | :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id } |
|
243 | :time_entry => { :hours => '2.5', :comments => 'should not be added', :activity_id => TimeEntryActivity.first.id } | |
244 | assert_response :success |
|
244 | assert_response :success | |
245 | end |
|
245 | end | |
246 |
|
246 | |||
247 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5' |
|
247 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2.5' | |
248 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added' |
|
248 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'should not be added' | |
249 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
249 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
250 | assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id |
|
250 | assert_select 'option[value=?][selected=selected]', TimeEntryActivity.first.id | |
251 | end |
|
251 | end | |
252 | end |
|
252 | end | |
253 |
|
253 | |||
254 | def test_index_should_rescue_invalid_sql_query |
|
254 | def test_index_should_rescue_invalid_sql_query | |
255 | IssueQuery.any_instance.stubs(:statement).returns("INVALID STATEMENT") |
|
255 | IssueQuery.any_instance.stubs(:statement).returns("INVALID STATEMENT") | |
256 |
|
256 | |||
257 | get :index |
|
257 | get :index | |
258 | assert_response 500 |
|
258 | assert_response 500 | |
259 | assert_tag 'p', :content => /An error occurred/ |
|
259 | assert_tag 'p', :content => /An error occurred/ | |
260 | assert_nil session[:query] |
|
260 | assert_nil session[:query] | |
261 | assert_nil session[:issues_index_sort] |
|
261 | assert_nil session[:issues_index_sort] | |
262 | end |
|
262 | end | |
263 | end |
|
263 | end |
General Comments 0
You need to be logged in to leave comments.
Login now