diff --git a/app/models/spotlight/solr_document_sidecar.rb b/app/models/spotlight/solr_document_sidecar.rb index 9fadcdbcb..3185a01f4 100644 --- a/app/models/spotlight/solr_document_sidecar.rb +++ b/app/models/spotlight/solr_document_sidecar.rb @@ -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 diff --git a/spec/models/spotlight/resource_spec.rb b/spec/models/spotlight/resource_spec.rb index b29ec9196..bd9bced19 100644 --- a/spec/models/spotlight/resource_spec.rb +++ b/spec/models/spotlight/resource_spec.rb @@ -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) } @@ -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 diff --git a/spec/models/spotlight/solr_document_sidecar_spec.rb b/spec/models/spotlight/solr_document_sidecar_spec.rb index 5be5f9df0..043e0c33d 100644 --- a/spec/models/spotlight/solr_document_sidecar_spec.rb +++ b/spec/models/spotlight/solr_document_sidecar_spec.rb @@ -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 @@ -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