Created
January 21, 2010 18:30
-
-
Save brianjlandau/283043 to your computer and use it in GitHub Desktop.
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 ActiveSupport::TestCase | |
| protected | |
| # Use this to destroy ActiveRecord models you created and stored in instance variables. | |
| # Pass in the names of the instance variables: | |
| # | |
| # teardown do | |
| # destroy_and_nil(*%w(contact_details user product)) | |
| # end | |
| # | |
| def destroy_and_nil(*args) | |
| args.flatten.each do |ivar| | |
| unless instance_eval("@#{ivar}.nil?") | |
| if instance_eval("@#{ivar}").respond_to?(:destroy!) | |
| instance_eval("@#{ivar}.destroy!") | |
| else | |
| instance_eval("@#{ivar}.destroy") | |
| end | |
| instance_eval("@#{ivar} = nil") | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment