##// END OF EJS Templates
Journalize values that are cleared after project or tracker change (#21623)....
Jean-Philippe Lang -
r15429:55be3ef1727e
parent child
Show More
@@ -226,18 +226,26 class Journal < ActiveRecord::Base
226 def journalize_changes
226 def journalize_changes
227 # attributes changes
227 # attributes changes
228 if @attributes_before_change
228 if @attributes_before_change
229 journalized.journalized_attribute_names.each {|attribute|
229 attrs = (journalized.journalized_attribute_names + @attributes_before_change.keys).uniq
230 attrs.each do |attribute|
230 before = @attributes_before_change[attribute]
231 before = @attributes_before_change[attribute]
231 after = journalized.send(attribute)
232 after = journalized.send(attribute)
232 next if before == after || (before.blank? && after.blank?)
233 next if before == after || (before.blank? && after.blank?)
233 add_attribute_detail(attribute, before, after)
234 add_attribute_detail(attribute, before, after)
234 }
235 end
235 end
236 end
237 # custom fields changes
236 if @custom_values_before_change
238 if @custom_values_before_change
237 # custom fields changes
239 values_by_custom_field_id = {}
238 journalized.custom_field_values.each {|c|
240 @custom_values_before_change.each do |custom_field_id, value|
239 before = @custom_values_before_change[c.custom_field_id]
241 values_by_custom_field_id[custom_field_id] = nil
240 after = c.value
242 end
243 journalized.custom_field_values.each do |c|
244 values_by_custom_field_id[c.custom_field_id] = c.value
245 end
246
247 values_by_custom_field_id.each do |custom_field_id, after|
248 before = @custom_values_before_change[custom_field_id]
241 next if before == after || (before.blank? && after.blank?)
249 next if before == after || (before.blank? && after.blank?)
242
250
243 if before.is_a?(Array) || after.is_a?(Array)
251 if before.is_a?(Array) || after.is_a?(Array)
@@ -246,16 +254,16 class Journal < ActiveRecord::Base
246
254
247 # values removed
255 # values removed
248 (before - after).reject(&:blank?).each do |value|
256 (before - after).reject(&:blank?).each do |value|
249 add_custom_value_detail(c, value, nil)
257 add_custom_field_detail(custom_field_id, value, nil)
250 end
258 end
251 # values added
259 # values added
252 (after - before).reject(&:blank?).each do |value|
260 (after - before).reject(&:blank?).each do |value|
253 add_custom_value_detail(c, nil, value)
261 add_custom_field_detail(custom_field_id, nil, value)
254 end
262 end
255 else
263 else
256 add_custom_value_detail(c, before, after)
264 add_custom_field_detail(custom_field_id, before, after)
257 end
265 end
258 }
266 end
259 end
267 end
260 start
268 start
261 end
269 end
@@ -266,8 +274,8 class Journal < ActiveRecord::Base
266 end
274 end
267
275
268 # Adds a journal detail for a custom field value change
276 # Adds a journal detail for a custom field value change
269 def add_custom_value_detail(custom_value, old_value, value)
277 def add_custom_field_detail(custom_field_id, old_value, value)
270 add_detail('cf', custom_value.custom_field_id, old_value, value)
278 add_detail('cf', custom_field_id, old_value, value)
271 end
279 end
272
280
273 # Adds a journal detail
281 # Adds a journal detail
@@ -3342,7 +3342,7 class IssuesControllerTest < Redmine::ControllerTest
3342
3342
3343 with_settings :notified_events => %w(issue_updated) do
3343 with_settings :notified_events => %w(issue_updated) do
3344 assert_difference('Journal.count') do
3344 assert_difference('Journal.count') do
3345 assert_difference('JournalDetail.count', 2) do
3345 assert_difference('JournalDetail.count', 3) do
3346 put :update, :id => 1, :issue => {:project_id => '1',
3346 put :update, :id => 1, :issue => {:project_id => '1',
3347 :tracker_id => '2',
3347 :tracker_id => '2',
3348 :priority_id => '6'
3348 :priority_id => '6'
@@ -643,7 +643,8 class IssueTest < ActiveSupport::TestCase
643 assert_nil issue.due_date
643 assert_nil issue.due_date
644 end
644 end
645
645
646 def test_changing_tracker_should_not_add_cleared_fields_to_journal
646 def test_attribute_cleared_on_tracker_change_should_be_journalized
647 CustomField.delete_all
647 tracker = Tracker.find(2)
648 tracker = Tracker.find(2)
648 tracker.core_fields = tracker.core_fields - %w(due_date)
649 tracker.core_fields = tracker.core_fields - %w(due_date)
649 tracker.save!
650 tracker.save!
@@ -658,7 +659,8 class IssueTest < ActiveSupport::TestCase
658 assert_nil issue.due_date
659 assert_nil issue.due_date
659 end
660 end
660 journal = Journal.order('id DESC').first
661 journal = Journal.order('id DESC').first
661 assert_equal 1, journal.details.count
662 details = journal.details.select {|d| d.prop_key == 'due_date'}
663 assert_equal 1, details.count
662 end
664 end
663
665
664 def test_reload_should_reload_custom_field_values
666 def test_reload_should_reload_custom_field_values
@@ -2473,6 +2475,22 class IssueTest < ActiveSupport::TestCase
2473 end
2475 end
2474 end
2476 end
2475
2477
2478 def test_custom_value_cleared_on_tracker_change_should_be_journalized
2479 a = IssueCustomField.generate!(:tracker_ids => [1])
2480 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {a.id.to_s => "foo"})
2481 assert_equal "foo", issue.custom_field_value(a)
2482
2483 journal = new_record(Journal) do
2484 issue.init_journal(User.first)
2485 issue.tracker_id = 2
2486 issue.save!
2487 end
2488 details = journal.details.select {|d| d.property == 'cf' && d.prop_key == a.id.to_s}
2489 assert_equal 1, details.size
2490 assert_equal 'foo', details.first.old_value
2491 assert_nil details.first.value
2492 end
2493
2476 def test_description_eol_should_be_normalized
2494 def test_description_eol_should_be_normalized
2477 i = Issue.new(:description => "CR \r LF \n CRLF \r\n")
2495 i = Issue.new(:description => "CR \r LF \n CRLF \r\n")
2478 assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description
2496 assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description
General Comments 0
You need to be logged in to leave comments. Login now