2005-07-05 01:08:24 -04:00
|
|
|
# The filename begins with "aaa" to ensure this is the first test.
|
2005-02-20 16:21:41 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
2006-02-10 16:32:25 -05:00
|
|
|
class AAACreateTablesTest < Test::Unit::TestCase
|
2005-12-04 00:40:50 -05:00
|
|
|
self.use_transactional_fixtures = false
|
|
|
|
|
2005-02-20 16:21:41 -05:00
|
|
|
def setup
|
2005-07-05 01:08:24 -04:00
|
|
|
@base_path = "#{File.dirname(__FILE__)}/fixtures/db_definitions"
|
2005-02-20 16:21:41 -05:00
|
|
|
end
|
|
|
|
|
2005-07-05 01:08:24 -04:00
|
|
|
def test_drop_and_create_main_tables
|
|
|
|
recreate ActiveRecord::Base
|
|
|
|
assert true
|
|
|
|
end
|
2005-12-02 01:03:43 -05:00
|
|
|
|
|
|
|
def test_load_schema
|
2006-06-03 17:47:29 -04:00
|
|
|
if ActiveRecord::Base.connection.supports_migrations?
|
|
|
|
eval(File.read("#{File.dirname(__FILE__)}/fixtures/db_definitions/schema.rb"))
|
|
|
|
else
|
|
|
|
recreate ActiveRecord::Base, '3'
|
|
|
|
end
|
2005-12-02 01:03:43 -05:00
|
|
|
assert true
|
|
|
|
end
|
2005-07-05 01:08:24 -04:00
|
|
|
|
|
|
|
def test_drop_and_create_courses_table
|
|
|
|
recreate Course, '2'
|
|
|
|
assert true
|
2005-02-20 16:21:41 -05:00
|
|
|
end
|
|
|
|
|
2005-07-05 01:08:24 -04:00
|
|
|
private
|
|
|
|
def recreate(base, suffix = nil)
|
|
|
|
connection = base.connection
|
|
|
|
adapter_name = connection.adapter_name.downcase + suffix.to_s
|
|
|
|
execute_sql_file "#{@base_path}/#{adapter_name}.drop.sql", connection
|
|
|
|
execute_sql_file "#{@base_path}/#{adapter_name}.sql", connection
|
|
|
|
end
|
2005-02-20 16:21:41 -05:00
|
|
|
|
2005-07-05 01:08:24 -04:00
|
|
|
def execute_sql_file(path, connection)
|
2006-03-18 11:50:25 -05:00
|
|
|
# OpenBase has a different format for sql files
|
|
|
|
if current_adapter?(:OpenBaseAdapter) then
|
|
|
|
File.read(path).split("go").each_with_index do |sql, i|
|
|
|
|
begin
|
|
|
|
# OpenBase does not support comments embedded in sql
|
|
|
|
connection.execute(sql,"SQL statement ##{i}") unless sql.blank?
|
|
|
|
rescue ActiveRecord::StatementInvalid
|
|
|
|
#$stderr.puts "warning: #{$!}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
File.read(path).split(';').each_with_index do |sql, i|
|
|
|
|
begin
|
|
|
|
connection.execute("\n\n-- statement ##{i}\n#{sql}\n") unless sql.blank?
|
|
|
|
rescue ActiveRecord::StatementInvalid
|
|
|
|
#$stderr.puts "warning: #{$!}"
|
|
|
|
end
|
2005-07-05 01:08:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2005-02-20 16:21:41 -05:00
|
|
|
end
|