Skip to content

Commit 1b50a2e

Browse files
jcoynetaylor-steve
authored andcommitted
Poision the exhibit cache value when a document is updated
1 parent bc58475 commit 1b50a2e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

app/models/spotlight/solr_document_sidecar.rb

Lines changed: 2 additions & 1 deletion
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

spec/models/spotlight/resource_spec.rb

Lines changed: 2 additions & 2 deletions
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

Lines changed: 12 additions & 1 deletion
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
@@ -55,4 +55,15 @@
5555
its(:to_solr) { is_expected.to include 'a_hash_field' => ['b'] }
5656
end
5757
end
58+
59+
describe '#update' do
60+
before do
61+
subject.save
62+
end
63+
64+
it 'poisions the exhibit cache' do
65+
expect { subject.update(data: { 'a_tesim' => 1, 'b_tesim' => 2, 'c_tesim' => 3 }) }
66+
.to(change { subject.exhibit.updated_at })
67+
end
68+
end
5869
end

0 commit comments

Comments
 (0)