mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Merge pull request #7236 from Matt-Yorkley/exchange-deadlocks
Update Exchange touch on Enterprise to use #touch_later
This commit is contained in:
@@ -12,7 +12,7 @@ class Exchange < ActiveRecord::Base
|
||||
|
||||
belongs_to :order_cycle
|
||||
belongs_to :sender, class_name: 'Enterprise'
|
||||
belongs_to :receiver, class_name: 'Enterprise', touch: true
|
||||
belongs_to :receiver, class_name: 'Enterprise'
|
||||
|
||||
has_many :exchange_variants, dependent: :destroy
|
||||
has_many :variants, through: :exchange_variants
|
||||
@@ -23,6 +23,8 @@ class Exchange < ActiveRecord::Base
|
||||
validates :order_cycle, :sender, :receiver, presence: true
|
||||
validates :sender_id, uniqueness: { scope: [:order_cycle_id, :receiver_id, :incoming] }
|
||||
|
||||
after_save :touch_receiver
|
||||
|
||||
accepts_nested_attributes_for :variants
|
||||
|
||||
scope :in_order_cycle, lambda { |order_cycle| where(order_cycle_id: order_cycle) }
|
||||
@@ -95,4 +97,10 @@ class Exchange < ActiveRecord::Base
|
||||
def participant
|
||||
incoming? ? sender : receiver
|
||||
end
|
||||
|
||||
def touch_receiver
|
||||
return unless receiver&.persisted?
|
||||
|
||||
receiver.touch_later
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,6 +92,13 @@ describe Enterprise do
|
||||
enterprise.reload
|
||||
}.to change { enterprise.updated_at }
|
||||
end
|
||||
|
||||
it "touches enterprise when a relevant exchange is updated" do
|
||||
expect {
|
||||
oc.exchanges.first.update!(updated_at: Time.zone.now)
|
||||
enterprise.reload
|
||||
}.to change { enterprise.updated_at }
|
||||
end
|
||||
end
|
||||
|
||||
it "touches enterprise when the product's variant is added to order cycle" do
|
||||
|
||||
Reference in New Issue
Block a user