2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
module NotificationHelpers
|
|
|
|
extend self
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def send_notifications(*new_mentions, current_user: @u_disabled)
|
2018-10-15 14:42:47 +05:30
|
|
|
mentionable.description = new_mentions.map(&:to_reference).join(' ')
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
notification.send(notification_method, mentionable, new_mentions, current_user)
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create_global_setting_for(user, level)
|
|
|
|
setting = user.global_notification_setting
|
|
|
|
setting.level = level
|
2020-10-24 23:57:45 +05:30
|
|
|
setting.save!
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
user
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_user_with_notification(level, username, resource = project)
|
|
|
|
user = create(:user, username: username)
|
2019-07-31 22:56:46 +05:30
|
|
|
create_notification_setting(user, resource, level)
|
|
|
|
|
|
|
|
user
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_notification_setting(user, resource, level)
|
2018-10-15 14:42:47 +05:30
|
|
|
setting = user.notification_settings_for(resource)
|
|
|
|
setting.level = level
|
2020-10-24 23:57:45 +05:30
|
|
|
setting.save!
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# Create custom notifications
|
|
|
|
# When resource is nil it means global notification
|
|
|
|
def update_custom_notification(event, user, resource: nil, value: true)
|
|
|
|
setting = user.notification_settings_for(resource)
|
|
|
|
setting.update!(event => value)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
def expect_delivery_jobs_count(count)
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.exactly(count).times
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def expect_no_delivery_jobs
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(ActionMailer::MailDeliveryJob).not_to have_been_enqueued
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def expect_any_delivery_jobs
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.at_least(:once)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def have_enqueued_email(*args, mailer: "Notify", mail: "", delivery: "deliver_now")
|
2020-07-28 23:09:34 +05:30
|
|
|
have_enqueued_job(ActionMailer::MailDeliveryJob).with(mailer, mail, delivery, args: args)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def expect_enqueud_email(*args, mailer: "Notify", mail: "", delivery: "deliver_now")
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.with(mailer, mail, delivery, args: args)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def expect_not_enqueud_email(*args, mailer: "Notify", mail: "")
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(ActionMailer::MailDeliveryJob).not_to have_been_enqueued.with(mailer, mail, args: any_args)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|