diff --git a/app/models/spree/address_decorator.rb b/app/models/spree/address_decorator.rb index 28f292fbd3..8797a91599 100644 --- a/app/models/spree/address_decorator.rb +++ b/app/models/spree/address_decorator.rb @@ -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. diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 3ef46f1724..23aa2a7458 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -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 diff --git a/spec/models/enterprise_caching_spec.rb b/spec/models/enterprise_caching_spec.rb index 51ed68aace..72b356df21 100644 --- a/spec/models/enterprise_caching_spec.rb +++ b/spec/models/enterprise_caching_spec.rb @@ -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