mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
cops
This commit is contained in:
@@ -20,7 +20,7 @@ class CustomersWithBalanceQuery
|
||||
# The resulting orders are in states that belong after the checkout. Only these can be considered
|
||||
# for a customer's balance.
|
||||
def left_join_complete_orders
|
||||
<<~SQL
|
||||
<<~SQL.squish
|
||||
LEFT JOIN spree_orders ON spree_orders.customer_id = customers.id
|
||||
AND #{finalized_states.to_sql}
|
||||
SQL
|
||||
|
||||
@@ -29,7 +29,7 @@ class OutstandingBalanceQuery
|
||||
# Arel doesn't support CASE statements until v7.1.0 so we'll have to wait with SQL literals
|
||||
# a little longer. See https://github.com/rails/arel/pull/400 for details.
|
||||
def statement
|
||||
<<~SQL
|
||||
<<~SQL.squish
|
||||
CASE WHEN "spree_orders"."state" IN #{non_fulfilled_states_group.to_sql} THEN "spree_orders"."payment_total"
|
||||
WHEN "spree_orders"."state" IS NOT NULL THEN "spree_orders"."payment_total" - "spree_orders"."total"
|
||||
ELSE 0 END
|
||||
|
||||
@@ -6,7 +6,7 @@ class PaymentsRequiringActionQuery
|
||||
end
|
||||
|
||||
def call
|
||||
Spree::Payment.joins(:order).where("spree_orders.user_id = ?", user.id).
|
||||
Spree::Payment.joins(:order).where(spree_orders: { user_id: user.id }).
|
||||
requires_authorization
|
||||
end
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ require 'spec_helper'
|
||||
|
||||
describe CompleteVisibleOrdersQuery do
|
||||
subject { described_class.new(order_permissions).call }
|
||||
|
||||
let(:filter_canceled) { false }
|
||||
|
||||
describe '#call' do
|
||||
|
||||
@@ -64,7 +64,8 @@ describe CustomersWithBalanceQuery do
|
||||
context 'when orders are in delivery state' do
|
||||
before do
|
||||
create(:order, customer: customers, total: order_total, payment_total: 0, state: 'delivery')
|
||||
create(:order, customer: customers, total: order_total, payment_total: 50, state: 'delivery')
|
||||
create(:order, customer: customers, total: order_total, payment_total: 50,
|
||||
state: 'delivery')
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
|
||||
@@ -4,6 +4,7 @@ require 'spec_helper'
|
||||
|
||||
describe OutstandingBalanceQuery do
|
||||
subject { described_class.new(relation) }
|
||||
|
||||
let(:result) { subject.call }
|
||||
|
||||
describe '#statement' do
|
||||
@@ -12,7 +13,7 @@ describe OutstandingBalanceQuery do
|
||||
it 'returns the CASE statement necessary to compute the order balance' do
|
||||
normalized_sql_statement = normalize(subject.statement)
|
||||
|
||||
expect(normalized_sql_statement).to eq(normalize(<<-SQL))
|
||||
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"
|
||||
ELSE 0 END
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe PaymentsRequiringActionQuery do
|
||||
subject { described_class.new(user).call }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:order) { create(:order, user:) }
|
||||
subject { described_class.new(user).call }
|
||||
|
||||
describe '#call' do
|
||||
context "payment has a cvv_response_message" do
|
||||
@@ -27,7 +28,7 @@ describe PaymentsRequiringActionQuery do
|
||||
end
|
||||
|
||||
it "does not find the payment" do
|
||||
expect(subject.all).to_not include(payment)
|
||||
expect(subject.all).not_to include(payment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user