DataDump#email_json_dump tests
parent
efa2f8bcfd
commit
0dfeff0777
|
@ -1,17 +1,22 @@
|
|||
class DataDumpMailer < ApplicationMailer
|
||||
SUBJECT = "FarmBot Account Data Export"
|
||||
SUBJECT = "FarmBot Account Data Export"
|
||||
EXPORT_MIME_TYPE = "application/json"
|
||||
EXPORT_FILENAME = "export.json"
|
||||
|
||||
attr_reader :device
|
||||
|
||||
def email_json_dump(device)
|
||||
@device = device
|
||||
attachments['export.json'] = {
|
||||
mime_type: 'application/mymimetype',
|
||||
content: Devices::Dump.run!(device: device).to_json
|
||||
}
|
||||
@device = device
|
||||
attachments[EXPORT_FILENAME] = \
|
||||
{ mime_type: EXPORT_MIME_TYPE, content: export_data }
|
||||
mail to: recipients, subject: SUBJECT
|
||||
end
|
||||
|
||||
def recipients
|
||||
@recipients ||= device.users.pluck(:email)
|
||||
end
|
||||
|
||||
def export_data
|
||||
@export_data ||= Devices::Dump.run!(device: device).to_json
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,11 +7,18 @@ describe Api::DevicesController do
|
|||
describe '#dump' do
|
||||
it 'queues the creation of an account backup' do
|
||||
sign_in user
|
||||
wow = double("WOW", run_by_id: nil)
|
||||
expect(wow).to receive(:run_by_id)
|
||||
expect(Devices::Dump).to receive(:delay).and_return(wow).once
|
||||
post :dump, params: {}, session: { format: :json }
|
||||
empty_mail_bag
|
||||
run_jobs_now do
|
||||
post :dump, params: {}, session: { format: :json }
|
||||
end
|
||||
expect(response.status).to eq(200)
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
expect(mail).to be_kind_of(Mail::Message)
|
||||
expect(mail.to).to include(user.email)
|
||||
expect(mail.subject).to eq(DataDumpMailer::SUBJECT)
|
||||
expect(mail.attachments.count).to eq(1)
|
||||
expect(mail.attachments.first.filename)
|
||||
.to eq(DataDumpMailer::EXPORT_FILENAME)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require "rails_helper"
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe DataDumpMailer, type: :mailer do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe DataDumpMailer, type: :mailer do
|
||||
it 'sends a JSON file to users'
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Devices::Dump do
|
|||
resources = MODEL_NAMES
|
||||
.map { |x| x.to_s.singularize.to_sym }
|
||||
.map { |x| FactoryBot.create_list(x, 4, device: device) }
|
||||
results = Devices::Dump.run!(device_id: device.id)
|
||||
results = Devices::Dump.run!(device: device)
|
||||
MODEL_NAMES
|
||||
.concat(SPECIAL)
|
||||
.without(:device, :plants, :tool_slots, :generic_pointers)
|
||||
|
|
Loading…
Reference in New Issue