Expire cache when adding documents and images

Proposals and budget investments were not correctly updated when adding,
removing or modifying their documents and images.
This commit is contained in:
Javi Martín
2021-09-14 16:40:33 +02:00
parent 288ae13958
commit f7b83319c6
4 changed files with 10 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ class Document < ApplicationRecord
hash_secret: Rails.application.secrets.secret_key_base hash_secret: Rails.application.secrets.secret_key_base
belongs_to :user belongs_to :user
belongs_to :documentable, polymorphic: true belongs_to :documentable, polymorphic: true, touch: true
validates :title, presence: true validates :title, presence: true
validates :user_id, presence: true validates :user_id, presence: true

View File

@@ -12,7 +12,7 @@ class Image < ApplicationRecord
hash_secret: Rails.application.secrets.secret_key_base hash_secret: Rails.application.secrets.secret_key_base
belongs_to :user belongs_to :user
belongs_to :imageable, polymorphic: true belongs_to :imageable, polymorphic: true, touch: true
validates :title, presence: true validates :title, presence: true
validate :validate_title_length validate :validate_title_length

View File

@@ -9,7 +9,6 @@
<% cache [locale_and_user_status(investment), <% cache [locale_and_user_status(investment),
investment, investment,
investment.image,
investment.author, investment.author,
Flag.flagged?(current_user, investment), Flag.flagged?(current_user, investment),
investment.followed_by?(current_user), investment.followed_by?(current_user),

View File

@@ -400,6 +400,14 @@ describe Proposal do
expect { proposal.update(tag_list: "new tag") }.to change { proposal.cache_version } expect { proposal.update(tag_list: "new tag") }.to change { proposal.cache_version }
end end
it "expires cache when it has a new image" do
expect { create(:image, imageable: proposal) }.to change { proposal.cache_version }
end
it "expires cache when it has a new document" do
expect { create(:document, documentable: proposal) }.to change { proposal.cache_version }
end
it "expires cache when hidden" do it "expires cache when hidden" do
expect { proposal.hide }.to change { proposal.cache_version } expect { proposal.hide }.to change { proposal.cache_version }
end end