mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Caching address and touching enterprise on save
This commit is contained in:
@@ -2,6 +2,8 @@ Spree::Address.class_eval do
|
||||
has_one :enterprise
|
||||
belongs_to :country, class_name: "Spree::Country"
|
||||
|
||||
after_save :touch_enterprise
|
||||
|
||||
geocoded_by :full_address
|
||||
|
||||
delegate :name, :to => :state, :prefix => true, :allow_nil => true
|
||||
@@ -15,6 +17,10 @@ Spree::Address.class_eval do
|
||||
|
||||
private
|
||||
|
||||
def touch_enterprise
|
||||
enterprise.andand.touch
|
||||
end
|
||||
|
||||
# We have a hard-to-track-down bug around invalid addresses with all-nil fields finding
|
||||
# their way into the database. I don't know what the source of them is, so this patch
|
||||
# is designed to track them down.
|
||||
|
||||
@@ -18,7 +18,6 @@ end
|
||||
|
||||
class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :orders_close_at, :active
|
||||
has_one :address, serializer: Api::AddressSerializer
|
||||
|
||||
def orders_close_at
|
||||
OrderCycle.first_closing_for(object).andand.orders_close_at
|
||||
@@ -44,6 +43,8 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
has_many :distributors, key: :hubs, serializer: Api::IdSerializer
|
||||
has_many :suppliers, key: :producers, serializer: Api::IdSerializer
|
||||
|
||||
#has_one :address, serializer: Api::AddressSerializer
|
||||
|
||||
def pickup
|
||||
object.shipping_methods.where(:require_ship_address => false).present?
|
||||
end
|
||||
|
||||
@@ -46,6 +46,10 @@ describe Enterprise do
|
||||
expect{sm.save!}.to change {enterprise.reload.updated_at }
|
||||
end
|
||||
end
|
||||
|
||||
it "touches enterprise when address is updated" do
|
||||
expect{enterprise.address.save!}.to change {enterprise.reload.updated_at }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user