aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-07-05 05:08:24 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-07-05 05:08:24 +0000
commit2418a68aa23c96ce20aae6168c71c760cb6e7809 (patch)
tree73280e87b3275a57926e0f85bfa671677e065ca7 /activerecord/test
parentc1efa54195917179b8f2fef64c8c32db08b8538f (diff)
downloadrails-2418a68aa23c96ce20aae6168c71c760cb6e7809.tar.gz
rails-2418a68aa23c96ce20aae6168c71c760cb6e7809.tar.bz2
rails-2418a68aa23c96ce20aae6168c71c760cb6e7809.zip
Simplify aaa_create_tables_test
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1696 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/aaa_create_tables_test.rb74
1 files changed, 26 insertions, 48 deletions
diff --git a/activerecord/test/aaa_create_tables_test.rb b/activerecord/test/aaa_create_tables_test.rb
index 5d494946c1..d49e62561f 100644
--- a/activerecord/test/aaa_create_tables_test.rb
+++ b/activerecord/test/aaa_create_tables_test.rb
@@ -1,58 +1,36 @@
+# The filename begins with "aaa" to ensure this is the first test.
require 'abstract_unit'
-# The filename for this test begins with "aaa" so that
-# it will be the first test.
-
-class SqlFile < File
- #Define an iterator that iterates over the statements in a .sql file.
- #statements are separated by a semicolon.
- def initialize(path)
- super(path)
- end
-
- def each_statement()
- statement = ''
- each_line { |line|
- #The last character of each line is a line-feed, so we will check the next-to-last character
- #to see if it is a semicolon. A better way of doing this would be to look for a semicolon anywhere
- #within the line in case multiple statements have been put on a single line.
- #The last statement in the file must be followed by a line-feed.
- if line.slice(-2,1)==';' then
- statement = statement + line.slice(0,line.length-2) + "\n"
- yield statement
- statement = ''
- else
- statement = statement + line
- end
- }
- end
-end
-
class CreateTablesTest < Test::Unit::TestCase
def setup
- # This method is required by rake.
+ @base_path = "#{File.dirname(__FILE__)}/fixtures/db_definitions"
end
- def run_sql_file(connection, path)
- sql_file = SqlFile.new(path)
- sql_file.each_statement { |statement|
- begin
- #Skip errors. If there is a problem creating the tables then it will show up in other tests.
- connection.execute(statement)
- rescue ActiveRecord::StatementInvalid
- end }
+ def test_drop_and_create_main_tables
+ recreate ActiveRecord::Base
+ assert true
+ end
+
+ def test_drop_and_create_courses_table
+ recreate Course, '2'
+ assert true
end
- def test_table_creation
- adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
- run_sql_file ActiveRecord::Base.connection, "#{File.dirname(__FILE__)}/fixtures/db_definitions/" + adapter_name + ".drop.sql"
- run_sql_file ActiveRecord::Base.connection, "#{File.dirname(__FILE__)}/fixtures/db_definitions/" + adapter_name + ".sql"
+ 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
- # Now do the same thing with the connection used by multiple_db_test.rb
- adapter_name = Course.retrieve_connection.adapter_name.downcase
- run_sql_file Course.retrieve_connection, "#{File.dirname(__FILE__)}/fixtures/db_definitions/" + adapter_name + "2.drop.sql"
- run_sql_file Course.retrieve_connection, "#{File.dirname(__FILE__)}/fixtures/db_definitions/" + adapter_name + "2.sql"
-
- assert_equal 1,1
- end
+ def execute_sql_file(path, connection)
+ 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
+ end
+ end
end