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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Don't use implicitly build custom_values for change detection
Oliver Günther39c7e8e51f9d
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rbindex 4a754132fc2..47571448c22 100644--- a/app/models/custom_value.rb+++ b/app/models/custom_value.rb@@ -61,6 +61,10 @@ class CustomValue < ApplicationRecordendend+ def default?+ value == custom_field.default_value+ end+protecteddef validate_presence_of_required_valuediff --git a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rbindex 722a9f2889d..4d50c786e49 100644--- a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb+++ b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb@@ -256,6 +256,9 @@ module Redmine# Skip when the old value equals the new value (no change happened).next cfv_changes if value_was == cfv.value+ # Skip when the new value is the default value+ next cfv_changes if value_was.nil? && cfv.default?+cfv_changes.merge("custom_field_#{cfv.custom_field_id}": [value_was, cfv.value])endenddiff --git a/spec/models/work_package/work_package_acts_as_customizable_spec.rb b/spec/models/work_package/work_package_acts_as_customizable_spec.rbindex 6ce4144292d..0bdba6a4e2e 100644--- a/spec/models/work_package/work_package_acts_as_customizable_spec.rb+++ b/spec/models/work_package/work_package_acts_as_customizable_spec.rb@@ -135,5 +135,16 @@ describe WorkPackage, 'acts_as_customizable' dobefore dosetup_custom_field(custom_field)end++ context 'with a default value' do+ before do+ custom_field.update! default_value: 'foobar'+ model_instance.custom_values.destroy_all+ end++ it 'returns no changes' do+ expect(model_instance.custom_field_changes).to be_empty+ end+ endendend