diff --git a/app/controllers/notifications/bulk_readings_controller.rb b/app/controllers/notifications/bulk_readings_controller.rb
new file mode 100644
index 000000000..71b387101
--- /dev/null
+++ b/app/controllers/notifications/bulk_readings_controller.rb
@@ -0,0 +1,5 @@
+class Notifications::BulkReadingsController < ApplicationController
+ def create
+ Current.user.notifications.unread.read_all
+ end
+end
diff --git a/app/controllers/notifications/readings_controller.rb b/app/controllers/notifications/readings_controller.rb
index 3ea6a28dd..2accc3373 100644
--- a/app/controllers/notifications/readings_controller.rb
+++ b/app/controllers/notifications/readings_controller.rb
@@ -1,19 +1,11 @@
class Notifications::ReadingsController < ApplicationController
def create
- @notification = Current.user.notifications.find(params[:id])
+ @notification = Current.user.notifications.find(params[:notification_id])
@notification.read
end
def destroy
- @notification = Current.user.notifications.find(params[:id])
+ @notification = Current.user.notifications.find(params[:notification_id])
@notification.unread
end
-
- def create_all
- Current.user.notifications.unread.read_all
- respond_to do |format|
- format.html { redirect_to notifications_path }
- format.turbo_stream { } # No action needed, readings will have been broadcast
- end
- end
end
diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb
index 3c7f3d0e0..cd9e005a9 100644
--- a/app/helpers/notifications_helper.rb
+++ b/app/helpers/notifications_helper.rb
@@ -38,7 +38,7 @@ module NotificationsHelper
def notification_toggle_read_button(notification)
if notification.read?
- button_to read_notification_path(notification),
+ button_to notification_reading_path(notification),
method: :delete,
class: "card__notification-unread-indicator btn btn--circle borderless",
title: "Mark as unread",
@@ -48,7 +48,7 @@ module NotificationsHelper
concat(tag.span("Mark as unread", class: "for-screen-reader"))
end
else
- button_to read_notification_path(notification),
+ button_to notification_reading_path(notification),
class: "card__notification-unread-indicator btn btn--circle borderless",
title: "Mark as read",
data: { action: "form#submit:stop badge#update:stop", form_target: "submit" },
diff --git a/app/views/notifications/_tray.html.erb b/app/views/notifications/_tray.html.erb
index 048730ff2..a009835a4 100644
--- a/app/views/notifications/_tray.html.erb
+++ b/app/views/notifications/_tray.html.erb
@@ -28,7 +28,7 @@
<% end %>
- <%= button_to read_all_notifications_path,
+ <%= button_to bulk_reading_path,
class: "btn borderless tray__clear-notifications",
title: "Mark all notifications as read",
data: { action: "dialog#close badge#clear", turbo_frame: "notifications" },
diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb
index c30e46d7c..18a4f31b0 100644
--- a/app/views/notifications/index.html.erb
+++ b/app/views/notifications/index.html.erb
@@ -19,7 +19,7 @@
<% if @unread.any? %>
New for you
- <%= button_to "Mark all as read", read_all_notifications_path, class: "btn txt-small", form: { data: { turbo: false } }, data: { action: "badge#clear" } %>
+ <%= button_to "Mark all as read", bulk_reading_path, class: "btn txt-small", form: { data: { turbo: false } }, data: { action: "badge#clear" } %>
<% else %>
diff --git a/config/routes.rb b/config/routes.rb
index 554545c2f..bc4e7ae14 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -60,9 +60,11 @@ Rails.application.routes.draw do
scope module: :notifications do
get "tray", to: "trays#show", on: :collection
- post "readings", to: "readings#create_all", on: :collection, as: :read_all
- post "reading", to: "readings#create", on: :member, as: :read
- delete "reading", to: "readings#destroy", on: :member
+ collection do
+ resource :bulk_reading, only: :create
+ end
+
+ resource :reading, only: %i[ create destroy ]
end
end
diff --git a/test/controllers/notifications/bulk_readings_controller_test.rb b/test/controllers/notifications/bulk_readings_controller_test.rb
new file mode 100644
index 000000000..405d1f4a0
--- /dev/null
+++ b/test/controllers/notifications/bulk_readings_controller_test.rb
@@ -0,0 +1,15 @@
+require "test_helper"
+
+class Notifications::BulkReadingsControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ sign_in_as :kevin
+ end
+
+ test "create" do
+ assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do
+ assert_changes -> { notifications(:layout_commented_kevin).reload.read? }, from: false, to: true do
+ post bulk_reading_path
+ end
+ end
+ end
+end
diff --git a/test/controllers/notifications/readings_controller_test.rb b/test/controllers/notifications/readings_controller_test.rb
index cdbca89ce..f25d77ccc 100644
--- a/test/controllers/notifications/readings_controller_test.rb
+++ b/test/controllers/notifications/readings_controller_test.rb
@@ -7,7 +7,7 @@ class Notifications::ReadingsControllerTest < ActionDispatch::IntegrationTest
test "create" do
assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do
- post read_notification_path(notifications(:logo_published_kevin), format: :turbo_stream)
+ post notification_reading_path(notifications(:logo_published_kevin), format: :turbo_stream)
assert_response :success
end
end
@@ -17,17 +17,8 @@ class Notifications::ReadingsControllerTest < ActionDispatch::IntegrationTest
notification.read # Mark as read first
assert_changes -> { notification.reload.read? }, from: true, to: false do
- delete read_notification_path(notification, format: :turbo_stream)
+ delete notification_reading_path(notification, format: :turbo_stream)
assert_response :success
end
end
-
- test "create all" do
- assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do
- assert_changes -> { notifications(:layout_commented_kevin).reload.read? }, from: false, to: true do
- post read_all_notifications_path
- assert_redirected_to notifications_path
- end
- end
- end
end