Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix displaying deleted custom field values

Dombi Attilaa87148f29d30
diff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
index fbfe65915b8..86f7fad034a 100644
--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/journable_differ.rb
@@ -38,8 +38,8 @@ module Acts::Journalized
.with_indifferent_access
end
- def association_changes(original, changed, *association_params)
- get_association_changes(original, changed, *association_params)
+ def association_changes(original, changed, *)
+ get_association_changes(original, changed, *)
end
private
@@ -90,12 +90,12 @@ module Acts::Journalized
def added_references(merged_references)
merged_references
- .select { |_, (old_value, new_value)| old_value.nil? && new_value.present? }
+ .select { |_, (old_value, new_value)| old_value.to_s.empty? && new_value.present? }
end
def removed_references(merged_references)
merged_references
- .select { |_, (old_value, new_value)| old_value.present? && new_value.nil? }
+ .select { |_, (old_value, new_value)| old_value.present? && new_value.to_s.empty? }
end
def changed_references(merged_references)
diff --git a/spec/features/work_packages/table/baseline/baseline_rendering_spec.rb b/spec/features/work_packages/table/baseline/baseline_rendering_spec.rb
index 891bcb2fda4..36078fd81f0 100644
--- a/spec/features/work_packages/table/baseline/baseline_rendering_spec.rb
+++ b/spec/features/work_packages/table/baseline/baseline_rendering_spec.rb
@@ -209,9 +209,9 @@ RSpec.describe 'baseline rendering',
int_wp_custom_field.id => 1,
string_wp_custom_field.id => 'this is a string',
bool_wp_custom_field.id => true,
- float_wp_custom_field.id => 2.9,
+ float_wp_custom_field.id => nil,
date_wp_custom_field.id => Date.yesterday,
- list_wp_custom_field.id => list_wp_custom_field.possible_values.first,
+ list_wp_custom_field.id => nil,
multi_list_wp_custom_field.id => multi_list_wp_custom_field.possible_values, # not working
user_wp_custom_field.id => [assignee.id.to_s],
version_wp_custom_field.id => version_a
@@ -220,14 +220,14 @@ RSpec.describe 'baseline rendering',
shared_let(:changed_custom_values) do
{
- "custom_field_#{int_wp_custom_field.id}": 2,
+ "custom_field_#{int_wp_custom_field.id}": nil,
"custom_field_#{string_wp_custom_field.id}": 'this is a changed string',
"custom_field_#{bool_wp_custom_field.id}": false,
"custom_field_#{float_wp_custom_field.id}": 3.7,
"custom_field_#{date_wp_custom_field.id}": Time.zone.today,
"custom_field_#{list_wp_custom_field.id}": [list_wp_custom_field.possible_values.second],
"custom_field_#{multi_list_wp_custom_field.id}": multi_list_wp_custom_field.possible_values.take(2),
- "custom_field_#{user_wp_custom_field.id}": [user.id.to_s],
+ "custom_field_#{user_wp_custom_field.id}": nil,
"custom_field_#{version_wp_custom_field.id}": version_b
}
end
@@ -328,7 +328,7 @@ RSpec.describe 'baseline rendering',
baseline.expect_changed_attributes wp_task_cf,
"customField#{int_wp_custom_field.id}": [
'1',
- '2'
+ '-'
],
"customField#{string_wp_custom_field.id}": [
'this is a string',
@@ -339,7 +339,7 @@ RSpec.describe 'baseline rendering',
'no'
],
"customField#{float_wp_custom_field.id}": [
- '2.9',
+ '-',
'3.7'
],
"customField#{date_wp_custom_field.id}": [
@@ -347,8 +347,8 @@ RSpec.describe 'baseline rendering',
Time.zone.today.iso8601
],
"customField#{list_wp_custom_field.id}": [
- list_wp_custom_field.possible_values.first.value,
- list_wp_custom_field.possible_values.second.value
+ "-",
+ "B"
],
"customField#{multi_list_wp_custom_field.id}": [
"A, B, ...\n7",
@@ -356,7 +356,7 @@ RSpec.describe 'baseline rendering',
],
"customField#{user_wp_custom_field.id}": [
'Assigned User',
- 'Itsa Me'
+ '-'
],
"customField#{version_wp_custom_field.id}": [
'Version A',
diff --git a/spec/lib/acts_as_journalized/journable_differ_spec.rb b/spec/lib/acts_as_journalized/journable_differ_spec.rb
index 8f84fd58738..fb93bb9d6a9 100644
--- a/spec/lib/acts_as_journalized/journable_differ_spec.rb
+++ b/spec/lib/acts_as_journalized/journable_differ_spec.rb
@@ -74,7 +74,7 @@ RSpec.describe Acts::Journalized::JournableDiffer do
status_id: 45,
schedule_manually: nil,
ignore_non_working_days: false,
- estimated_hours: 1)
+ estimated_hours: nil)
end
let(:changed) do
build_stubbed(:journal_work_package_journal,
@@ -86,7 +86,7 @@ RSpec.describe Acts::Journalized::JournableDiffer do
status_id: original.status_id + 12,
schedule_manually: false,
ignore_non_working_days: true,
- estimated_hours: nil)
+ estimated_hours: 1)
end
it 'returns the changes' do
@@ -97,7 +97,38 @@ RSpec.describe Acts::Journalized::JournableDiffer do
"status_id" => [original.status_id, changed.status_id],
"schedule_manually" => [nil, false],
"ignore_non_working_days" => [false, true],
- "estimated_hours" => [1.0, nil])
+ "estimated_hours" => [nil, 1.0])
+ end
+ end
+ end
+
+ describe '.association_changes' do
+ context 'when the objects are work packages' do
+ let(:original) do
+ build(:work_package,
+ custom_values: [
+ build_stubbed(:work_package_custom_value, custom_field_id: 1, value: 1),
+ build_stubbed(:work_package_custom_value, custom_field_id: 2, value: nil),
+ build_stubbed(:work_package_custom_value, custom_field_id: 3, value: "")
+ ])
+ end
+
+ let(:changed) do
+ build(:work_package,
+ custom_values: [
+ build_stubbed(:work_package_custom_value, custom_field_id: 1, value: ""),
+ build_stubbed(:work_package_custom_value, custom_field_id: 2, value: ""),
+ build_stubbed(:work_package_custom_value, custom_field_id: 3, value: 2)
+ ])
+ end
+
+ it 'returns the changes' do
+ params = [original, changed, 'custom_values', 'custom_field', :custom_field_id, :value]
+ expect(described_class.association_changes(*params))
+ .to eql(
+ "custom_field_1" => ["1", ""],
+ "custom_field_3" => ["", "2"]
+ )
end
end
end