mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Remove fire_event method usage
This commit is contained in:
@@ -47,8 +47,6 @@ class CheckoutController < Spree::StoreController
|
|||||||
params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user)
|
params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user)
|
||||||
return action_failed unless @order.update(params_adapter.params[:order])
|
return action_failed unless @order.update(params_adapter.params[:order])
|
||||||
|
|
||||||
fire_event('spree.checkout.update')
|
|
||||||
|
|
||||||
checkout_workflow(params_adapter.shipping_method_id)
|
checkout_workflow(params_adapter.shipping_method_id)
|
||||||
rescue Spree::Core::GatewayError => e
|
rescue Spree::Core::GatewayError => e
|
||||||
rescue_from_spree_gateway_error(e)
|
rescue_from_spree_gateway_error(e)
|
||||||
|
|||||||
@@ -78,11 +78,7 @@ module Spree
|
|||||||
discard_empty_line_items
|
discard_empty_line_items
|
||||||
with_open_adjustments { update_totals_and_taxes }
|
with_open_adjustments { update_totals_and_taxes }
|
||||||
|
|
||||||
if @order == current_order
|
@order.update_distribution_charge!
|
||||||
fire_event('spree.order.contents_changed')
|
|
||||||
else
|
|
||||||
@order.update_distribution_charge!
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_with(@order) do |format|
|
respond_with(@order) do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
|||||||
@@ -6,11 +6,6 @@ require 'open_food_network/feature_toggle'
|
|||||||
require 'open_food_network/tag_rule_applicator'
|
require 'open_food_network/tag_rule_applicator'
|
||||||
require 'concerns/order_shipment'
|
require 'concerns/order_shipment'
|
||||||
|
|
||||||
ActiveSupport::Notifications
|
|
||||||
.subscribe('spree.order.contents_changed') do |_name, _start, _finish, _id, payload|
|
|
||||||
payload[:order].reload.update_distribution_charge!
|
|
||||||
end
|
|
||||||
|
|
||||||
module Spree
|
module Spree
|
||||||
class Order < ActiveRecord::Base
|
class Order < ActiveRecord::Base
|
||||||
prepend OrderShipment
|
prepend OrderShipment
|
||||||
|
|||||||
@@ -16,20 +16,6 @@ module Spree
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Convenience method for firing instrumentation events with the default payload hash
|
|
||||||
def fire_event(name, extra_payload = {})
|
|
||||||
ActiveSupport::Notifications.instrument(name, default_notification_payload.
|
|
||||||
merge(extra_payload))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates the hash that is sent as the payload for all notifications.
|
|
||||||
# Specific notifications will add additional keys as appropriate.
|
|
||||||
# This method can be overriden to provide additional data when
|
|
||||||
# responding to a notification
|
|
||||||
def default_notification_payload
|
|
||||||
{ user: spree_current_user, order: current_order }
|
|
||||||
end
|
|
||||||
|
|
||||||
# This can be used in views as well as controllers.
|
# This can be used in views as well as controllers.
|
||||||
# e.g. <% self.title = 'This is a custom title for this view' %>
|
# e.g. <% self.title = 'This is a custom title for this view' %>
|
||||||
attr_writer :title
|
attr_writer :title
|
||||||
|
|||||||
@@ -48,12 +48,6 @@ describe CheckoutController, concurrency: true, type: :controller do
|
|||||||
# New threads start running straight away. The breakpoint is after loading
|
# New threads start running straight away. The breakpoint is after loading
|
||||||
# the order and before advancing the order's state and making payments.
|
# the order and before advancing the order's state and making payments.
|
||||||
breakpoint.lock
|
breakpoint.lock
|
||||||
expect(controller).to receive(:fire_event).with("spree.checkout.update") do
|
|
||||||
breakpoint.synchronize {}
|
|
||||||
# This is what fire_event does.
|
|
||||||
# I did not find out how to call the original code otherwise.
|
|
||||||
ActiveSupport::Notifications.instrument("spree.checkout.update")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Starting two checkout threads. The controller code will determine if
|
# Starting two checkout threads. The controller code will determine if
|
||||||
# these two threads are synchronised correctly or run into a race condition.
|
# these two threads are synchronised correctly or run into a race condition.
|
||||||
|
|||||||
Reference in New Issue
Block a user