Touch the associated record when assigning targets
So the cache will expire properly.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class SDG::Relation < ApplicationRecord
|
class SDG::Relation < ApplicationRecord
|
||||||
validates :related_sdg_id, uniqueness: { scope: [:related_sdg_type, :relatable_id, :relatable_type] }
|
validates :related_sdg_id, uniqueness: { scope: [:related_sdg_type, :relatable_id, :relatable_type] }
|
||||||
|
|
||||||
belongs_to :relatable, polymorphic: true, optional: false
|
belongs_to :relatable, polymorphic: true, optional: false, touch: true
|
||||||
belongs_to :related_sdg, polymorphic: true, optional: false
|
belongs_to :related_sdg, polymorphic: true, optional: false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -159,6 +159,16 @@ describe SDG::Relatable do
|
|||||||
expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], SDG::Goal[3], SDG::Goal[4]]
|
expect(relatable.reload.sdg_goals).to match_array [SDG::Goal[1], SDG::Goal[3], SDG::Goal[4]]
|
||||||
expect(relatable.reload.sdg_targets).to match_array [SDG::Target[1.1], SDG::Target[4.1]]
|
expect(relatable.reload.sdg_targets).to match_array [SDG::Target[1.1], SDG::Target[4.1]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "touches the associated record" do
|
||||||
|
relatable.sdg_related_list = "1.1, 2.1, 2.2"
|
||||||
|
|
||||||
|
travel(10.seconds) do
|
||||||
|
relatable.sdg_related_list = "1.1, 2.1, 2.2, 3.1"
|
||||||
|
|
||||||
|
expect(relatable.updated_at).to eq Time.current
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#sdg_review" do
|
describe "#sdg_review" do
|
||||||
|
|||||||
Reference in New Issue
Block a user