mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #6672 from Matt-Yorkley/update-hooks
Delete dead code #update_hooks
This commit is contained in:
@@ -96,9 +96,6 @@ module Spree
|
||||
before_save :update_shipping_fees!, if: :complete?
|
||||
before_save :update_payment_fees!, if: :complete?
|
||||
|
||||
class_attribute :update_hooks
|
||||
self.update_hooks = Set.new
|
||||
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
@@ -157,12 +154,6 @@ module Spree
|
||||
where(completed_at: nil)
|
||||
end
|
||||
|
||||
# Use this method in other gems that wish to register their own custom logic
|
||||
# that should be called after Order#update
|
||||
def self.register_update_hook(hook)
|
||||
update_hooks.add(hook)
|
||||
end
|
||||
|
||||
# For compatiblity with Calculator::PriceSack
|
||||
def amount
|
||||
line_items.inject(0.0) { |sum, li| sum + li.amount }
|
||||
@@ -450,7 +441,6 @@ module Spree
|
||||
updater.update_shipment_state
|
||||
updater.before_save_hook
|
||||
save
|
||||
updater.run_hooks
|
||||
|
||||
deliver_order_confirmation_email
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ module OrderManagement
|
||||
module Order
|
||||
class Updater
|
||||
attr_reader :order
|
||||
delegate :payments, :line_items, :adjustments, :shipments, :update_hooks, to: :order
|
||||
|
||||
delegate :payments, :line_items, :adjustments, :shipments, to: :order
|
||||
|
||||
def initialize(order)
|
||||
@order = order
|
||||
@@ -40,12 +41,6 @@ module OrderManagement
|
||||
payment_total: order.payment_total,
|
||||
total: order.total
|
||||
)
|
||||
|
||||
run_hooks
|
||||
end
|
||||
|
||||
def run_hooks
|
||||
update_hooks.each { |hook| order.__send__(hook) }
|
||||
end
|
||||
|
||||
# Updates the following Order total values:
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
let(:order) { create(:order) }
|
||||
|
||||
context "#update!" do
|
||||
let(:line_items) { [build(:line_item, amount: 5)] }
|
||||
|
||||
context "when there are update hooks" do
|
||||
before { Spree::Order.register_update_hook :foo }
|
||||
after { Spree::Order.update_hooks.clear }
|
||||
it "should call each of the update hooks" do
|
||||
expect(order).to receive :foo
|
||||
order.update!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -436,30 +436,6 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
context "add_update_hook" do
|
||||
before do
|
||||
Spree::Order.class_eval do
|
||||
register_update_hook :add_awesome_sauce
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
Spree::Order.update_hooks = Set.new
|
||||
end
|
||||
|
||||
it "calls hook during update" do
|
||||
order = create(:order)
|
||||
expect(order).to receive(:add_awesome_sauce)
|
||||
order.update!
|
||||
end
|
||||
|
||||
it "calls hook during finalize" do
|
||||
order = create(:order)
|
||||
expect(order).to receive(:add_awesome_sauce)
|
||||
order.finalize!
|
||||
end
|
||||
end
|
||||
|
||||
context "ensure shipments will be updated" do
|
||||
before { Spree::Shipment.create!(order: order) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user