Skip to content

Commit 4fc3d3c

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

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
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/resource_spec.rb

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

3-
describe Spotlight::Resource, type: :model do
3+
RSpec.describe Spotlight::Resource, type: :model do
44
subject(:resource) { described_class.create(id: 123, exhibit: exhibit) }
55

66
let(:exhibit) { FactoryBot.create(:exhibit) }
@@ -113,7 +113,7 @@
113113

114114
indexed_document
115115

116-
expect(exhibit).to have_received(:touch)
116+
expect(exhibit).to have_received(:touch).twice
117117
end
118118

119119
context 'with touch: false' do

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)