Skip to content

Commit

Permalink
Test :enqueue with symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Jan 8, 2025
1 parent 3bdb146 commit 3991366
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions spec/support/models/queued_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 3991366

Please sign in to comment.