Skip to content

Commit

Permalink
Poision the exhibit cache value when a document is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 10, 2023
1 parent 75fa406 commit 0471b30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/spotlight/solr_document_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class SolrDocumentSidecar < ActiveRecord::Base

acts_as_taggable

belongs_to :exhibit, optional: false
# The "touch: true" ensures the exhibit's cache is invalidated when the document is updated
belongs_to :exhibit, optional: false, touch: true
belongs_to :resource, optional: true
belongs_to :document, optional: false, polymorphic: true
serialize :data, Hash
Expand Down
13 changes: 12 additions & 1 deletion spec/models/spotlight/solr_document_sidecar_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Spotlight::SolrDocumentSidecar, type: :model do
RSpec.describe Spotlight::SolrDocumentSidecar, type: :model do
let(:exhibit) { FactoryBot.create(:exhibit) }

before do
Expand Down Expand Up @@ -45,4 +45,15 @@
its(:to_solr) { is_expected.to include 'a_multivalued_field_with_some_blanks' => ['a'] }
end
end

describe '#update' do
before do
subject.save
end

it 'poisions the exhibit cache' do
expect { subject.update(data: { 'a_tesim' => 1, 'b_tesim' => 2, 'c_tesim' => 3 }) }
.to(change { subject.exhibit.updated_at })
end
end
end

0 comments on commit 0471b30

Please sign in to comment.