From 39c7e8e51f9d0e12c9f450333e79b4bb0facdb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 11 Jan 2023 08:55:15 +0100 Subject: [PATCH 1/2] Don't use implicitly build custom_values for change detection --- app/models/custom_value.rb | 4 ++++ .../acts_as_customizable/lib/acts_as_customizable.rb | 3 +++ .../work_package_acts_as_customizable_spec.rb | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb index 4a754132fc..47571448c2 100644 --- a/app/models/custom_value.rb +++ b/app/models/custom_value.rb @@ -61,6 +61,10 @@ class CustomValue < ApplicationRecord end end + def default? + value == custom_field.default_value + end + protected def validate_presence_of_required_value diff --git a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb index 722a9f2889..4d50c786e4 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]) end end 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 6ce4144292..0bdba6a4e2 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' do before do setup_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 + end end end From 29bebde81fc9704c4fdbc9f021f461f92ce72304 Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Tue, 29 Nov 2022 15:49:06 +0200 Subject: [PATCH 2/2] [#45057] Week calculations on the gannt chart are incorrect in tests https://community.openproject.org/work_packages/45057 --- .../work_packages/timeline/timeline_dates_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/features/work_packages/timeline/timeline_dates_spec.rb b/spec/features/work_packages/timeline/timeline_dates_spec.rb index bc186f8e11..34c8743180 100644 --- a/spec/features/work_packages/timeline/timeline_dates_spec.rb +++ b/spec/features/work_packages/timeline/timeline_dates_spec.rb @@ -149,10 +149,14 @@ RSpec.describe 'Work package timeline date formatting', expect(page).to have_selector('.wp-timeline--header-element', text: '01') expect(page).to have_selector('.wp-timeline--header-element', text: '02') - # Most years do not have 53 weeks. Some do. - unless Date.current.beginning_of_year.saturday? - expect(page).not_to have_selector('.wp-timeline--header-element', text: '53') - end + # According to the Canadian locale (https://savvytime.com/week-number/canada/2022) + # the first week of the year is the week where 1st of January falls. + # If that is last year, then we need to add an offset +1 week to the total number of years. + current_year = Date.current.year + week_offset = current_year - Date.new(current_year, 1, 1).beginning_of_week.year + + weeks_this_year = Date.new(current_year, 12, 28).cweek + week_offset + expect(page).not_to have_selector('.wp-timeline--header-element', text: weeks_this_year + 1) # expect moment to return week 01 for start date and due date expect_date_week work_package.start_date.iso8601, '01'