@@ -226,18 +226,26 class Journal < ActiveRecord::Base | |||
|
226 | 226 | def journalize_changes |
|
227 | 227 | # attributes changes |
|
228 | 228 | if @attributes_before_change |
|
229 |
journalized.journalized_attribute_names. |
|
|
229 | attrs = (journalized.journalized_attribute_names + @attributes_before_change.keys).uniq | |
|
230 | attrs.each do |attribute| | |
|
230 | 231 | before = @attributes_before_change[attribute] |
|
231 | 232 | after = journalized.send(attribute) |
|
232 | 233 | next if before == after || (before.blank? && after.blank?) |
|
233 | 234 | add_attribute_detail(attribute, before, after) |
|
234 |
|
|
|
235 | end | |
|
235 | 236 | end |
|
237 | # custom fields changes | |
|
236 | 238 | if @custom_values_before_change |
|
237 | # custom fields changes | |
|
238 | journalized.custom_field_values.each {|c| | |
|
239 |
|
|
|
240 | after = c.value | |
|
239 | values_by_custom_field_id = {} | |
|
240 | @custom_values_before_change.each do |custom_field_id, value| | |
|
241 | values_by_custom_field_id[custom_field_id] = nil | |
|
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 | 249 | next if before == after || (before.blank? && after.blank?) |
|
242 | 250 | |
|
243 | 251 | if before.is_a?(Array) || after.is_a?(Array) |
@@ -246,16 +254,16 class Journal < ActiveRecord::Base | |||
|
246 | 254 | |
|
247 | 255 | # values removed |
|
248 | 256 | (before - after).reject(&:blank?).each do |value| |
|
249 |
add_custom_ |
|
|
257 | add_custom_field_detail(custom_field_id, value, nil) | |
|
250 | 258 | end |
|
251 | 259 | # values added |
|
252 | 260 | (after - before).reject(&:blank?).each do |value| |
|
253 |
add_custom_ |
|
|
261 | add_custom_field_detail(custom_field_id, nil, value) | |
|
254 | 262 | end |
|
255 | 263 | else |
|
256 |
add_custom_ |
|
|
264 | add_custom_field_detail(custom_field_id, before, after) | |
|
257 | 265 | end |
|
258 |
|
|
|
266 | end | |
|
259 | 267 | end |
|
260 | 268 | start |
|
261 | 269 | end |
@@ -266,8 +274,8 class Journal < ActiveRecord::Base | |||
|
266 | 274 | end |
|
267 | 275 | |
|
268 | 276 | # Adds a journal detail for a custom field value change |
|
269 |
def add_custom_ |
|
|
270 |
add_detail('cf', |
|
|
277 | def add_custom_field_detail(custom_field_id, old_value, value) | |
|
278 | add_detail('cf', custom_field_id, old_value, value) | |
|
271 | 279 | end |
|
272 | 280 | |
|
273 | 281 | # Adds a journal detail |
@@ -3342,7 +3342,7 class IssuesControllerTest < Redmine::ControllerTest | |||
|
3342 | 3342 | |
|
3343 | 3343 | with_settings :notified_events => %w(issue_updated) do |
|
3344 | 3344 | assert_difference('Journal.count') do |
|
3345 |
assert_difference('JournalDetail.count', |
|
|
3345 | assert_difference('JournalDetail.count', 3) do | |
|
3346 | 3346 | put :update, :id => 1, :issue => {:project_id => '1', |
|
3347 | 3347 | :tracker_id => '2', |
|
3348 | 3348 | :priority_id => '6' |
@@ -643,7 +643,8 class IssueTest < ActiveSupport::TestCase | |||
|
643 | 643 | assert_nil issue.due_date |
|
644 | 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 | 648 | tracker = Tracker.find(2) |
|
648 | 649 | tracker.core_fields = tracker.core_fields - %w(due_date) |
|
649 | 650 | tracker.save! |
@@ -658,7 +659,8 class IssueTest < ActiveSupport::TestCase | |||
|
658 | 659 | assert_nil issue.due_date |
|
659 | 660 | end |
|
660 | 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 | 664 | end |
|
663 | 665 | |
|
664 | 666 | def test_reload_should_reload_custom_field_values |
@@ -2473,6 +2475,22 class IssueTest < ActiveSupport::TestCase | |||
|
2473 | 2475 | end |
|
2474 | 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 | 2494 | def test_description_eol_should_be_normalized |
|
2477 | 2495 | i = Issue.new(:description => "CR \r LF \n CRLF \r\n") |
|
2478 | 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