mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Skip Active Record tests in Action Pack if the SQLite database cant be brought up
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@652 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
ea3faf3df9
commit
bc574a86ac
5 changed files with 123 additions and 108 deletions
|
@ -1,4 +1,5 @@
|
||||||
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
||||||
|
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
|
||||||
|
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'action_controller'
|
require 'action_controller'
|
||||||
|
|
|
@ -1,40 +1,43 @@
|
||||||
path_to_ar = File.dirname(__FILE__) + '/../../../activerecord'
|
path_to_ar = File.dirname(__FILE__) + '/../../../activerecord'
|
||||||
|
|
||||||
if Object.const_defined?("ActiveRecord") || File.exist?(path_to_ar)
|
if Object.const_defined?("ActiveRecord") || File.exist?(path_to_ar)
|
||||||
# This test is very different than the others. It requires ActiveRecord to
|
|
||||||
# run. There's a bunch of stuff we are assuming here:
|
|
||||||
#
|
|
||||||
# 1. activerecord exists as a sibling directory to actionpack
|
|
||||||
# (i.e., actionpack/../activerecord)
|
|
||||||
# 2. you've created the appropriate database to run the active_record unit tests
|
|
||||||
# 3. you set the appropriate database connection below
|
|
||||||
|
|
||||||
driver_to_use = 'native_sqlite'
|
# This test is very different than the others. It requires ActiveRecord to
|
||||||
|
# run. There's a bunch of stuff we are assuming here:
|
||||||
|
#
|
||||||
|
# 1. activerecord exists as a sibling directory to actionpack
|
||||||
|
# (i.e., actionpack/../activerecord)
|
||||||
|
# 2. you've created the appropriate database to run the active_record unit tests
|
||||||
|
# 3. you set the appropriate database connection below
|
||||||
|
|
||||||
$: << path_to_ar + '/lib/'
|
begin
|
||||||
$: << path_to_ar + '/test/'
|
|
||||||
require 'active_record' unless Object.const_defined?("ActiveRecord")
|
|
||||||
require "connections/#{driver_to_use}/connection"
|
|
||||||
require 'fixtures/company'
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
driver_to_use = 'native_sqlite'
|
||||||
|
|
||||||
# add some validation rules to trip up the assertions
|
$: << path_to_ar + '/lib/'
|
||||||
class Company
|
$: << path_to_ar + '/test/'
|
||||||
|
require 'active_record' unless Object.const_defined?("ActiveRecord")
|
||||||
|
require "connections/#{driver_to_use}/connection"
|
||||||
|
require 'fixtures/company'
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# add some validation rules to trip up the assertions
|
||||||
|
class Company
|
||||||
protected
|
protected
|
||||||
def validate
|
def validate
|
||||||
errors.add_on_empty('name')
|
errors.add_on_empty('name')
|
||||||
errors.add('rating', 'rating should not be 2') if rating == 2
|
errors.add('rating', 'rating should not be 2') if rating == 2
|
||||||
errors.add_to_base('oh oh') if rating == 3
|
errors.add_to_base('oh oh') if rating == 3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
require File.dirname(__FILE__) + '/../abstract_unit'
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||||
|
|
||||||
# a controller class to handle the AR assertions
|
# a controller class to handle the AR assertions
|
||||||
class ActiveRecordAssertionsController < ActionController::Base
|
class ActiveRecordAssertionsController < ActionController::Base
|
||||||
# fail with 1 bad column
|
# fail with 1 bad column
|
||||||
def nasty_columns_1
|
def nasty_columns_1
|
||||||
@company = Company.new
|
@company = Company.new
|
||||||
|
@ -67,14 +70,14 @@ class ActiveRecordAssertionsController < ActionController::Base
|
||||||
|
|
||||||
# the safety dance......
|
# the safety dance......
|
||||||
def rescue_action(e) raise; end
|
def rescue_action(e) raise; end
|
||||||
end
|
end
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
ActiveRecordAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/"
|
ActiveRecordAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/"
|
||||||
|
|
||||||
# The test case to try the AR assertions
|
# The test case to try the AR assertions
|
||||||
class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
|
class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
|
||||||
# set it up
|
# set it up
|
||||||
def setup
|
def setup
|
||||||
@request = ActionController::TestRequest.new
|
@request = ActionController::TestRequest.new
|
||||||
|
@ -115,6 +118,11 @@ class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
|
||||||
assert_success
|
assert_success
|
||||||
assert_invalid_record 'company'
|
assert_invalid_record 'company'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue SqliteError => e
|
||||||
|
puts "Skipping active record based tests"
|
||||||
|
puts e.message
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
||||||
|
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
|
||||||
|
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'active_record'
|
require 'active_record'
|
||||||
|
|
|
@ -3,6 +3,9 @@ require 'fixtures/course'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||||
|
|
||||||
|
class SqliteError < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
|
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
|
||||||
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
|
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
|
||||||
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
|
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
|
||||||
|
@ -12,7 +15,7 @@ def make_connection(clazz, db_file, db_definitions_file)
|
||||||
puts "SQLite database not found at #{db_file}. Rebuilding it."
|
puts "SQLite database not found at #{db_file}. Rebuilding it."
|
||||||
sqlite_command = "sqlite #{db_file} 'create table a (a integer); drop table a;'"
|
sqlite_command = "sqlite #{db_file} 'create table a (a integer); drop table a;'"
|
||||||
puts "Executing '#{sqlite_command}'"
|
puts "Executing '#{sqlite_command}'"
|
||||||
`#{sqlite_command}`
|
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
|
||||||
clazz.establish_connection(
|
clazz.establish_connection(
|
||||||
:adapter => "sqlite",
|
:adapter => "sqlite",
|
||||||
:dbfile => db_file)
|
:dbfile => db_file)
|
||||||
|
|
|
@ -2,7 +2,9 @@ print "Using native SQLite3\n"
|
||||||
require 'fixtures/course'
|
require 'fixtures/course'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||||
ActiveRecord::Base.logger.level = Logger::DEBUG
|
|
||||||
|
class SqliteError < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
|
BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
|
||||||
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
|
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
|
||||||
|
@ -13,7 +15,7 @@ def make_connection(clazz, db_file, db_definitions_file)
|
||||||
puts "SQLite3 database not found at #{db_file}. Rebuilding it."
|
puts "SQLite3 database not found at #{db_file}. Rebuilding it."
|
||||||
sqlite_command = "sqlite3 #{db_file} 'create table a (a integer); drop table a;'"
|
sqlite_command = "sqlite3 #{db_file} 'create table a (a integer); drop table a;'"
|
||||||
puts "Executing '#{sqlite_command}'"
|
puts "Executing '#{sqlite_command}'"
|
||||||
`#{sqlite_command}`
|
raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
|
||||||
clazz.establish_connection(
|
clazz.establish_connection(
|
||||||
:adapter => "sqlite3",
|
:adapter => "sqlite3",
|
||||||
:dbfile => db_file)
|
:dbfile => db_file)
|
||||||
|
|
Loading…
Reference in a new issue