Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fix sunspot#939

rails/30919 added strict callback checking
for Rails 6. The on callback used to be ignored on our default callback.
It now raises an error.

This change checks the configured callback
and conditionally adds the on filter.

* Simplify regex, use different regex operator
  • Loading branch information
Michael authored and MarkyMarkMcDonald committed Mar 8, 2022
1 parent 8673bfd commit abf80b5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sunspot_rails/lib/sunspot/rails/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ def searchable(options = {}, &block)

unless options[:auto_remove] == false
# after_commit { |searchable| searchable.remove_from_index }, :on => :destroy
__send__ Sunspot::Rails.configuration.auto_remove_callback,
proc { |searchable| searchable.remove_from_index },
:on => :destroy
# Only add the on filter if the callback supports it
if Sunspot::Rails.configuration.auto_remove_callback =~ /save|destroy|create/
__send__ Sunspot::Rails.configuration.auto_remove_callback,
proc { |searchable| searchable.remove_from_index }
else
__send__ Sunspot::Rails.configuration.auto_remove_callback,
proc { |searchable| searchable.remove_from_index },
:on => :destroy
end
end
options[:include] = Util::Array(options[:include])

Expand Down

0 comments on commit abf80b5

Please sign in to comment.