From f1f9578f1c95ca6fb60d45b60ace42638980adb5 Mon Sep 17 00:00:00 2001 From: mhasbini Date: Tue, 11 Apr 2017 15:20:25 +0300 Subject: [PATCH] Fix issue's note cache expiration after delete --- app/models/note.rb | 1 + changelogs/unreleased/30457-expire-note-destroy.yml | 4 ++++ spec/models/note_spec.rb | 12 +++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/30457-expire-note-destroy.yml diff --git a/app/models/note.rb b/app/models/note.rb index 1ea7b946061..834507feccc 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -96,6 +96,7 @@ class Note < ActiveRecord::Base before_validation :set_discussion_id, on: :create after_save :keep_around_commit, unless: :for_personal_snippet? after_save :expire_etag_cache + after_destroy :expire_etag_cache class << self def model_name diff --git a/changelogs/unreleased/30457-expire-note-destroy.yml b/changelogs/unreleased/30457-expire-note-destroy.yml new file mode 100644 index 00000000000..f5c89da68a9 --- /dev/null +++ b/changelogs/unreleased/30457-expire-note-destroy.yml @@ -0,0 +1,4 @@ +--- +title: Fix issue's note cache expiration after delete +merge_request: +author: mhasbini diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 3c4bf3f4ddb..557ea97b008 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -622,12 +622,22 @@ describe Note, models: true do describe 'expiring ETag cache' do let(:note) { build(:note_on_issue) } - it "expires cache for note's issue when note is saved" do + def expect_expiration(note) expect_any_instance_of(Gitlab::EtagCaching::Store) .to receive(:touch) .with("/#{note.project.namespace.to_param}/#{note.project.to_param}/noteable/issue/#{note.noteable.id}/notes") + end + + it "expires cache for note's issue when note is saved" do + expect_expiration(note) note.save! end + + it "expires cache for note's issue when note is destroyed" do + expect_expiration(note) + + note.destroy! + end end end