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