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
use default rails autosave
ulferts18d0450ee9fa
diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rbindex 02111750e37..295f16b2fc2 100644--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb@@ -36,6 +36,7 @@ module Redminemodule ClassMethodsdef acts_as_customizable(options = {})return if included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)+cattr_accessor :customizable_optionsself.customizable_options = options@@ -46,11 +47,13 @@ module Redmine.order("#{CustomField.table_name}.position")}, as: :customized,dependent: :delete_all,- validate: false+ validate: false,+ autosave: truevalidate :validate_custom_valuessend :include, Redmine::Acts::Customizable::InstanceMethods- # Save custom values when saving the customized object- after_save :save_custom_field_values++ before_save :ensure_custom_values_complete+ after_save :reset_custom_values_change_trackerendend@@ -82,7 +85,7 @@ module Redmine# Also supports multiple values for a custom field where# instead of a single value you'd pass an array.def custom_field_values=(values)- return nil unless values.is_a?(Hash) && values.any?+ return unless values.is_a?(Hash) && values.any?@custom_field_values_changed = true@@ -114,7 +117,7 @@ module Redminedef delete_obsolete_custom_values!(existing_custom_values, new_values)existing_custom_values.zip(new_values).each_with_index do |(custom_value, new_value), i|if new_value.nil?- if i == 0+ if i.zero?# leave the first value but set it to nil as that's the behaviour expected# by the original acts_as_customizablecustom_value.value = nil@@ -195,9 +198,11 @@ module Redmineendend- def save_custom_field_values+ def ensure_custom_values_completeself.custom_values = custom_field_values- custom_field_values.each(&:save)+ end++ def reset_custom_values_change_tracker@custom_field_values_changed = false@custom_field_values = nilenddiff --git a/spec/services/projects/update_service_intergration_spec.rb b/spec/services/projects/update_service_intergration_spec.rbindex 5a2363599f9..6c6b0006cb2 100644--- a/spec/services/projects/update_service_intergration_spec.rb+++ b/spec/services/projects/update_service_intergration_spec.rb@@ -68,5 +68,24 @@ describe Projects::UpdateService, 'integration', type: :model do.not_to eql later_updated_atendend++ context 'if a new custom field gets a value assigned' do+ let(:custom_field2) { FactoryBot.create(:text_project_custom_field) }++ let(:attributes) do+ { "custom_field_#{custom_field2.id}" => 'some text' }+ end++ it 'touches the project after saving' do+ former_updated_at = Project.pluck(:updated_on).first++ service_result++ later_updated_at = Project.pluck(:updated_on).first++ expect(former_updated_at)+ .not_to eql later_updated_at+ end+ endendend