Refactor notifiable_available? method
This method was calling `check_availability`, which returned a boolean value and caused a `Naming/PredicateMethod` when upgrading rubocop. So we're changing the logic a little bit to remove the `check_availability` method and merge the tests of `check_availability` and `notifiable_available?` (which were almost identical) together.
This commit is contained in:
@@ -17,20 +17,20 @@ module Notifiable
|
||||
end
|
||||
|
||||
def notifiable_available?
|
||||
case self.class.name
|
||||
when "ProposalNotification"
|
||||
check_availability(proposal)
|
||||
when "Comment"
|
||||
check_availability(commentable)
|
||||
else
|
||||
check_availability(self)
|
||||
end
|
||||
notifiable_resource.present? &&
|
||||
!(notifiable_resource.respond_to?(:hidden?) && notifiable_resource.hidden?) &&
|
||||
!(notifiable_resource.respond_to?(:retired?) && notifiable_resource.retired?)
|
||||
end
|
||||
|
||||
def check_availability(resource)
|
||||
resource.present? &&
|
||||
!(resource.respond_to?(:hidden?) && resource.hidden?) &&
|
||||
!(resource.respond_to?(:retired?) && resource.retired?)
|
||||
def notifiable_resource
|
||||
case self.class.name
|
||||
when "ProposalNotification"
|
||||
proposal
|
||||
when "Comment"
|
||||
commentable
|
||||
else
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
def linkable_resource
|
||||
|
||||
@@ -10,8 +10,7 @@ class Notification < ApplicationRecord
|
||||
scope :recent, -> { order(id: :desc) }
|
||||
scope :for_render, -> { includes(:notifiable) }
|
||||
|
||||
delegate :notifiable_title, :notifiable_body, :notifiable_available?,
|
||||
:check_availability, :linkable_resource,
|
||||
delegate :notifiable_title, :notifiable_body, :notifiable_available?, :linkable_resource,
|
||||
to: :notifiable, allow_nil: true
|
||||
|
||||
def mark_as_read
|
||||
|
||||
Reference in New Issue
Block a user