forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications_common.rb
More file actions
37 lines (30 loc) · 1.07 KB
/
Copy pathnotifications_common.rb
File metadata and controls
37 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'rake'
module NotificationsCommon
def setup_comm_channel(user, path = 'test@example.com', path_type = 'email')
@channel = user.communication_channels.create(path: path, path_type: path_type)
@channel.confirm
end
def setup_notification(user, params = {})
default_params = {
name: 'Conversation Message',
category: 'TestImmediately',
frequency: 'immediately',
sms: false,
}
params = default_params.merge(params)
n = Notification.create!(name: params[:name], category: params[:category])
# we don't send notifications to sms channels automatically so will need a policy set up for that if sms is chosen
if params[:sms] == true
NotificationPolicy.create!(
notification: n,
communication_channel: user.communication_channel,
frequency: params[:frequency]
)
end
end
def load_all_notifications
load File.expand_path("../../../../lib/tasks/db_load_data.rake", __FILE__)
Rake::Task.define_task(:environment)
Rake::Task["db:load_notifications"].invoke
end
end