mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove Adjustment#set_eligibility
This commit is contained in:
@@ -87,16 +87,6 @@ module Spree
|
||||
|
||||
localize_number :amount
|
||||
|
||||
# Update the boolean _eligible_ attribute which determines which adjustments
|
||||
# count towards the order's adjustment_total.
|
||||
def set_eligibility
|
||||
result = mandatory || amount != 0
|
||||
update_columns(
|
||||
eligible: result,
|
||||
updated_at: Time.zone.now
|
||||
)
|
||||
end
|
||||
|
||||
# Update both the eligibility and amount of the adjustment. Adjustments
|
||||
# delegate updating of amount to their Originator when present, but only if
|
||||
# +locked+ is false. Adjustments that are +locked+ will never change their amount.
|
||||
@@ -119,7 +109,6 @@ module Spree
|
||||
# the order object. After calling a reload, the source is the Shipment.
|
||||
reload
|
||||
originator.update_adjustment(self, calculable || source) if originator.present?
|
||||
set_eligibility
|
||||
end
|
||||
|
||||
def currency
|
||||
|
||||
@@ -24,6 +24,7 @@ describe Spree::Admin::OrdersController, type: :controller do
|
||||
:adjustment,
|
||||
adjustable: order,
|
||||
label: "invalid adjustment",
|
||||
eligible: false,
|
||||
amount: 0
|
||||
)
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@ describe Admin::OrdersHelper, type: :helper do
|
||||
expect(helper.order_adjustments_for_display(order)).to eq []
|
||||
end
|
||||
|
||||
it "filters zero tax rate adjustments" do
|
||||
create(:adjustment, adjustable: order, amount: 0, originator_type: "Spree::TaxRate")
|
||||
it "filters ineligible adjustments" do
|
||||
create(:adjustment, adjustable: order, amount: 0, eligible: false,
|
||||
originator_type: "Spree::TaxRate")
|
||||
|
||||
expect(helper.order_adjustments_for_display(order)).to eq []
|
||||
end
|
||||
|
||||
@@ -36,11 +36,6 @@ module Spree
|
||||
adjustment.update!
|
||||
end
|
||||
|
||||
it "should set the eligibility" do
|
||||
expect(adjustment).to receive(:set_eligibility)
|
||||
adjustment.update!
|
||||
end
|
||||
|
||||
it "should ask the originator to update_adjustment" do
|
||||
expect(originator).to receive(:update_adjustment)
|
||||
adjustment.update!
|
||||
@@ -68,33 +63,6 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
context "#eligible? after #set_eligibility" do
|
||||
context "when amount is 0" do
|
||||
before { adjustment.amount = 0 }
|
||||
it "should be eligible if mandatory?" do
|
||||
adjustment.mandatory = true
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to be_eligible
|
||||
end
|
||||
|
||||
it "should not be eligible unless mandatory?" do
|
||||
adjustment.mandatory = false
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to_not be_eligible
|
||||
end
|
||||
end
|
||||
|
||||
context "when amount is greater than 0" do
|
||||
before { adjustment.amount = 25.00 }
|
||||
|
||||
it "should be eligible if mandatory?" do
|
||||
adjustment.mandatory = true
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to be_eligible
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#save" do
|
||||
it "should call order#update!" do
|
||||
adjustment = Spree::Adjustment.new(
|
||||
|
||||
Reference in New Issue
Block a user