Add AlgoliaSearchable for Organization (#20883)

* Add algolia for org

* Add test

* Remove redundant path
This commit is contained in:
Mac Siri 2024-04-23 15:35:53 -04:00 committed by GitHub
parent ed4843ef4c
commit c44a2dcdb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,20 @@
module AlgoliaSearchable
module SearchableOrganization
extend ActiveSupport::Concern
included do
algoliasearch(**DEFAULT_ALGOLIA_SETTINGS) do
attribute :name, :tag_line, :summary, :slug
attribute :profile_image do
profile_image_90
end
end
end
class_methods do
def trigger_sidekiq_worker(record, delete)
AlgoliaSearch::SearchIndexWorker.perform_async(record.class.name, record.id, delete)
end
end
end
end

View file

@ -1,6 +1,7 @@
class Organization < ApplicationRecord class Organization < ApplicationRecord
include CloudinaryHelper include CloudinaryHelper
include PgSearch::Model include PgSearch::Model
include AlgoliaSearchable
include Images::Profile.for(:profile_image_url) include Images::Profile.for(:profile_image_url)

View file

@ -439,4 +439,13 @@ RSpec.describe Organization do
end end
end end
end end
context "when indexing with Algolia", :algolia do
it "indexes the organization on create" do
search_index_worker = AlgoliaSearch::SearchIndexWorker
allow(search_index_worker).to receive(:perform_async)
create(:organization)
expect(search_index_worker).to have_received(:perform_async).with("Organization", kind_of(Integer), false)
end
end
end end