PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/site/vendor/plugins/acts_as_url_param/test/test_helper.rb

https://github.com/bradgessler/compass-style.org
Ruby | 58 lines | 43 code | 10 blank | 5 comment | 4 complexity | 230592aa198acf928dec235739abed8f MD5 | raw file
Possible License(s): LGPL-2.0
  1. # Include this file in your test by copying the following line to your test:
  2. # require File.expand_path(File.dirname(__FILE__) + "/test_helper")
  3. require 'test/unit'
  4. rails_env = File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
  5. if File.exist? rails_env
  6. ENV["RAILS_ENV"] = "test"
  7. require rails_env
  8. require 'active_record/fixtures'
  9. else
  10. require 'rubygems'
  11. $:.unshift(File.dirname(__FILE__) + '/../lib')
  12. RAILS_ROOT = File.dirname(__FILE__)
  13. require 'active_record'
  14. require 'active_record/fixtures'
  15. require "#{File.dirname(__FILE__)}/../init"
  16. ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
  17. end
  18. Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
  19. $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
  20. load_schema = Proc.new do
  21. config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
  22. schema = File.dirname(__FILE__) + "/schema.rb"
  23. ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
  24. load(schema) if File.exist?(schema)
  25. ACTS_AS_URL_PARAM_TEST_DB = ActiveRecord::Base.connection
  26. end
  27. keep_connection_and_load_schema = Proc.new do
  28. old_connection = ActiveRecord::Base.connection
  29. load_schema.call
  30. ActiveRecord::Base.connection = old_connection
  31. end
  32. ActiveRecord::Base.connected? ? keep_connection_and_load_schema.call : load_schema.call
  33. require "redirect"
  34. Redirect.connection = ACTS_AS_URL_PARAM_TEST_DB
  35. class Test::Unit::TestCase #:nodoc:
  36. def create_fixtures(*table_names)
  37. if block_given?
  38. Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
  39. else
  40. Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
  41. end
  42. end
  43. # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
  44. self.use_transactional_fixtures = true
  45. # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
  46. self.use_instantiated_fixtures = false
  47. # Add more helper methods to be used by all tests here...
  48. end