@@ -1,26 +1,26 | |||||
1 | <div class="conflict"> |
|
1 | <div class="conflict"> | |
2 | <%= l(:notice_issue_update_conflict) %> |
|
2 | <%= l(:notice_issue_update_conflict) %> | |
3 | <% if @conflict_journals.present? %> |
|
3 | <% if @conflict_journals.present? %> | |
4 | <div class="conflict-details"> |
|
4 | <div class="conflict-details"> | |
5 | <% @conflict_journals.sort_by(&:id).each do |journal| %> |
|
5 | <% @conflict_journals.sort_by(&:id).each do |journal| %> | |
6 | <p><%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></p> |
|
6 | <p><%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></p> | |
7 | <% if journal.details.any? %> |
|
7 | <% if journal.details.any? %> | |
8 | <ul class="details"> |
|
8 | <ul class="details"> | |
9 | <% details_to_strings(journal.details).each do |string| %> |
|
9 | <% details_to_strings(journal.details).each do |string| %> | |
10 | <li><%= string %></li> |
|
10 | <li><%= string %></li> | |
11 | <% end %> |
|
11 | <% end %> | |
12 | </ul> |
|
12 | </ul> | |
13 | <% end %> |
|
13 | <% end %> | |
14 | <%= textilizable(journal, :notes) unless journal.notes.blank? %> |
|
14 | <%= textilizable(journal, :notes) unless journal.notes.blank? %> | |
15 | <% end %> |
|
15 | <% end %> | |
16 | </div> |
|
16 | </div> | |
17 | <% end %> |
|
17 | <% end %> | |
18 | </div> |
|
18 | </div> | |
19 | <p> |
|
19 | <p> | |
20 | <label><%= radio_button_tag 'conflict_resolution', 'overwrite' %> <%= l(:text_issue_conflict_resolution_overwrite) %></label><br /> |
|
20 | <label><%= radio_button_tag 'conflict_resolution', 'overwrite' %> <%= l(:text_issue_conflict_resolution_overwrite) %></label><br /> | |
21 | <% if @notes.present? %> |
|
21 | <% if @notes.present? %> | |
22 | <label><%= radio_button_tag 'conflict_resolution', 'add_notes' %> <%= l(:text_issue_conflict_resolution_add_notes) %></label><br /> |
|
22 | <label><%= radio_button_tag 'conflict_resolution', 'add_notes' %> <%= l(:text_issue_conflict_resolution_add_notes) %></label><br /> | |
23 | <% end %> |
|
23 | <% end %> | |
24 | <label><%= radio_button_tag 'conflict_resolution', 'cancel' %> <%= l(:text_issue_conflict_resolution_cancel, :link => link_to_issue(@issue, :subject => false)) %></label> |
|
24 | <label><%= radio_button_tag 'conflict_resolution', 'cancel' %> <%= l(:text_issue_conflict_resolution_cancel, :link => link_to_issue(@issue, :subject => false)).html_safe %></label> | |
25 | </p> |
|
25 | </p> | |
26 | <p><%= submit_tag l(:button_submit) %></p> |
|
26 | <p><%= submit_tag l(:button_submit) %></p> |
@@ -1,232 +1,236 | |||||
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 | :lock_version => (issue.lock_version - 1) |
|
65 | :lock_version => (issue.lock_version - 1) | |
66 | }, |
|
66 | }, | |
67 | :notes => 'My notes', |
|
67 | :notes => 'My notes', | |
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 | assert_tag 'div', :attributes => {:class => 'conflict'} |
|
74 | ||
75 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} |
|
75 | assert_select 'div.conflict' | |
76 |
assert_t |
|
76 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'overwrite' | |
77 |
assert_t |
|
77 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'add_notes' | |
|
78 | assert_select 'label' do | |||
|
79 | assert_select 'input[name=?][value=?]', 'conflict_resolution', 'cancel' | |||
|
80 | assert_select 'a[href=/issues/2]' | |||
|
81 | end | |||
78 | end |
|
82 | end | |
79 |
|
83 | |||
80 | def test_update_stale_issue_should_save_attachments |
|
84 | def test_update_stale_issue_should_save_attachments | |
81 | set_tmp_attachments_directory |
|
85 | set_tmp_attachments_directory | |
82 | issue = Issue.find(2) |
|
86 | issue = Issue.find(2) | |
83 | @request.session[:user_id] = 2 |
|
87 | @request.session[:user_id] = 2 | |
84 |
|
88 | |||
85 | assert_no_difference 'Journal.count' do |
|
89 | assert_no_difference 'Journal.count' do | |
86 | assert_no_difference 'TimeEntry.count' do |
|
90 | assert_no_difference 'TimeEntry.count' do | |
87 | assert_difference 'Attachment.count' do |
|
91 | assert_difference 'Attachment.count' do | |
88 | put :update, |
|
92 | put :update, | |
89 | :id => issue.id, |
|
93 | :id => issue.id, | |
90 | :issue => { |
|
94 | :issue => { | |
91 | :fixed_version_id => 4, |
|
95 | :fixed_version_id => 4, | |
92 | :lock_version => (issue.lock_version - 1) |
|
96 | :lock_version => (issue.lock_version - 1) | |
93 | }, |
|
97 | }, | |
94 | :notes => 'My notes', |
|
98 | :notes => 'My notes', | |
95 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, |
|
99 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}, | |
96 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } |
|
100 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id } | |
97 | end |
|
101 | end | |
98 | end |
|
102 | end | |
99 | end |
|
103 | end | |
100 |
|
104 | |||
101 | assert_response :success |
|
105 | assert_response :success | |
102 | assert_template 'edit' |
|
106 | assert_template 'edit' | |
103 | attachment = Attachment.first(:order => 'id DESC') |
|
107 | attachment = Attachment.first(:order => 'id DESC') | |
104 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
108 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
105 | assert_tag 'span', :content => /testfile.txt/ |
|
109 | assert_tag 'span', :content => /testfile.txt/ | |
106 | end |
|
110 | end | |
107 |
|
111 | |||
108 | 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 | |
109 | issue = Issue.find(2) |
|
113 | issue = Issue.find(2) | |
110 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
111 |
|
115 | |||
112 | put :update, :id => issue.id, |
|
116 | put :update, :id => issue.id, | |
113 | :issue => { |
|
117 | :issue => { | |
114 | :fixed_version_id => 4, |
|
118 | :fixed_version_id => 4, | |
115 | :lock_version => (issue.lock_version - 1) |
|
119 | :lock_version => (issue.lock_version - 1) | |
116 | }, |
|
120 | }, | |
117 | :notes => '' |
|
121 | :notes => '' | |
118 |
|
122 | |||
119 | assert_tag 'div', :attributes => {:class => 'conflict'} |
|
123 | assert_tag 'div', :attributes => {:class => 'conflict'} | |
120 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} |
|
124 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'overwrite'} | |
121 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'} |
|
125 | assert_no_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'add_notes'} | |
122 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'} |
|
126 | assert_tag 'input', :attributes => {:name => 'conflict_resolution', :value => 'cancel'} | |
123 |
|
127 | |||
124 | end |
|
128 | end | |
125 |
|
129 | |||
126 | def test_update_stale_issue_should_show_conflicting_journals |
|
130 | def test_update_stale_issue_should_show_conflicting_journals | |
127 | @request.session[:user_id] = 2 |
|
131 | @request.session[:user_id] = 2 | |
128 |
|
132 | |||
129 | put :update, :id => 1, |
|
133 | put :update, :id => 1, | |
130 | :issue => { |
|
134 | :issue => { | |
131 | :fixed_version_id => 4, |
|
135 | :fixed_version_id => 4, | |
132 | :lock_version => 2 |
|
136 | :lock_version => 2 | |
133 | }, |
|
137 | }, | |
134 | :notes => '', |
|
138 | :notes => '', | |
135 | :last_journal_id => 1 |
|
139 | :last_journal_id => 1 | |
136 |
|
140 | |||
137 | assert_not_nil assigns(:conflict_journals) |
|
141 | assert_not_nil assigns(:conflict_journals) | |
138 | assert_equal 1, assigns(:conflict_journals).size |
|
142 | assert_equal 1, assigns(:conflict_journals).size | |
139 | assert_equal 2, assigns(:conflict_journals).first.id |
|
143 | assert_equal 2, assigns(:conflict_journals).first.id | |
140 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
144 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
141 | :descendant => {:content => /Some notes with Redmine links/} |
|
145 | :descendant => {:content => /Some notes with Redmine links/} | |
142 | end |
|
146 | end | |
143 |
|
147 | |||
144 | def test_update_stale_issue_without_previous_journal_should_show_all_journals |
|
148 | def test_update_stale_issue_without_previous_journal_should_show_all_journals | |
145 | @request.session[:user_id] = 2 |
|
149 | @request.session[:user_id] = 2 | |
146 |
|
150 | |||
147 | put :update, :id => 1, |
|
151 | put :update, :id => 1, | |
148 | :issue => { |
|
152 | :issue => { | |
149 | :fixed_version_id => 4, |
|
153 | :fixed_version_id => 4, | |
150 | :lock_version => 2 |
|
154 | :lock_version => 2 | |
151 | }, |
|
155 | }, | |
152 | :notes => '', |
|
156 | :notes => '', | |
153 | :last_journal_id => '' |
|
157 | :last_journal_id => '' | |
154 |
|
158 | |||
155 | assert_not_nil assigns(:conflict_journals) |
|
159 | assert_not_nil assigns(:conflict_journals) | |
156 | assert_equal 2, assigns(:conflict_journals).size |
|
160 | assert_equal 2, assigns(:conflict_journals).size | |
157 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
161 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
158 | :descendant => {:content => /Some notes with Redmine links/} |
|
162 | :descendant => {:content => /Some notes with Redmine links/} | |
159 | assert_tag 'div', :attributes => {:class => 'conflict'}, |
|
163 | assert_tag 'div', :attributes => {:class => 'conflict'}, | |
160 | :descendant => {:content => /Journal notes/} |
|
164 | :descendant => {:content => /Journal notes/} | |
161 | end |
|
165 | end | |
162 |
|
166 | |||
163 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update |
|
167 | def test_update_stale_issue_with_overwrite_conflict_resolution_should_update | |
164 | @request.session[:user_id] = 2 |
|
168 | @request.session[:user_id] = 2 | |
165 |
|
169 | |||
166 | assert_difference 'Journal.count' do |
|
170 | assert_difference 'Journal.count' do | |
167 | put :update, :id => 1, |
|
171 | put :update, :id => 1, | |
168 | :issue => { |
|
172 | :issue => { | |
169 | :fixed_version_id => 4, |
|
173 | :fixed_version_id => 4, | |
170 | :lock_version => 2 |
|
174 | :lock_version => 2 | |
171 | }, |
|
175 | }, | |
172 | :notes => 'overwrite_conflict_resolution', |
|
176 | :notes => 'overwrite_conflict_resolution', | |
173 | :conflict_resolution => 'overwrite' |
|
177 | :conflict_resolution => 'overwrite' | |
174 | end |
|
178 | end | |
175 |
|
179 | |||
176 | assert_response 302 |
|
180 | assert_response 302 | |
177 | issue = Issue.find(1) |
|
181 | issue = Issue.find(1) | |
178 | assert_equal 4, issue.fixed_version_id |
|
182 | assert_equal 4, issue.fixed_version_id | |
179 | journal = Journal.first(:order => 'id DESC') |
|
183 | journal = Journal.first(:order => 'id DESC') | |
180 | assert_equal 'overwrite_conflict_resolution', journal.notes |
|
184 | assert_equal 'overwrite_conflict_resolution', journal.notes | |
181 | assert journal.details.any? |
|
185 | assert journal.details.any? | |
182 | end |
|
186 | end | |
183 |
|
187 | |||
184 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update |
|
188 | def test_update_stale_issue_with_add_notes_conflict_resolution_should_update | |
185 | @request.session[:user_id] = 2 |
|
189 | @request.session[:user_id] = 2 | |
186 |
|
190 | |||
187 | assert_difference 'Journal.count' do |
|
191 | assert_difference 'Journal.count' do | |
188 | put :update, :id => 1, |
|
192 | put :update, :id => 1, | |
189 | :issue => { |
|
193 | :issue => { | |
190 | :fixed_version_id => 4, |
|
194 | :fixed_version_id => 4, | |
191 | :lock_version => 2 |
|
195 | :lock_version => 2 | |
192 | }, |
|
196 | }, | |
193 | :notes => 'add_notes_conflict_resolution', |
|
197 | :notes => 'add_notes_conflict_resolution', | |
194 | :conflict_resolution => 'add_notes' |
|
198 | :conflict_resolution => 'add_notes' | |
195 | end |
|
199 | end | |
196 |
|
200 | |||
197 | assert_response 302 |
|
201 | assert_response 302 | |
198 | issue = Issue.find(1) |
|
202 | issue = Issue.find(1) | |
199 | assert_nil issue.fixed_version_id |
|
203 | assert_nil issue.fixed_version_id | |
200 | journal = Journal.first(:order => 'id DESC') |
|
204 | journal = Journal.first(:order => 'id DESC') | |
201 | assert_equal 'add_notes_conflict_resolution', journal.notes |
|
205 | assert_equal 'add_notes_conflict_resolution', journal.notes | |
202 | assert journal.details.empty? |
|
206 | assert journal.details.empty? | |
203 | end |
|
207 | end | |
204 |
|
208 | |||
205 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating |
|
209 | def test_update_stale_issue_with_cancel_conflict_resolution_should_redirect_without_updating | |
206 | @request.session[:user_id] = 2 |
|
210 | @request.session[:user_id] = 2 | |
207 |
|
211 | |||
208 | assert_no_difference 'Journal.count' do |
|
212 | assert_no_difference 'Journal.count' do | |
209 | put :update, :id => 1, |
|
213 | put :update, :id => 1, | |
210 | :issue => { |
|
214 | :issue => { | |
211 | :fixed_version_id => 4, |
|
215 | :fixed_version_id => 4, | |
212 | :lock_version => 2 |
|
216 | :lock_version => 2 | |
213 | }, |
|
217 | }, | |
214 | :notes => 'add_notes_conflict_resolution', |
|
218 | :notes => 'add_notes_conflict_resolution', | |
215 | :conflict_resolution => 'cancel' |
|
219 | :conflict_resolution => 'cancel' | |
216 | end |
|
220 | end | |
217 |
|
221 | |||
218 | assert_redirected_to '/issues/1' |
|
222 | assert_redirected_to '/issues/1' | |
219 | issue = Issue.find(1) |
|
223 | issue = Issue.find(1) | |
220 | assert_nil issue.fixed_version_id |
|
224 | assert_nil issue.fixed_version_id | |
221 | end |
|
225 | end | |
222 |
|
226 | |||
223 | def test_index_should_rescue_invalid_sql_query |
|
227 | def test_index_should_rescue_invalid_sql_query | |
224 | Query.any_instance.stubs(:statement).returns("INVALID STATEMENT") |
|
228 | Query.any_instance.stubs(:statement).returns("INVALID STATEMENT") | |
225 |
|
229 | |||
226 | get :index |
|
230 | get :index | |
227 | assert_response 500 |
|
231 | assert_response 500 | |
228 | assert_tag 'p', :content => /An error occurred/ |
|
232 | assert_tag 'p', :content => /An error occurred/ | |
229 | assert_nil session[:query] |
|
233 | assert_nil session[:query] | |
230 | assert_nil session[:issues_index_sort] |
|
234 | assert_nil session[:issues_index_sort] | |
231 | end |
|
235 | end | |
232 | end |
|
236 | end |
General Comments 0
You need to be logged in to leave comments.
Login now