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

Don't use implicitly build boolean custom_values for change detection

Christophe Bliard28d54fd72fff
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 34ca86925f7..f47932f69ee 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -62,7 +62,7 @@ class CustomValue < ApplicationRecord
end
def default?
- value == custom_field.default_value
+ custom_field.cast_value(value) == custom_field.default_value
end
protected
diff --git a/spec/models/work_package/work_package_acts_as_customizable_spec.rb b/spec/models/work_package/work_package_acts_as_customizable_spec.rb
index a3f0b9a89b3..0c9a42624ae 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
@@ -146,5 +146,16 @@ describe WorkPackage, 'acts_as_customizable' do
expect(model_instance.custom_field_changes).to be_empty
end
end
+
+ context 'with a bool custom_field having a default value' do
+ before do
+ custom_field.update! field_format: 'bool', default_value: '0'
+ model_instance.custom_values.destroy_all
+ end
+
+ it 'returns no changes' do
+ expect(model_instance.custom_field_changes).to be_empty
+ end
+ end
end
end