Created
February 21, 2013 18:40
-
-
Save jmdeldin/5006998 to your computer and use it in GitHub Desktop.
A few methods to disable and restore ActiveRecord in a spec helper
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
def disable_ar | |
class << ActiveRecord::Base | |
def fail_connection; fail 'Tried to access the DB'; end | |
alias_method :old_connection, :connection | |
alias_method :connection, :fail_connection | |
end | |
end | |
def restore_ar | |
class << ActiveRecord::Base | |
alias_method :connection, :old_connection | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment