Created
October 13, 2010 13:05
-
-
Save szimek/623999 to your computer and use it in GitHub Desktop.
Disable delayed_job in tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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