aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorFrederick Cheung <frederick.cheung@gmail.com>2008-04-21 11:00:01 +0100
committerMichael Koziarski <michael@koziarski.com>2008-04-22 13:55:13 +1200
commita4fc93c3a9f59dcd7cf56c6ae1cb1fb749f6678b (patch)
treeb45689a4b8ab2d55b475986e0d49519906f55c44 /activerecord/test/cases
parent0a94f16b9532894aeb7aed2aec5082dd3b521414 (diff)
downloadrails-a4fc93c3a9f59dcd7cf56c6ae1cb1fb749f6678b.tar.gz
rails-a4fc93c3a9f59dcd7cf56c6ae1cb1fb749f6678b.tar.bz2
rails-a4fc93c3a9f59dcd7cf56c6ae1cb1fb749f6678b.zip
Use schema.rb for all databases
Move adapter specific schema into their own files Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/aaa_create_tables_test.rb58
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb2
-rwxr-xr-xactiverecord/test/cases/associations_test.rb2
-rwxr-xr-xactiverecord/test/cases/base_test.rb2
4 files changed, 10 insertions, 54 deletions
diff --git a/activerecord/test/cases/aaa_create_tables_test.rb b/activerecord/test/cases/aaa_create_tables_test.rb
index 32e0d2936e..3911afac49 100644
--- a/activerecord/test/cases/aaa_create_tables_test.rb
+++ b/activerecord/test/cases/aaa_create_tables_test.rb
@@ -4,65 +4,21 @@ require "cases/helper"
class AAACreateTablesTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
- def test_drop_and_create_main_tables
- recreate ActiveRecord::Base unless use_migrations?
- assert true
- end
-
def test_load_schema
- if ActiveRecord::Base.connection.supports_migrations?
- eval(File.read(SCHEMA_ROOT + "/schema.rb"))
- else
- recreate ActiveRecord::Base, '3'
+ 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
- if Course.connection.supports_migrations?
- eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
- end
- recreate Course, '2' unless use_migrations_for_courses?
+ eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
assert true
end
private
- def use_migrations?
- unittest_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + ".sql"
- not File.exist? SCHEMA_ROOT + "/#{unittest_sql_filename}"
- end
-
- def use_migrations_for_courses?
- unittest2_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"
- not File.exist? SCHEMA_ROOT + "/#{unittest2_sql_filename}"
- end
-
- def recreate(base, suffix = nil)
- connection = base.connection
- adapter_name = connection.adapter_name.downcase + suffix.to_s
- execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.drop.sql", connection
- execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.sql", connection
- end
-
- def execute_sql_file(path, connection)
- # 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
- end
- end
- end
+ def adapter_specific_schema_file
+ SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb'
+ end
end
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 00bcb05e2d..a9899102d7 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -25,7 +25,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
new_person = nil # so block binding catches it
assert_queries(0) do
- new_person = Person.new
+ new_person = Person.new :first_name => 'bob'
end
# Associating new records always saves them
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index bfb95eca1a..ed2fab6d22 100755
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -41,7 +41,7 @@ class AssociationsTest < ActiveRecord::TestCase
end
def test_should_construct_new_finder_sql_after_create
- person = Person.new
+ person = Person.new :first_name => 'clark'
assert_equal [], person.readers.find(:all)
person.save!
reader = Reader.create! :person => person, :post => Post.new(:title => "foo", :body => "bar")
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index e5bba1b63d..45d47837a4 100755
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1704,7 +1704,7 @@ class BasicsTest < ActiveRecord::TestCase
old_class = LooseDescendant
Object.send :remove_const, :LooseDescendant
- descendant = old_class.create!
+ descendant = old_class.create! :first_name => 'bob'
assert_not_nil LoosePerson.find(descendant.id), "Should have found instance of LooseDescendant when finding abstract LoosePerson: #{descendant.inspect}"
ensure
unless Object.const_defined?(:LooseDescendant)