mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
replace the aaa_create_tables_test hack with loading test database schema in the test helper [#2663 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
092089015b
commit
b33c0d9832
4 changed files with 22 additions and 31 deletions
|
@ -1,24 +0,0 @@
|
|||
# The filename begins with "aaa" to ensure this is the first test.
|
||||
require "cases/helper"
|
||||
|
||||
class AAACreateTablesTest < ActiveRecord::TestCase
|
||||
self.use_transactional_fixtures = false
|
||||
|
||||
def test_load_schema
|
||||
eval(File.read(SCHEMA_ROOT + "/schema.rb"))
|
||||
if File.exists?(adapter_specific_schema_file)
|
||||
eval(File.read(adapter_specific_schema_file))
|
||||
end
|
||||
assert true
|
||||
end
|
||||
|
||||
def test_drop_and_create_courses_table
|
||||
eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
|
||||
assert true
|
||||
end
|
||||
|
||||
private
|
||||
def adapter_specific_schema_file
|
||||
SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb'
|
||||
end
|
||||
end
|
|
@ -5,6 +5,7 @@ require 'config'
|
|||
|
||||
require 'rubygems'
|
||||
require 'test/unit'
|
||||
require 'stringio'
|
||||
gem 'mocha', '>= 0.9.5'
|
||||
require 'mocha'
|
||||
|
||||
|
@ -72,3 +73,20 @@ class ActiveSupport::TestCase
|
|||
Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
|
||||
end
|
||||
end
|
||||
|
||||
# silence verbose schema loading
|
||||
original_stdout = $stdout
|
||||
$stdout = StringIO.new
|
||||
|
||||
begin
|
||||
adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
|
||||
adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
|
||||
|
||||
load SCHEMA_ROOT + "/schema.rb"
|
||||
|
||||
if File.exists?(adapter_specific_schema_file)
|
||||
load adapter_specific_schema_file
|
||||
end
|
||||
ensure
|
||||
$stdout = original_stdout
|
||||
end
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
ActiveRecord::Schema.define do
|
||||
def except(adapter_names_to_exclude)
|
||||
unless [adapter_names_to_exclude].flatten.include?(adapter_name)
|
||||
|
@ -500,3 +499,7 @@ ActiveRecord::Schema.define do
|
|||
execute "ALTER TABLE fk_test_has_fk ADD CONSTRAINT fk_name FOREIGN KEY (#{quote_column_name 'fk_id'}) REFERENCES #{quote_table_name 'fk_test_has_pk'} (#{quote_column_name 'id'})"
|
||||
end
|
||||
end
|
||||
|
||||
Course.connection.create_table :courses, :force => true do |t|
|
||||
t.column :name, :string, :null => false
|
||||
end
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
ActiveRecord::Schema.define do
|
||||
|
||||
Course.connection.create_table :courses, :force => true do |t|
|
||||
t.column :name, :string, :null => false
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue