Disallow marking a notification as read again

This commit is contained in:
Artur Beljajev 2018-08-24 14:34:44 +03:00
parent 1183d06c09
commit 412641cdb0
2 changed files with 8 additions and 0 deletions

View file

@ -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

View file

@ -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