Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poision the exhibit cache value when a document is updated #2970

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading