mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
cops
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
module Api
|
||||
module Admin
|
||||
# This serializer relies on `object` to respond to `#balance_value`. That's done in
|
||||
# `CustomersWithBalanceQuery` due to the fact that ActiveRecord maps the DB result set's columns to
|
||||
# instance methods. This way, the `balance_value` alias on that class ends up being
|
||||
# `CustomersWithBalanceQuery` due to the fact that ActiveRecord maps the DB result set's
|
||||
# columns to instance methods. This way, the `balance_value` alias on that class ends up being
|
||||
# `object.balance_value` here.
|
||||
class CustomerWithBalanceSerializer < CustomerSerializer
|
||||
attributes :balance, :balance_status
|
||||
|
||||
@@ -9,8 +9,8 @@ module Api
|
||||
|
||||
has_many :payments, serializer: Api::PaymentSerializer
|
||||
|
||||
# This method relies on `balance_value` as a computed DB column. See `CompleteOrdersWithBalanceQuery`
|
||||
# for reference.
|
||||
# This method relies on `balance_value` as a computed DB column.
|
||||
# See `CompleteOrdersWithBalanceQuery` for reference.
|
||||
def outstanding_balance
|
||||
-object.balance_value
|
||||
end
|
||||
|
||||
@@ -18,7 +18,8 @@ module Reporting
|
||||
|
||||
describe "fetching orders" do
|
||||
it 'calls the OutstandingBalanceQuery query object' do
|
||||
outstanding_balance = instance_double(OutstandingBalanceQuery, call: Spree::Order.none)
|
||||
outstanding_balance = instance_double(OutstandingBalanceQuery,
|
||||
call: Spree::Order.none)
|
||||
expect(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
|
||||
|
||||
subject.orders
|
||||
|
||||
@@ -26,9 +26,11 @@ describe CompleteOrdersWithBalanceQuery do
|
||||
|
||||
it 'calls OutstandingBalanceQuery#call' do
|
||||
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
|
||||
expect(outstanding_balance).to receive(:call)
|
||||
allow(outstanding_balance).to receive(:call)
|
||||
|
||||
result
|
||||
|
||||
expect(outstanding_balance).to have_received(:call)
|
||||
end
|
||||
|
||||
it 'returns complete orders including their balance' do
|
||||
@@ -46,9 +48,11 @@ describe CompleteOrdersWithBalanceQuery do
|
||||
|
||||
it 'calls OutstandingBalanceQuery' do
|
||||
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
|
||||
expect(outstanding_balance).to receive(:call)
|
||||
allow(outstanding_balance).to receive(:call)
|
||||
|
||||
result
|
||||
|
||||
expect(outstanding_balance).to have_received(:call)
|
||||
end
|
||||
|
||||
it 'returns an empty array' do
|
||||
|
||||
@@ -9,10 +9,9 @@ describe OutstandingBalanceQuery do
|
||||
|
||||
describe '#statement' do
|
||||
let(:relation) { Spree::Order.none }
|
||||
let(:normalized_sql_statement) { normalize(query.statement) }
|
||||
|
||||
it 'returns the CASE statement necessary to compute the order balance' do
|
||||
normalized_sql_statement = normalize(query.statement)
|
||||
|
||||
expect(normalized_sql_statement).to eq(normalize(<<-SQL.squish))
|
||||
CASE WHEN "spree_orders"."state" IN ('canceled', 'returned') THEN "spree_orders"."payment_total"
|
||||
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
|
||||
|
||||
Reference in New Issue
Block a user