mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
Add tests
This commit is contained in:
parent
cc0a6c229f
commit
9d74cd5673
2 changed files with 21 additions and 2 deletions
|
@ -2,12 +2,12 @@ class Notification < ActiveRecord::Base
|
|||
include Versions # version/notification_version.rb
|
||||
belongs_to :registrar, required: true
|
||||
|
||||
before_create -> { self.read = false; true }
|
||||
|
||||
scope :unread, -> { where(read: false) }
|
||||
|
||||
validates :text, presence: true
|
||||
|
||||
after_initialize :set_defaults
|
||||
|
||||
def mark_as_read
|
||||
self.read = true
|
||||
save
|
||||
|
@ -17,4 +17,10 @@ class Notification < ActiveRecord::Base
|
|||
def name
|
||||
"-"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_defaults
|
||||
self.read = false if read.nil?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,19 @@ class NotificationTest < ActiveSupport::TestCase
|
|||
assert @notification.invalid?
|
||||
end
|
||||
|
||||
def test_unread_by_default
|
||||
notification = Notification.new(registrar: registrars(:bestnames), text: 'test')
|
||||
assert_not notification.read?
|
||||
|
||||
notification.save!
|
||||
assert_not notification.read?
|
||||
end
|
||||
|
||||
def test_honor_given_read_state
|
||||
notification = Notification.new(read: true)
|
||||
assert notification.read?
|
||||
end
|
||||
|
||||
def test_mark_as_read
|
||||
@notification.mark_as_read
|
||||
@notification.reload
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue