From 5b27282ab8665120119687cf4ca34953fbfa1bf0 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 30 Jul 2026 12:39:08 +0100 Subject: [PATCH] Prepare to drop the intermediate objects --- app/helpers/notifications_helper.rb | 10 ++++++++++ app/models/user_notifications.rb | 9 --------- app/views/notifications/_changeset_comment.html.erb | 2 +- app/views/notifications/_diary_comment.html.erb | 2 +- app/views/notifications/_gpx_import_failure.html.erb | 2 +- app/views/notifications/_gpx_import_success.html.erb | 2 +- app/views/notifications/_new_follower.html.erb | 2 +- app/views/notifications/_note_comment.html.erb | 2 +- app/views/notifications/_page.html.erb | 8 ++++++-- .../notifications/changeset_comment_view_test.rb | 4 ++-- .../notifications/diary_comment_view_test.rb | 2 +- .../notifications/gpx_import_failure_view_test.rb | 6 +++++- .../notifications/gpx_import_success_view_test.rb | 6 +++++- .../notifications/new_follower_view_test.rb | 2 +- .../notifications/note_comment_view_test.rb | 8 ++++---- 15 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 app/helpers/notifications_helper.rb diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb new file mode 100644 index 000000000..426923946 --- /dev/null +++ b/app/helpers/notifications_helper.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module NotificationsHelper + def partial_path_for_notification(notification) + # Turn "ChangesetCommentNotifier::Notification" into "ChangesetComment" + event_type_name = notification.class.name.sub("Notifier::Notification", "") + + "notifications/#{event_type_name.underscore}" + end +end diff --git a/app/models/user_notifications.rb b/app/models/user_notifications.rb index ee8884d43..6977f348d 100644 --- a/app/models/user_notifications.rb +++ b/app/models/user_notifications.rb @@ -19,11 +19,6 @@ class UserNotifications delegate :record, :to => :@notification - def to_partial_path - event_type_name = self.class.event_type_name_of(@notification) - "notifications/#{event_type_name.underscore}" - end - def timestamp record.created_at end @@ -162,8 +157,4 @@ class UserNotifications NewFollowerNotifier::Notification NoteCommentNotifier::Notification ].freeze - - def self.wrap(notification_records) - notification_records.map { |record| Notification.from(record) } - end end diff --git a/app/views/notifications/_changeset_comment.html.erb b/app/views/notifications/_changeset_comment.html.erb index 8b54fbb9d..d81ba0d7f 100644 --- a/app/views/notifications/_changeset_comment.html.erb +++ b/app/views/notifications/_changeset_comment.html.erb @@ -1,4 +1,4 @@ -<%# locals: (notification:) %> +<%# locals: (notification:, record:) %>
diff --git a/app/views/notifications/_diary_comment.html.erb b/app/views/notifications/_diary_comment.html.erb index 03e41c556..2866f7f2e 100644 --- a/app/views/notifications/_diary_comment.html.erb +++ b/app/views/notifications/_diary_comment.html.erb @@ -1,4 +1,4 @@ -<%# locals: (notification:) %> +<%# locals: (notification:, record:) %>
diff --git a/app/views/notifications/_gpx_import_failure.html.erb b/app/views/notifications/_gpx_import_failure.html.erb index 0cd3a94ab..b3e1d23d9 100644 --- a/app/views/notifications/_gpx_import_failure.html.erb +++ b/app/views/notifications/_gpx_import_failure.html.erb @@ -1,4 +1,4 @@ -<%# locals: (notification:) %> +<%# locals: (notification:, record:) %>
diff --git a/app/views/notifications/_gpx_import_success.html.erb b/app/views/notifications/_gpx_import_success.html.erb index 3da792dd9..4593d4ffd 100644 --- a/app/views/notifications/_gpx_import_success.html.erb +++ b/app/views/notifications/_gpx_import_success.html.erb @@ -1,4 +1,4 @@ -<%# locals: (notification:) %> +<%# locals: (notification:, record:) %>
diff --git a/app/views/notifications/_new_follower.html.erb b/app/views/notifications/_new_follower.html.erb index bade0a97f..6732c6be8 100644 --- a/app/views/notifications/_new_follower.html.erb +++ b/app/views/notifications/_new_follower.html.erb @@ -1,4 +1,4 @@ -<%# locals: (notification:) %> +<%# locals: (notification:, record:) %>
diff --git a/app/views/notifications/_note_comment.html.erb b/app/views/notifications/_note_comment.html.erb index 636f1e03a..e48a9dd0f 100644 --- a/app/views/notifications/_note_comment.html.erb +++ b/app/views/notifications/_note_comment.html.erb @@ -1,4 +1,4 @@ -<%# locals: (notification:) %> +<%# locals: (notification:, record:) %>
diff --git a/app/views/notifications/_page.html.erb b/app/views/notifications/_page.html.erb index b07a5c29c..c1709117b 100644 --- a/app/views/notifications/_page.html.erb +++ b/app/views/notifications/_page.html.erb @@ -1,8 +1,12 @@ <%# locals: (notifications:, params:) %> - <% UserNotifications.wrap(notifications.items).each do |notification| %> - <%= render :partial => notification.to_partial_path, :object => notification, :as => :notification %> + <% notifications.items.each do |notification| %> + <%= render( + partial_path_for_notification(notification), + :notification => UserNotifications::Notification.from(notification), + :record => notification.record + ) %>
<% end %> diff --git a/test/controllers/notifications/changeset_comment_view_test.rb b/test/controllers/notifications/changeset_comment_view_test.rb index 8a82d0ea0..277afe01d 100644 --- a/test/controllers/notifications/changeset_comment_view_test.rb +++ b/test/controllers/notifications/changeset_comment_view_test.rb @@ -12,7 +12,7 @@ module Notifications notification = build_stubbed(:notification, :record => changeset_comment) notification_wrapper = UserNotifications::ChangesetCommentNotification.new(notification) - render "notifications/changeset_comment", :notification => notification_wrapper + render "notifications/changeset_comment", :notification => notification_wrapper, :record => changeset_comment assert_dom ".user-notification" do assert_dom "h2", "Changeset comment" @@ -37,7 +37,7 @@ module Notifications notification = build_stubbed(:notification, :record => changeset_comment) notification_wrapper = UserNotifications::ChangesetCommentNotification.new(notification) - render "notifications/changeset_comment", :notification => notification_wrapper + render "notifications/changeset_comment", :notification => notification_wrapper, :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 749ccb4bf..048893f50 100644 --- a/test/controllers/notifications/diary_comment_view_test.rb +++ b/test/controllers/notifications/diary_comment_view_test.rb @@ -9,7 +9,7 @@ module Notifications notification = build_stubbed(:notification, :record => diary_comment) notification_wrapper = UserNotifications::DiaryCommentNotification.new(notification) - render "notifications/diary_comment", :notification => notification_wrapper + render "notifications/diary_comment", :notification => notification_wrapper, :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 7d3d31c59..15fd28e07 100644 --- a/test/controllers/notifications/gpx_import_failure_view_test.rb +++ b/test/controllers/notifications/gpx_import_failure_view_test.rb @@ -18,7 +18,11 @@ module Notifications notification_wrapper = UserNotifications::GpxImportFailureNotification.new(notification) - render "notifications/gpx_import_failure", :notification => notification_wrapper + render( + "notifications/gpx_import_failure", + :notification => notification_wrapper, + :record => nil + ) assert_dom ".user-notification h2", "GPS trace could not be imported" assert_dom ".user-notification time", "less than 1 minute ago" diff --git a/test/controllers/notifications/gpx_import_success_view_test.rb b/test/controllers/notifications/gpx_import_success_view_test.rb index e1a6b0f37..51a89b4b8 100644 --- a/test/controllers/notifications/gpx_import_success_view_test.rb +++ b/test/controllers/notifications/gpx_import_success_view_test.rb @@ -21,7 +21,11 @@ module Notifications notification_wrapper = UserNotifications::GpxImportSuccessNotification.new(notification) - render "notifications/gpx_import_success", :notification => notification_wrapper + render( + "notifications/gpx_import_success", + :notification => notification_wrapper, + :record => trace + ) assert_dom ".user-notification h2", "GPS trace imported successfully" assert_dom ".user-notification time", "less than 1 minute ago" diff --git a/test/controllers/notifications/new_follower_view_test.rb b/test/controllers/notifications/new_follower_view_test.rb index 535e4f9f5..4bc5e0f6a 100644 --- a/test/controllers/notifications/new_follower_view_test.rb +++ b/test/controllers/notifications/new_follower_view_test.rb @@ -11,7 +11,7 @@ module Notifications notification = build_stubbed(:notification, :record => follow, :notifier_class => NewFollowerNotifier) notification_wrapper = UserNotifications::NewFollowerNotification.new(notification) - render "notifications/new_follower", :notification => notification_wrapper + render "notifications/new_follower", :notification => notification_wrapper, :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 06c466d2e..ab42ab20d 100644 --- a/test/controllers/notifications/note_comment_view_test.rb +++ b/test/controllers/notifications/note_comment_view_test.rb @@ -13,7 +13,7 @@ module Notifications notification = build_stubbed(:notification, :record => note_comment) notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper + render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment assert_dom ".user-notification h2", "Note comment" assert_dom ".user-notification time", "less than 1 minute ago" @@ -35,7 +35,7 @@ module Notifications notification = build_stubbed(:notification, :record => note_comment) notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper + render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment assert_dom ".user-notification h2", "Note resolved" assert_dom ".user-notification time", "less than 1 minute ago" @@ -58,7 +58,7 @@ module Notifications notification = build_stubbed(:notification, :record => note_comment) notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper + render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment assert_dom ".user-notification h2", "Note resolved" assert_dom ".user-notification time", "less than 1 minute ago" @@ -81,7 +81,7 @@ module Notifications notification = build_stubbed(:notification, :record => note_comment) notification_wrapper = UserNotifications::NoteCommentNotification.new(notification) - render "notifications/note_comment", :notification => notification_wrapper + render "notifications/note_comment", :notification => notification_wrapper, :record => note_comment assert_dom ".user-notification h2", "Note reopened" assert_dom ".user-notification time", "less than 1 minute ago" -- 2.47.3