Skip to content

Commit 0471b30

Browse files
committed
Poision the exhibit cache value when a document is updated
1 parent 75fa406 commit 0471b30

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/models/spotlight/solr_document_sidecar.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class SolrDocumentSidecar < ActiveRecord::Base
88

99
acts_as_taggable
1010

11-
belongs_to :exhibit, optional: false
11+
# The "touch: true" ensures the exhibit's cache is invalidated when the document is updated
12+
belongs_to :exhibit, optional: false, touch: true
1213
belongs_to :resource, optional: true
1314
belongs_to :document, optional: false, polymorphic: true
1415
serialize :data, Hash

spec/models/spotlight/solr_document_sidecar_spec.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
describe Spotlight::SolrDocumentSidecar, type: :model do
3+
RSpec.describe Spotlight::SolrDocumentSidecar, type: :model do
44
let(:exhibit) { FactoryBot.create(:exhibit) }
55

66
before do
@@ -45,4 +45,15 @@
4545
its(:to_solr) { is_expected.to include 'a_multivalued_field_with_some_blanks' => ['a'] }
4646
end
4747
end
48+
49+
describe '#update' do
50+
before do
51+
subject.save
52+
end
53+
54+
it 'poisions the exhibit cache' do
55+
expect { subject.update(data: { 'a_tesim' => 1, 'b_tesim' => 2, 'c_tesim' => 3 }) }
56+
.to(change { subject.exhibit.updated_at })
57+
end
58+
end
4859
end

0 commit comments

Comments
 (0)