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
[#43673] fixing specs
Dmitriiee78bd0b8ec3
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rbindex 991a68823d5..4dc8e5614f3 100644--- a/app/models/notification_setting.rb+++ b/app/models/notification_setting.rb@@ -26,18 +26,24 @@ class NotificationSetting < ApplicationRecordASSIGNEE,RESPONSIBLE,MENTIONED,- START_DATE,- DUE_DATE,- OVERDUE,WORK_PACKAGE_CREATED,WORK_PACKAGE_COMMENTED,WORK_PACKAGE_PROCESSED,WORK_PACKAGE_PRIORITIZED,WORK_PACKAGE_SCHEDULED,+ *duration_settings,*email_settings]end+ def self.duration_settings+ [+ START_DATE,+ DUE_DATE,+ OVERDUE+ ]+ end+def self.email_settings[NEWS_ADDED,diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.tsindex 9a79f81da75..af7c28333f2 100644--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts@@ -170,8 +170,8 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin implworkPackageScheduled: notificationSettings.workPackageScheduled,workPackagePrioritized: notificationSettings.workPackagePrioritized,workPackageCommented: notificationSettings.workPackageCommented,- startDate: 24,- dueDate: 24,+ startDate: 'P1D',+ dueDate: 'P1D',overdue: null,};@@ -194,8 +194,8 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin implwikiPageUpdated: false,membershipAdded: false,membershipUpdated: false,- startDate: 24,- dueDate: 24,+ startDate: 'P1D',+ dueDate: 'P1D',overdue: null,}));diff --git a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts b/frontend/src/app/features/user-preferences/state/notification-setting.model.tsindex 3fad0c5ea2f..89c50b396b0 100644--- a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts+++ b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts@@ -19,9 +19,9 @@ export interface INotificationSetting {wikiPageUpdated:boolean;membershipAdded:boolean;membershipUpdated:boolean;- startDate:number|null;- dueDate:number|null;- overdue:number|null;+ startDate:string|null;+ dueDate:string|null;+ overdue:string|null;}export function buildNotificationSetting(project:null|HalSourceLink, params:Partial<INotificationSetting>):INotificationSetting {@@ -49,8 +49,8 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:PartwikiPageUpdated: true,membershipAdded: true,membershipUpdated: true,- startDate: 24,- dueDate: 24,+ startDate: 'P1D',+ dueDate: 'P1D',overdue: null,...params,};diff --git a/lib/api/v3/user_preferences/notification_setting_representer.rb b/lib/api/v3/user_preferences/notification_setting_representer.rbindex 959bcd524b1..44ac5df6f61 100644--- a/lib/api/v3/user_preferences/notification_setting_representer.rb+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb@@ -33,45 +33,28 @@ module APIinclude API::Decorators::LinkedResourceNotificationSetting.all_settings.each do |setting|- property setting+ setting_configuration = {}+ if setting.in?(NotificationSetting.duration_settings)+ setting_configuration = {+ exec_context: :decorator,+ getter: ->(*) do+ datetime_formatter.format_duration_from_hours(represented.send(setting),+ allow_nil: true)+ end,+ setter: ->(fragment:, **) {+ hours = datetime_formatter.parse_duration_to_hours(fragment, setting, allow_nil: true)- property :start_date,- exec_context: :decorator,- getter: ->(*) do- datetime_formatter.format_duration_from_hours(represented.overdue,- allow_nil: true)- end-- property :due_date,- exec_context: :decorator,- getter: ->(*) do- datetime_formatter.format_duration_from_hours(represented.overdue,- allow_nil: true)- end-- property :overdue,- exec_context: :decorator,- getter: ->(*) do- datetime_formatter.format_duration_from_hours(represented.overdue,- allow_nil: true)- end-- def start_date=(value)- represented.start_date = datetime_formatter.parse_duration_to_days(value,- 'start_date',- allow_nil: true)+ send(:"#{setting}=", hours)+ }+ }end- def due_date=(value)- represented.due_date = datetime_formatter.parse_duration_to_days(value,- 'due_date',- allow_nil: true)- end+ property setting, **setting_configuration+ end- def overdue=(value)- represented.overdue = datetime_formatter.parse_duration_to_days(value,- 'startDate',- allow_nil: true)+ NotificationSetting.duration_settings.each do |setting|+ define_method "#{setting}=" do |value|+ represented[setting] = valueendenddiff --git a/spec/lib/api/v3/support/date_time_examples.rb b/spec/lib/api/v3/support/date_time_examples.rbindex 2e88a6a8c59..e4e1d4161d5 100644--- a/spec/lib/api/v3/support/date_time_examples.rb+++ b/spec/lib/api/v3/support/date_time_examples.rb@@ -60,3 +60,20 @@ shared_examples_for 'has UTC ISO 8601 date and time' doexpect(called_with_expected).to be_truthyendend++shared_examples_for 'has ISO 8601 hours only' do+ it 'exists' do+ expect(subject).to have_json_path(json_path)+ end++ it 'indicates date and time as ISO 8601' do+ called_with_expected = false+ expect(::API::V3::Utilities::DateTimeFormatter).to receive(:format_duration_from_hours) do |actual, *_|+ # ActiveSupport flaws :eql? we circumvent that by calling utc (which is equally valid)+ called_with_expected = true if actual.eql? hours+ end.at_least(:once)++ subject # we need to resolve the subject for calls to occur+ expect(called_with_expected).to be_truthy+ end+enddiff --git a/spec/lib/api/v3/support/property_examples.rb b/spec/lib/api/v3/support/property_examples.rbindex 39628914a03..b3152d33520 100644--- a/spec/lib/api/v3/support/property_examples.rb+++ b/spec/lib/api/v3/support/property_examples.rb@@ -55,3 +55,10 @@ shared_examples_for 'datetime property' do |name|let(:date) { value }endend++shared_examples_for 'hours property' do |name|+ it_behaves_like 'has ISO 8601 hours only' do+ let(:json_path) { name.to_s }+ let(:hours) { value }+ end+enddiff --git a/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rbindex 876737709e0..01f36281d96 100644--- a/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb+++ b/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb@@ -70,8 +70,14 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'endNotificationSetting.all_settings.each do |property|- it_behaves_like 'property', property.to_s.camelize(:lower) do- let(:value) { notification_setting.send property }+ if property.in?(NotificationSetting.duration_settings)+ it_behaves_like 'hours property', property.to_s.camelize(:lower) do+ let(:value) { notification_setting.send property }+ end+ else+ it_behaves_like 'property', property.to_s.camelize(:lower) do+ let(:value) { notification_setting.send property }+ endendendend