From 7889efd6ee8f84afc06dd75fa28796702c6b82f2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 20 Dec 2017 12:43:49 +0100 Subject: [PATCH] Fix map location update When editing the map of a proposal or investment(the mappable) the updated_at attribute of the mappable was not been updated and so the map still displayed the old location after updating it --- app/models/map_location.rb | 4 ++-- spec/shared/models/map_validations.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/map_location.rb b/app/models/map_location.rb index 14e91d92c..42fb8ab2f 100644 --- a/app/models/map_location.rb +++ b/app/models/map_location.rb @@ -1,7 +1,7 @@ class MapLocation < ActiveRecord::Base - belongs_to :proposal - belongs_to :investment, class_name: Budget::Investment + belongs_to :proposal, touch: true + belongs_to :investment, class_name: Budget::Investment, touch: true def available? latitude.present? && longitude.present? && zoom.present? diff --git a/spec/shared/models/map_validations.rb b/spec/shared/models/map_validations.rb index f9adb638f..2ce1af79c 100644 --- a/spec/shared/models/map_validations.rb +++ b/spec/shared/models/map_validations.rb @@ -2,7 +2,7 @@ shared_examples "map validations" do let(:mappable) { build(model_name(described_class)) } - describe "map" do + describe "validations" do before(:each) do Setting["feature.map"] = true @@ -49,5 +49,17 @@ shared_examples "map validations" do end end + describe "cache" do + + it "should expire cache when the map is updated" do + map_location = create(:map_location) + mappable.map_location = map_location + mappable.save + + expect { map_location.update(latitude: 12.34) } + .to change { mappable.reload.updated_at } + end + + end end \ No newline at end of file