mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +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
|
include Versions # version/notification_version.rb
|
||||||
belongs_to :registrar, required: true
|
belongs_to :registrar, required: true
|
||||||
|
|
||||||
before_create -> { self.read = false; true }
|
|
||||||
|
|
||||||
scope :unread, -> { where(read: false) }
|
scope :unread, -> { where(read: false) }
|
||||||
|
|
||||||
validates :text, presence: true
|
validates :text, presence: true
|
||||||
|
|
||||||
|
after_initialize :set_defaults
|
||||||
|
|
||||||
def mark_as_read
|
def mark_as_read
|
||||||
self.read = true
|
self.read = true
|
||||||
save
|
save
|
||||||
|
@ -17,4 +17,10 @@ class Notification < ActiveRecord::Base
|
||||||
def name
|
def name
|
||||||
"-"
|
"-"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_defaults
|
||||||
|
self.read = false if read.nil?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,19 @@ class NotificationTest < ActiveSupport::TestCase
|
||||||
assert @notification.invalid?
|
assert @notification.invalid?
|
||||||
end
|
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
|
def test_mark_as_read
|
||||||
@notification.mark_as_read
|
@notification.mark_as_read
|
||||||
@notification.reload
|
@notification.reload
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue