mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Cleanup
This commit is contained in:
@@ -16,7 +16,7 @@ module Spree
|
||||
before_action :set_locale
|
||||
|
||||
def show
|
||||
@payments_requiring_action = PaymentsRequiringAction.new(spree_current_user).query
|
||||
@payments_requiring_action = PaymentsRequiringActionQuery.new(spree_current_user).call
|
||||
@orders = orders_collection.includes(:line_items)
|
||||
|
||||
customers = spree_current_user.customers
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PaymentsRequiringAction
|
||||
class PaymentsRequiringActionQuery
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def query
|
||||
def call
|
||||
Spree::Payment.joins(:order).where("spree_orders.user_id = ?", user.id).
|
||||
requires_authorization
|
||||
end
|
||||
@@ -3,7 +3,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe CompleteOrdersWithBalanceQuery do
|
||||
let(:result) { described_class.new(user).call }
|
||||
subject { described_class.new(user).call }
|
||||
|
||||
describe '#call' do
|
||||
let(:user) { order.user }
|
||||
@@ -28,16 +28,16 @@ describe CompleteOrdersWithBalanceQuery do
|
||||
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
|
||||
expect(outstanding_balance).to receive(:call)
|
||||
|
||||
result
|
||||
subject
|
||||
end
|
||||
|
||||
it 'returns complete orders including their balance' do
|
||||
order = result.first
|
||||
order = subject.first
|
||||
expect(order[:balance_value]).to eq(-1.0)
|
||||
end
|
||||
|
||||
it 'sorts them by their completed_at with the most recent first' do
|
||||
expect(result.pluck(:id)).to eq([other_order.id, order.id])
|
||||
expect(subject.pluck(:id)).to eq([other_order.id, order.id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,11 +48,11 @@ describe CompleteOrdersWithBalanceQuery do
|
||||
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
|
||||
expect(outstanding_balance).to receive(:call)
|
||||
|
||||
result
|
||||
subject
|
||||
end
|
||||
|
||||
it 'returns an empty array' do
|
||||
expect(result).to be_empty
|
||||
expect(subject).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe CompleteVisibleOrdersQuery do
|
||||
subject(:result) { described_class.new(order_permissions).call }
|
||||
subject { described_class.new(order_permissions).call }
|
||||
let(:filter_canceled) { false }
|
||||
|
||||
describe '#call' do
|
||||
@@ -20,7 +20,7 @@ describe CompleteVisibleOrdersQuery do
|
||||
let(:cart_order) { create(:order, distributor: enterprise) }
|
||||
|
||||
it 'does not return it' do
|
||||
expect(result).not_to include(cart_order)
|
||||
expect(subject).not_to include(cart_order)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,13 +28,13 @@ describe CompleteVisibleOrdersQuery do
|
||||
let(:complete_order) { create(:order, completed_at: 1.day.ago, distributor: enterprise) }
|
||||
|
||||
it 'does not return it' do
|
||||
expect(result).to include(complete_order)
|
||||
expect(subject).to include(complete_order)
|
||||
end
|
||||
end
|
||||
|
||||
it 'calls #visible_orders' do
|
||||
expect(order_permissions).to receive(:visible_orders).and_call_original
|
||||
result
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe CustomersWithBalanceQuery do
|
||||
subject(:result) { described_class.new(Customer.where(id: customers)).call }
|
||||
subject { described_class.new(Customer.where(id: customers)).call }
|
||||
|
||||
describe '#call' do
|
||||
let(:customers) { create(:customer) }
|
||||
@@ -15,7 +15,7 @@ describe CustomersWithBalanceQuery do
|
||||
allow(OutstandingBalanceQuery).to receive(:new).and_return(outstanding_balance)
|
||||
expect(outstanding_balance).to receive(:statement)
|
||||
|
||||
result
|
||||
subject
|
||||
end
|
||||
|
||||
describe 'arguments' do
|
||||
@@ -23,8 +23,8 @@ describe CustomersWithBalanceQuery do
|
||||
let(:customers) { create_pair(:customer) }
|
||||
|
||||
it 'returns balance' do
|
||||
expect(result.pluck(:id).sort).to eq([customers.first.id, customers.second.id].sort)
|
||||
expect(result.map(&:balance_value)).to eq([0, 0])
|
||||
expect(subject.pluck(:id).sort).to eq([customers.first.id, customers.second.id].sort)
|
||||
expect(subject.map(&:balance_value)).to eq([0, 0])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ describe CustomersWithBalanceQuery do
|
||||
let(:customers) { Customer.none }
|
||||
|
||||
it 'returns empty customers collection' do
|
||||
expect(result).to eq([])
|
||||
expect(subject).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -44,7 +44,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(0)
|
||||
end
|
||||
end
|
||||
@@ -56,7 +56,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(0)
|
||||
end
|
||||
end
|
||||
@@ -68,7 +68,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(0)
|
||||
end
|
||||
end
|
||||
@@ -80,7 +80,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(0)
|
||||
end
|
||||
end
|
||||
@@ -94,7 +94,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(-total)
|
||||
end
|
||||
end
|
||||
@@ -110,7 +110,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
end
|
||||
end
|
||||
@@ -132,7 +132,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(payment_total - non_canceled_orders_total)
|
||||
end
|
||||
end
|
||||
@@ -148,7 +148,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
end
|
||||
end
|
||||
@@ -164,7 +164,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
end
|
||||
end
|
||||
@@ -180,7 +180,7 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(payment_total - total)
|
||||
end
|
||||
end
|
||||
@@ -197,14 +197,14 @@ describe CustomersWithBalanceQuery do
|
||||
end
|
||||
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(payment_total - non_returned_orders_total)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are no orders' do
|
||||
it 'returns the customer balance' do
|
||||
customer = result.first
|
||||
customer = subject.first
|
||||
expect(customer.balance_value).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe PaymentsRequiringAction do
|
||||
describe PaymentsRequiringActionQuery do
|
||||
let(:user) { create(:user) }
|
||||
let(:order) { create(:order, user:) }
|
||||
subject(:payments_requiring_action) { described_class.new(user) }
|
||||
subject { described_class.new(user).call }
|
||||
|
||||
describe '#query' do
|
||||
describe '#call' do
|
||||
context "payment has a cvv_response_message" do
|
||||
let(:payment) do
|
||||
create(:payment,
|
||||
@@ -17,7 +17,7 @@ describe PaymentsRequiringAction do
|
||||
end
|
||||
|
||||
it "finds the payment" do
|
||||
expect(payments_requiring_action.query.all).to include(payment)
|
||||
expect(subject.all).to include(payment)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ describe PaymentsRequiringAction do
|
||||
end
|
||||
|
||||
it "does not find the payment" do
|
||||
expect(payments_requiring_action.query.all).to_not include(payment)
|
||||
expect(subject.all).to_not include(payment)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user