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

Replace property + spec with iterator over all_settings

Oliver Günther4abc005ff285
diff --git a/lib/api/v3/user_preferences/notification_setting_representer.rb b/lib/api/v3/user_preferences/notification_setting_representer.rb
index 75066a5a78e..4c49e010696 100644
--- a/lib/api/v3/user_preferences/notification_setting_representer.rb
+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb
@@ -35,23 +35,9 @@ module API
include API::Decorators::LinkedResource
property :channel
- property NotificationSetting::WATCHED
- property NotificationSetting::INVOLVED
- property NotificationSetting::MENTIONED
- property NotificationSetting::WORK_PACKAGE_CREATED
- property NotificationSetting::WORK_PACKAGE_COMMENTED
- property NotificationSetting::WORK_PACKAGE_PROCESSED
- property NotificationSetting::WORK_PACKAGE_PRIORITIZED
- property NotificationSetting::WORK_PACKAGE_SCHEDULED
- property NotificationSetting::NEWS_ADDED
- property NotificationSetting::NEWS_COMMENTED
- property NotificationSetting::DOCUMENT_ADDED
- property NotificationSetting::FORUM_MESSAGES
- property NotificationSetting::WIKI_PAGE_ADDED
- property NotificationSetting::WIKI_PAGE_UPDATED
- property NotificationSetting::MEMBERSHIP_ADDED
- property NotificationSetting::MEMBERSHIP_UPDATED
- property NotificationSetting::ALL
+ NotificationSetting.all_settings.each do |setting|
+ property setting
+ end
associated_resource :project,
skip_render: ->(*) { true },
diff --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.rb
index c6a814d8352..ae77c86e04d 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
@@ -73,40 +73,10 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'
let(:value) { notification_setting.channel }
end
- it_behaves_like 'property', :watched do
- let(:value) { notification_setting.watched }
- end
-
- it_behaves_like 'property', :involved do
- let(:value) { notification_setting.involved }
- end
-
- it_behaves_like 'property', :mentioned do
- let(:value) { notification_setting.mentioned }
- end
-
- it_behaves_like 'property', :all do
- let(:value) { notification_setting.all }
- end
-
- it_behaves_like 'property', :workPackageCommented do
- let(:value) { notification_setting.work_package_commented }
- end
-
- it_behaves_like 'property', :workPackageCreated do
- let(:value) { notification_setting.work_package_created }
- end
-
- it_behaves_like 'property', :workPackageProcessed do
- let(:value) { notification_setting.work_package_processed }
- end
-
- it_behaves_like 'property', :workPackagePrioritized do
- let(:value) { notification_setting.work_package_prioritized }
- end
-
- it_behaves_like 'property', :workPackageScheduled do
- let(:value) { notification_setting.work_package_scheduled }
+ NotificationSetting.all_settings.each do |property|
+ it_behaves_like 'property', property.to_s.camelize(:lower) do
+ let(:value) { notification_setting.send property }
+ end
end
end