From 67cd6ea6edd52728eb09aaeb6bb5863d39541c06 Mon Sep 17 00:00:00 2001 From: Feruz Oripov Date: Mon, 26 Feb 2024 23:44:58 +0500 Subject: [PATCH] cops --- app/queries/customers_with_balance_query.rb | 2 +- app/queries/outstanding_balance_query.rb | 2 +- app/queries/payments_requiring_action_query.rb | 2 +- spec/queries/complete_visible_orders_query_spec.rb | 1 + spec/queries/customers_with_balance_query_spec.rb | 3 ++- spec/queries/outstanding_balance_query_spec.rb | 3 ++- spec/queries/payments_requiring_action_query_spec.rb | 5 +++-- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/queries/customers_with_balance_query.rb b/app/queries/customers_with_balance_query.rb index a33b109540..47d0fabca9 100644 --- a/app/queries/customers_with_balance_query.rb +++ b/app/queries/customers_with_balance_query.rb @@ -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 diff --git a/app/queries/outstanding_balance_query.rb b/app/queries/outstanding_balance_query.rb index a0685800fa..c7d37fd62f 100644 --- a/app/queries/outstanding_balance_query.rb +++ b/app/queries/outstanding_balance_query.rb @@ -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 diff --git a/app/queries/payments_requiring_action_query.rb b/app/queries/payments_requiring_action_query.rb index a680b94ddc..c8fe5eda23 100644 --- a/app/queries/payments_requiring_action_query.rb +++ b/app/queries/payments_requiring_action_query.rb @@ -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 diff --git a/spec/queries/complete_visible_orders_query_spec.rb b/spec/queries/complete_visible_orders_query_spec.rb index 61ffc5f733..40b88b10c8 100644 --- a/spec/queries/complete_visible_orders_query_spec.rb +++ b/spec/queries/complete_visible_orders_query_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe CompleteVisibleOrdersQuery do subject { described_class.new(order_permissions).call } + let(:filter_canceled) { false } describe '#call' do diff --git a/spec/queries/customers_with_balance_query_spec.rb b/spec/queries/customers_with_balance_query_spec.rb index 44d24ac14e..6a5de07211 100644 --- a/spec/queries/customers_with_balance_query_spec.rb +++ b/spec/queries/customers_with_balance_query_spec.rb @@ -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 diff --git a/spec/queries/outstanding_balance_query_spec.rb b/spec/queries/outstanding_balance_query_spec.rb index 2af9a2c611..dbad29ec06 100644 --- a/spec/queries/outstanding_balance_query_spec.rb +++ b/spec/queries/outstanding_balance_query_spec.rb @@ -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 diff --git a/spec/queries/payments_requiring_action_query_spec.rb b/spec/queries/payments_requiring_action_query_spec.rb index 8fcde56146..ade23b5528 100644 --- a/spec/queries/payments_requiring_action_query_spec.rb +++ b/spec/queries/payments_requiring_action_query_spec.rb @@ -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