Skip to content

Instantly share code, notes, and snippets.

@szimek
Created October 13, 2010 13:05
Show Gist options
  • Select an option

  • Save szimek/623999 to your computer and use it in GitHub Desktop.

Select an option

Save szimek/623999 to your computer and use it in GitHub Desktop.
Disable delayed_job in tests
class ActiveRecord::Base
# Allow to bypass Delayed Job asynchronous handling
def self.dont_handle_asynchronously(*methods)
method_aliases = {}
methods.each do |method|
# TODO move this part into Delayed::MessageSending::ClassMethods#handle_asynchronously
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}"
method_aliases[method] = {:with => with_method, :without => without_method}
alias_method method, method_aliases[method][:without]
end
yield
methods.each do |method|
alias_method method, method_aliases[method][:with]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment