From 412641cdb093f9e2476da9dede938d11a9a1d9eb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 24 Aug 2018 14:34:44 +0300 Subject: [PATCH] Disallow marking a notification as read again --- app/models/notification.rb | 1 + test/models/notification_test.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/models/notification.rb b/app/models/notification.rb index 1e9dfa3dd..0b1829267 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -9,6 +9,7 @@ class Notification < ActiveRecord::Base after_initialize :set_defaults def mark_as_read + raise 'Read notification cannot be marked as read again' if read? self.read = true save end diff --git a/test/models/notification_test.rb b/test/models/notification_test.rb index bfd577fb9..3db685e0c 100644 --- a/test/models/notification_test.rb +++ b/test/models/notification_test.rb @@ -32,4 +32,11 @@ class NotificationTest < ActiveSupport::TestCase @notification.reload assert @notification.read? end + + def test_read_notification_cannot_be_marked_as_read_again + @notification.mark_as_read + assert_raises do + @notification.mark_as_read + end + end end \ No newline at end of file