Apply new order directly inside service

This commit is contained in:
François Turbelin
2020-05-24 14:41:40 +02:00
parent cf534237cd
commit b2b988b063
2 changed files with 12 additions and 2 deletions

View File

@@ -7,9 +7,8 @@ class BulkInvoiceService
def start_pdf_job(order_ids)
pdf = CombinePDF.new
orders = Spree::Order.where(id: order_ids)
orders.each do |order|
orders_from(order_ids).each do |order|
invoice = renderer.render_to_string(order)
pdf << CombinePDF.parse(invoice)
@@ -29,6 +28,10 @@ class BulkInvoiceService
private
def orders_from(order_ids)
Spree::Order.where(id: order_ids).order("completed_at DESC")
end
def new_invoice_id
Time.zone.now.to_i.to_s
end

View File

@@ -47,4 +47,11 @@ describe BulkInvoiceService do
expect(filepath).to eq 'tmp/invoices/1234567.pdf'
end
end
describe "#orders_from" do
it "orders with completed desc" do
expect(service.send(:orders_from, [1, 2]).to_sql)
.to include('ORDER BY completed_at DESC')
end
end
end