Simplify User.comment_notifiable scope
This commit is contained in:
parent
c9f410e68a
commit
9d4af0dcd3
4 changed files with 8 additions and 10 deletions
|
|
@ -4,9 +4,7 @@ class EventCommentMailJob < ApplicationJob
|
|||
queue_as :default
|
||||
|
||||
def perform(comment)
|
||||
conference = comment.commentable.program.conference
|
||||
|
||||
User.comment_notifiable(conference).each do |user|
|
||||
User.comment_notifiable(comment.conference_id).each do |user|
|
||||
Mailbot.event_comment_mail(comment, user).deliver_now
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -57,13 +57,13 @@ class Comment < ApplicationRecord
|
|||
commentable_str.constantize.find(commentable_id)
|
||||
end
|
||||
|
||||
def conference_id
|
||||
commentable.program.conference_id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_notification
|
||||
EventCommentMailJob.perform_later(self)
|
||||
end
|
||||
|
||||
def conference_id
|
||||
commentable.program.conference_id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class User < ApplicationRecord
|
|||
after_save :touch_events
|
||||
|
||||
# add scope
|
||||
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)}
|
||||
scope :comment_notifiable, ->(conference_id) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference_id)}
|
||||
|
||||
# scopes for user distributions
|
||||
scope :recent, lambda {
|
||||
|
|
|
|||
|
|
@ -88,11 +88,11 @@ describe User do
|
|||
let(:cfp_user) { create(:user, role_ids: [cfp_role.id]) }
|
||||
|
||||
it 'includes organizer and cfp user' do
|
||||
expect(User.comment_notifiable(conference)).to include(organizer, cfp_user)
|
||||
expect(User.comment_notifiable(conference.id)).to include(organizer, cfp_user)
|
||||
end
|
||||
|
||||
it 'excludes ordinary user' do
|
||||
expect(User.comment_notifiable(conference)).not_to include(user)
|
||||
expect(User.comment_notifiable(conference.id)).not_to include(user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue