Migration of notifications to mailboxer, without sending new emails

This commit is contained in:
Brenda Wallace committed 2019-08-10 17:30:24 +12:00
1 parent d76c77d176
commit 083d7c09e6
2 files changed
+24 -2

No files matched your search

+2
View File
@@ -4,6 +4,8 @@ class Notification < ApplicationRecord
belongs_to :post, optional: true
validates :subject, length: { maximum: 255 }
validates :subject, presence: true
validates :body, presence: true
scope :unread, -> { where(read: false) }
scope :by_recipient, ->(recipient) { where(recipient_id: recipient) }
@@ -1,7 +1,27 @@
class NotificationsToMailboxer < ActiveRecord::Migration[5.2]
def change
def up
Notification.all.each do |n|
n.sender.send_message(n.recipient, n.body, n.subject)
next unless n.valid?
conversation = Mailboxer::ConversationBuilder.new(
subject: n.subject,
created_at: n.created_at,
updated_at: n.updated_at
).build
message = Mailboxer::MessageBuilder.new(
sender: n.sender,
conversation: conversation,
recipients: [n.recipient],
body: n.body,
subject: n.subject,
# attachment: attachment,
created_at: n.created_at,
updated_at: n.updated_at
).build
conversation.save!
message.save!
end
end
end