Skip to content

Commit

Permalink
Do not test on order total value to go to payment state
Browse files Browse the repository at this point in the history
  • Loading branch information
jibees committed May 11, 2023
1 parent 2836751 commit 2890b29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/models/spree/order.rb
Expand Up @@ -22,7 +22,7 @@ class Order < ApplicationRecord
go_to_state :delivery
go_to_state :payment, if: ->(order) {
order.update_totals
order.payment_required?
!order.skip_payment_for_subscription?
}
go_to_state :confirmation, if: ->(order) {
OpenFoodNetwork::FeatureToggle.enabled? :split_checkout, order.created_by
Expand Down Expand Up @@ -208,6 +208,10 @@ def payment_required?
total.to_f > 0.0 && !skip_payment_for_subscription?
end

def skip_payment_for_subscription?
subscription.present? && order_cycle.orders_close_at&.>(Time.zone.now)
end

# Returns the relevant zone (if any) to be used for taxation purposes.
# Uses default tax zone unless there is a specific match
def tax_zone
Expand Down Expand Up @@ -701,10 +705,6 @@ def adjustments_fetcher
@adjustments_fetcher ||= OrderAdjustmentsFetcher.new(self)
end

def skip_payment_for_subscription?
subscription.present? && order_cycle.orders_close_at&.>(Time.zone.now)
end

def require_customer?
persisted? && state != "cart"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/spree/order/checkout_spec.rb
Expand Up @@ -34,7 +34,7 @@

context "#checkout_steps" do
context "when payment not required" do
before { allow(order).to receive_messages payment_required?: false }
before { allow(order).to receive_messages skip_payment_for_subscription?: true }
specify do
expect(order.checkout_steps).to eq %w(address delivery complete)
end
Expand Down Expand Up @@ -109,7 +109,7 @@

context "without payment required" do
before do
allow(order).to receive_messages payment_required?: false
allow(order).to receive_messages skip_payment_for_subscription?: true
end

it "transitions to complete" do
Expand Down

0 comments on commit 2890b29

Please sign in to comment.