diff --git a/app/models/notification.rb b/app/models/notification.rb index 65ccb84b8..8a786c8fa 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -24,35 +24,4 @@ class Notification < ApplicationRecord def send_message sender.send_message(recipient, body, subject) end - - def migrate_to_mailboxer! - conversation = Mailboxer::ConversationBuilder.new( - subject: subject, - created_at: created_at, - updated_at: updated_at - ).build - - message = Mailboxer::MessageBuilder.new( - sender: sender, - conversation: conversation, - recipients: [recipient], - body: body, - subject: subject, - # attachment: attachment, - created_at: created_at, - updated_at: updated_at - ).build - - notification = Mailboxer::NotificationBuilder.new( - recipients: [recipient], - subject: subject, - body: body, - sender: sender - ).build - - conversation.save! - message.save! - notification.save! - notification.deliver(false, false) - end end diff --git a/db/migrate/20190720000625_notifications_to_mailboxer.rb b/db/migrate/20190720000625_notifications_to_mailboxer.rb index 6e003c44a..1a5d281b6 100644 --- a/db/migrate/20190720000625_notifications_to_mailboxer.rb +++ b/db/migrate/20190720000625_notifications_to_mailboxer.rb @@ -1,9 +1,13 @@ class NotificationsToMailboxer < ActiveRecord::Migration[5.2] def up - Notification.find_in_batches do |group| + Mailboxer.setup do |config| + # turn off emails + config.uses_emails = false + end + Notification.find_in_batches.each do |group| group.each do |n| - next unless n.valid? - n.migrate_to_mailboxer! + n.body = 'message has no body' if n.body.blank? + n.send_message end end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 745a2fb7d..5c9dc4883 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -3,27 +3,6 @@ require 'rails_helper' describe Notification do let(:notification) { FactoryBot.create(:notification) } - describe 'migration to mailboxer' do - let(:body) do - "Hellos - how are you today? - I am fine - - -- me - " - end - let(:sender) { FactoryBot.create :member } - let(:recipient) { FactoryBot.create :member } - let(:notification) do - FactoryBot.create :notification, - subject: 'hello', body: body, - sender: sender, - recipient: recipient - end - before { notification.migrate_to_mailboxer! } - it { expect(recipient.mailbox.inbox.count).to eq 1 } - it { expect(recipient.mailbox.inbox.first.subject).to eq 'hello' } - end it "belongs to a post" do expect(notification.post).to be_an_instance_of Post end