test_helper.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #---
  2. # Excerpted from "Agile Web Development with Rails",
  3. # published by The Pragmatic Bookshelf.
  4. # Copyrights apply to this code. It may not be used to create training material,
  5. # courses, books, articles, and the like. Contact us if you are in doubt.
  6. # We make no guarantees that this code is fit for any purpose.
  7. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  8. #---
  9. ENV["RAILS_ENV"] = "test"
  10. require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
  11. require 'rails/test_help'
  12. class ActiveSupport::TestCase
  13. # Transactional fixtures accelerate your tests by wrapping each test method
  14. # in a transaction that's rolled back on completion. This ensures that the
  15. # test database remains unchanged so your fixtures don't have to be reloaded
  16. # between every test method. Fewer database queries means faster tests.
  17. #
  18. # Read Mike Clark's excellent walkthrough at
  19. # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
  20. #
  21. # Every Active Record database supports transactions except MyISAM tables
  22. # in MySQL. Turn off transactional fixtures in this case; however, if you
  23. # don't care one way or the other, switching from MyISAM to InnoDB tables
  24. # is recommended.
  25. #
  26. # The only drawback to using transactional fixtures is when you actually
  27. # need to test transactions. Since your test is bracketed by a transaction,
  28. # any transactions started in your code will be automatically rolled back.
  29. self.use_transactional_fixtures = true
  30. # Instantiated fixtures are slow, but give you @david where otherwise you
  31. # would need people(:david). If you don't want to migrate your existing
  32. # test cases which use the @david style and don't mind the speed hit (each
  33. # instantiated fixtures translates to a database query per test method),
  34. # then set this back to true.
  35. self.use_instantiated_fixtures = false
  36. # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  37. #
  38. # Note: You'll currently still have to declare fixtures explicitly in integration tests
  39. # -- they do not yet inherit this setting
  40. fixtures :all
  41. # Add more helper methods to be used by all tests here...
  42. end