Skip to content

Commit

Permalink
Fix fatal error in reports helper for orders without payments
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Yorkley committed Jun 11, 2020
1 parent ca45801 commit e84e0ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/helpers/spree/reports_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ def report_order_cycle_options(order_cycles)
end

def report_payment_method_options(orders)
orders.map do |o|
pm = o.payments.first.payment_method
[pm.andand.name, pm.andand.id]
end.uniq
orders.map do |order|
payment_method = order.payments.first.andand.payment_method

next unless payment_method

[payment_method.name, payment_method.id]
end.compact.uniq
end

def report_shipping_method_options(orders)
Expand Down
25 changes: 25 additions & 0 deletions spec/helpers/spree/admin/reports_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'spec_helper'


describe Spree::ReportsHelper, type: :helper do
describe "#report_payment_method_options" do
let(:order_with_payments) { create(:order_ready_to_ship) }
let(:order_without_payments) { create(:order_with_line_items) }
let(:orders) { [order_with_payments, order_without_payments] }
let(:payment_method) { order_with_payments.payments.first.payment_method }

it "returns payment method select options for given orders" do
select_options = helper.report_payment_method_options([order_with_payments])

expect(select_options).to eq [[payment_method.name, payment_method.id]]
end

it "handles orders that don't have payments, without error" do
select_options = helper.report_payment_method_options(orders)

expect(select_options).to eq [[payment_method.name, payment_method.id]]
end
end
end

0 comments on commit e84e0ae

Please sign in to comment.