From e69f3f1549ff0eca5464b8e4382ecb8302207ba1 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 30 Jul 2026 14:29:29 +0100 Subject: [PATCH] Remove intermediary now that it's not used --- app/controllers/notifications_controller.rb | 11 +++- app/models/user_notifications.rb | 55 ------------------- app/views/notifications/_page.html.erb | 2 +- .../changeset_comment_view_test.rb | 14 +++-- .../notifications/diary_comment_view_test.rb | 7 ++- .../gpx_import_failure_view_test.rb | 4 +- .../gpx_import_success_view_test.rb | 4 +- .../notifications/new_follower_view_test.rb | 7 ++- .../notifications/note_comment_view_test.rb | 28 +++++++--- 9 files changed, 53 insertions(+), 79 deletions(-) delete mode 100644 app/models/user_notifications.rb diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index f8da88677..dc860c873 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -3,6 +3,15 @@ class NotificationsController < ApplicationController include PaginationMethods + LISTABLE_NOTIFICATIONS = %w[ + ChangesetCommentNotifier::Notification + DiaryCommentNotifier::Notification + GpxImportFailureNotifier::Notification + GpxImportSuccessNotifier::Notification + NewFollowerNotifier::Notification + NoteCommentNotifier::Notification + ].freeze + layout :site_layout before_action :authorize_web @@ -13,7 +22,7 @@ class NotificationsController < ApplicationController before_action :check_database_readable def index - notifications = current_user.notifications.where(:type => UserNotifications::LISTABLE_NOTIFICATIONS) + notifications = current_user.notifications.where(:type => LISTABLE_NOTIFICATIONS) @notifications = get_page_items(notifications) @params = params.permit end diff --git a/app/models/user_notifications.rb b/app/models/user_notifications.rb deleted file mode 100644 index ca09b2faa..000000000 --- a/app/models/user_notifications.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -class UserNotifications - class Notification - def self.from(notification) - event_type_name = event_type_name_of(notification) - klass = "UserNotifications::#{event_type_name}Notification".constantize - klass.new(notification) - end - - # Takes "ChangesetCommentNotifier::Notification", returns "ChangesetComment" - def self.event_type_name_of(notification) - notification.class.name.sub("Notifier::Notification", "") - end - - def initialize(notification) - @notification = notification - end - - delegate :record, :to => :@notification - - def timestamp - record.created_at - end - end - - class ChangesetCommentNotification < Notification - end - - class DiaryCommentNotification < Notification - end - - class GpxImportFailureNotification < Notification - delegate :params, :created_at, :to => :@notification - end - - class GpxImportSuccessNotification < Notification - delegate :params, :to => :@notification - end - - class NewFollowerNotification < Notification - end - - class NoteCommentNotification < Notification - end - - LISTABLE_NOTIFICATIONS = %w[ - ChangesetCommentNotifier::Notification - DiaryCommentNotifier::Notification - GpxImportFailureNotifier::Notification - GpxImportSuccessNotifier::Notification - NewFollowerNotifier::Notification - NoteCommentNotifier::Notification - ].freeze -end diff --git a/app/views/notifications/_page.html.erb b/app/views/notifications/_page.html.erb index c1709117b..924083218 100644 --- a/app/views/notifications/_page.html.erb +++ b/app/views/notifications/_page.html.erb @@ -4,7 +4,7 @@ <% notifications.items.each do |notification| %> <%= render( partial_path_for_notification(notification), - :notification => UserNotifications::Notification.from(notification), + :notification => notification, :record => notification.record ) %>
diff --git a/test/controllers/notifications/changeset_comment_view_test.rb b/test/controllers/notifications/changeset_comment_view_test.rb index 277afe01d..de49c46d8 100644 --- a/test/controllers/notifications/changeset_comment_view_test.rb +++ b/test/controllers/notifications/changeset_comment_view_test.rb @@ -10,9 +10,12 @@ module Notifications :body => "Insightful comment" ) notification = build_stubbed(:notification, :record => changeset_comment) - notification_wrapper = UserNotifications::ChangesetCommentNotification.new(notification) - render "notifications/changeset_comment", :notification => notification_wrapper, :record => changeset_comment + render( + "notifications/changeset_comment", + :notification => notification, + :record => changeset_comment + ) assert_dom ".user-notification" do assert_dom "h2", "Changeset comment" @@ -35,9 +38,12 @@ module Notifications :body => "Insightful comment" ) notification = build_stubbed(:notification, :record => changeset_comment) - notification_wrapper = UserNotifications::ChangesetCommentNotification.new(notification) - render "notifications/changeset_comment", :notification => notification_wrapper, :record => changeset_comment + render( + "notifications/changeset_comment", + :notification => notification, + :record => changeset_comment + ) assert_dom ".user-notification" do assert_dom "h2", "Changeset comment" diff --git a/test/controllers/notifications/diary_comment_view_test.rb b/test/controllers/notifications/diary_comment_view_test.rb index 048893f50..d14b4d2b7 100644 --- a/test/controllers/notifications/diary_comment_view_test.rb +++ b/test/controllers/notifications/diary_comment_view_test.rb @@ -7,9 +7,12 @@ module Notifications def test_render diary_comment = build_stubbed(:diary_comment) notification = build_stubbed(:notification, :record => diary_comment) - notification_wrapper = UserNotifications::DiaryCommentNotification.new(notification) - render "notifications/diary_comment", :notification => notification_wrapper, :record => diary_comment + render( + "notifications/diary_comment", + :notification => notification, + :record => diary_comment + ) assert_dom ".user-notification h2", "Diary comment" assert_dom ".user-notification time", "less than 1 minute ago" diff --git a/test/controllers/notifications/gpx_import_failure_view_test.rb b/test/controllers/notifications/gpx_import_failure_view_test.rb index 15fd28e07..c027ef635 100644 --- a/test/controllers/notifications/gpx_import_failure_view_test.rb +++ b/test/controllers/notifications/gpx_import_failure_view_test.rb @@ -16,11 +16,9 @@ module Notifications } ) - notification_wrapper = UserNotifications::GpxImportFailureNotification.new(notification) - render( "notifications/gpx_import_failure", - :notification => notification_wrapper, + :notification => notification, :record => nil ) diff --git a/test/controllers/notifications/gpx_import_success_view_test.rb b/test/controllers/notifications/gpx_import_success_view_test.rb index 51a89b4b8..50e912431 100644 --- a/test/controllers/notifications/gpx_import_success_view_test.rb +++ b/test/controllers/notifications/gpx_import_success_view_test.rb @@ -19,11 +19,9 @@ module Notifications } ) - notification_wrapper = UserNotifications::GpxImportSuccessNotification.new(notification) - render( "notifications/gpx_import_success", - :notification => notification_wrapper, + :notification => notification, :record => trace ) diff --git a/test/controllers/notifications/new_follower_view_test.rb b/test/controllers/notifications/new_follower_view_test.rb index 4bc5e0f6a..5a85b94ee 100644 --- a/test/controllers/notifications/new_follower_view_test.rb +++ b/test/controllers/notifications/new_follower_view_test.rb @@ -9,9 +9,12 @@ module Notifications follow = build_stubbed(:follow, :follower => follower) notification = build_stubbed(:notification, :record => follow, :notifier_class => NewFollowerNotifier) - notification_wrapper = UserNotifications::NewFollowerNotification.new(notification) - render "notifications/new_follower", :notification => notification_wrapper, :record => follow + render( + "notifications/new_follower", + :notification => notification, + :record => follow + ) assert_dom ".user-notification h2", "New follower" assert_dom ".user-notification time", "less than 1 minute ago" diff --git a/test/controllers/notifications/note_comment_view_test.rb b/test/controllers/notifications/note_comment_view_test.rb index ab42ab20d..7175dc6a5 100644 --- a/test/controllers/notifications/note_comment_view_test.rb +++ b/test/controllers/notifications/note_comment_view_test.rb @@ -11,9 +11,12 @@ module Notifications :event => "commented" ) notification = build_stubbed(:notification, :record => note_comment) - notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment + render( + "notifications/note_comment", + :notification => notification, + :record => note_comment + ) assert_dom ".user-notification h2", "Note comment" assert_dom ".user-notification time", "less than 1 minute ago" @@ -33,9 +36,12 @@ module Notifications :event => "closed" ) notification = build_stubbed(:notification, :record => note_comment) - notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment + render( + "notifications/note_comment", + :notification => notification, + :record => note_comment + ) assert_dom ".user-notification h2", "Note resolved" assert_dom ".user-notification time", "less than 1 minute ago" @@ -56,9 +62,12 @@ module Notifications :body => "" ) notification = build_stubbed(:notification, :record => note_comment) - notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment + render( + "notifications/note_comment", + :notification => notification, + :record => note_comment + ) assert_dom ".user-notification h2", "Note resolved" assert_dom ".user-notification time", "less than 1 minute ago" @@ -79,9 +88,12 @@ module Notifications :body => "" ) notification = build_stubbed(:notification, :record => note_comment) - notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment + render( + "notifications/note_comment", + :notification => notification, + :record => note_comment + ) assert_dom ".user-notification h2", "Note reopened" assert_dom ".user-notification time", "less than 1 minute ago" -- 2.47.3