From 39913668122b7fd37675951bdccbff5c05d13a98 Mon Sep 17 00:00:00 2001 From: ellnix Date: Wed, 8 Jan 2025 22:41:22 +0100 Subject: [PATCH] Test :enqueue with symbol --- spec/options_spec.rb | 16 ++++++++++++++++ spec/support/models/queued_models.rb | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/spec/options_spec.rb b/spec/options_spec.rb index 41fbc744..84a672bb 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -153,6 +153,22 @@ end describe ':enqueue' do + context 'when configured with a symbol' do + it 'runs the class method when created' do + expect do + SymbolEnqueuedDocument.create! name: 'hellraiser' + end.to raise_error('enqueued hellraiser') + end + + it 'does not run method in without_auto_index block' do + expect do + SymbolEnqueuedDocument.without_auto_index do + SymbolEnqueuedDocument.create! name: 'hellraiser' + end + end.not_to raise_error + end + end + context 'when configured with a proc' do it 'runs proc when created' do expect do diff --git a/spec/support/models/queued_models.rb b/spec/support/models/queued_models.rb index 129a7d0f..aa011365 100644 --- a/spec/support/models/queued_models.rb +++ b/spec/support/models/queued_models.rb @@ -13,6 +13,10 @@ t.boolean :is_public end +ar_schema.create_table :symbol_enqueued_documents do |t| + t.string :name +end + class EnqueuedDocument < ActiveRecord::Base include MeiliSearch::Rails @@ -55,3 +59,16 @@ def should_index? is_public end end + +class SymbolEnqueuedDocument < ActiveRecord::Base + include MeiliSearch::Rails + + meilisearch(enqueue: :queue_me, + index_uid: safe_index_uid('SymbolEnqueuedDocument')) do + attributes %i[name is_public] + end + + def self.queue_me(record, remove) + raise "enqueued #{record.name}" + end +end