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 authored and taylor-steve committed Sep 10, 2024
1 parent bc58475 commit 1b50a2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 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

Expand Down
4 changes: 2 additions & 2 deletions spec/models/spotlight/resource_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

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

let(:exhibit) { FactoryBot.create(:exhibit) }
Expand Down Expand Up @@ -113,7 +113,7 @@

indexed_document

expect(exhibit).to have_received(:touch)
expect(exhibit).to have_received(:touch).twice
end

context 'with touch: false' do
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 @@ -55,4 +55,15 @@
its(:to_solr) { is_expected.to include 'a_hash_field' => ['b'] }
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 1b50a2e

Please sign in to comment.