public
Fork of caring/acts_as_url_param
Description: Pretty url support for Ruby on Rails applications
Homepage: http://www.caring.com
Clone URL: git://github.com/joshuabates/acts_as_url_param.git
acts_as_url_param / test / test_helper.rb
100644 57 lines (47 sloc) 2.051 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Include this file in your test by copying the following line to your test:
# require File.expand_path(File.dirname(__FILE__) + "/test_helper")
 
require 'test/unit'
rails_env = File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
if File.exist? rails_env
  require rails_env
  require 'active_record/fixtures'
else
  require 'rubygems'
  $:.unshift(File.dirname(__FILE__) + '/../lib')
  RAILS_ROOT = File.dirname(__FILE__)
  require 'active_record'
  require 'active_record/fixtures'
  require "#{File.dirname(__FILE__)}/../init"
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
end
 
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
 
load_schema = Proc.new do
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
  schema = File.dirname(__FILE__) + "/schema.rb"
  ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
  load(schema) if File.exist?(schema)
  ACTS_AS_URL_PARAM_TEST_DB = ActiveRecord::Base.connection
end
 
keep_connection_and_load_schema = Proc.new do
  old_connection = ActiveRecord::Base.connection
  load_schema.call
  ActiveRecord::Base.connection = old_connection
end
 
ActiveRecord::Base.connected? ? keep_connection_and_load_schema.call : load_schema.call
 
require "redirect"
Redirect.connection = ACTS_AS_URL_PARAM_TEST_DB
 
class Test::Unit::TestCase #:nodoc:
  def create_fixtures(*table_names)
    if block_given?
      Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
    else
      Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
    end
  end
 
  # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
  self.use_transactional_fixtures = true
  
  # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
  self.use_instantiated_fixtures = false
 
  # Add more helper methods to be used by all tests here...
end