test_helper.rb 2.6 KB

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