Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving SQL Server tests from AR core to plugin sqlserver adapter. Clo…
…ses #9884 [lawrence]
- Loading branch information
lawrence
committed
Oct 16, 2007
1 parent
32fbea8
commit 72a3221
Showing
9 changed files
with
849 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
== Creating the test database | |||
|
|||
The default names for the test databases are "activerecord_unittest" and | |||
"activerecord_unittest2". If you want to use another database name then be sure | |||
to update the connection adapter setups you want to test with in | |||
test/connections/<your database>/connection.rb. | |||
|
|||
|
|||
== Requirements | |||
|
|||
The tests of this adapter depend on the existence of rails edge. All the tests | |||
defined by rails edge are re-used. For this to work the following directory | |||
structure is assumed to exist: | |||
|
|||
#{RAILS_ROOT}/vendor/plugins/adapters/sqlserver | |||
#{RAILS_ROOT}/vendor/rails/activerecord/test | |||
|
|||
Define a user named 'rails' in SQL Server with all privileges granted. Use an empty | |||
password for user 'rails', or alternatively use the OSQLPASSWORD environment variable | |||
which allows you to set a default password for the current session. | |||
|
|||
Then run "rake create_databases". | |||
|
|||
|
|||
== Running with Rake | |||
|
|||
The easiest way to run the unit tests is through Rake. Either run "rake test_sqlserver" | |||
or "rake test_sqlserver_odbc". For more information, checkout the full array | |||
of rake tasks with "rake -T" | |||
|
|||
Rake can be found at http://rake.rubyforge.org | |||
|
|||
|
|||
== Running by hand | |||
|
|||
Unit tests are located in test directory. If you only want to run a single test suite, | |||
you can do so with: | |||
|
|||
rake test_sqlserver TEST=base_test.rb | |||
|
|||
That'll run the base suite using the SQLServer-Ruby adapter. | |||
|
|||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,88 @@ | |||
# The filename begins with "aaaa" to ensure this is the first test. | |||
require 'abstract_unit' | |||
|
|||
class AAAACreateTablesTestSqlserver < Test::Unit::TestCase | |||
self.use_transactional_fixtures = false | |||
|
|||
def setup | |||
@ar_path = "../../../rails/activerecord/test/fixtures/db_definitions" | |||
@base_path = "#{File.dirname(__FILE__)}/fixtures/db_definitions" | |||
end | |||
|
|||
def test_sqlserver_load_test_schema | |||
execute_sql_file("#{@base_path}/sqlserver.drop.sql", ActiveRecord::Base.connection) | |||
execute_sql_file("#{@base_path}/sqlserver.sql", ActiveRecord::Base.connection) | |||
execute_sql_file("#{@base_path}/sqlserver2.drop.sql", Course.connection) | |||
execute_sql_file("#{@base_path}/sqlserver2.sql", Course.connection) | |||
assert true | |||
end | |||
|
|||
#FUTURE | |||
def __test_activerecord_load_test_schema | |||
#FUTURE: eval(File.read("#{@ar_path}/schema.rb")) | |||
eval(File.read("#{@base_path}/schema.rb")) | |||
connection = ActiveRecord::Base.connection | |||
begin | |||
ActiveRecord::Base.connection = Course.connection | |||
#FUTURE: eval(File.read("#{@ar_path}/schema2.rb")) | |||
eval(File.read("#{@base_path}/schema2.rb")) | |||
ensure | |||
ActiveRecord::Base.connection = connection | |||
end | |||
assert true | |||
end | |||
|
|||
private | |||
|
|||
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 | |||
# The filename begins with "aaaa" to ensure this is the first test. | |||
require 'abstract_unit' | |||
|
|||
class AAAACreateTablesTestSqlserver < Test::Unit::TestCase | |||
self.use_transactional_fixtures = false | |||
|
|||
def setup | |||
@ar_path = "../../../rails/activerecord/test/fixtures/db_definitions" | |||
@base_path = "#{File.dirname(__FILE__)}/fixtures/db_definitions" | |||
end | |||
|
|||
def test_sqlserver_load_test_schema | |||
execute_sql_file("#{@base_path}/sqlserver.drop.sql", ActiveRecord::Base.connection) | |||
execute_sql_file("#{@base_path}/sqlserver.sql", ActiveRecord::Base.connection) | |||
execute_sql_file("#{@base_path}/sqlserver2.drop.sql", Course.connection) | |||
execute_sql_file("#{@base_path}/sqlserver2.sql", Course.connection) | |||
assert true | |||
end | |||
|
|||
#FUTURE | |||
def __test_activerecord_load_test_schema | |||
#FUTURE: eval(File.read("#{@ar_path}/schema.rb")) | |||
eval(File.read("#{@base_path}/schema.rb")) | |||
connection = ActiveRecord::Base.connection | |||
begin | |||
ActiveRecord::Base.connection = Course.connection | |||
#FUTURE: eval(File.read("#{@ar_path}/schema2.rb")) | |||
eval(File.read("#{@base_path}/schema2.rb")) | |||
ensure | |||
ActiveRecord::Base.connection = connection | |||
end | |||
assert true | |||
end | |||
|
|||
private | |||
|
|||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
print "Using native SQLServer\n" | |||
require_dependency 'fixtures/course' | |||
require 'logger' | |||
|
|||
ActiveRecord::Base.logger = Logger.new("debug.log") | |||
|
|||
ActiveRecord::Base.configurations = { | |||
'arunit' => { | |||
:adapter => 'sqlserver', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:database => 'activerecord_unittest' | |||
}, | |||
'arunit2' => { | |||
:adapter => 'sqlserver', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:database => 'activerecord_unittest2' | |||
} | |||
} | |||
|
|||
ActiveRecord::Base.establish_connection 'arunit' | |||
Course.establish_connection 'arunit2' | |||
print "Using native SQLServer\n" | |||
require_dependency 'fixtures/course' | |||
require 'logger' | |||
|
|||
ActiveRecord::Base.logger = Logger.new("debug.log") | |||
|
|||
ActiveRecord::Base.configurations = { | |||
'arunit' => { | |||
:adapter => 'sqlserver', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:database => 'activerecord_unittest' | |||
}, | |||
'arunit2' => { | |||
:adapter => 'sqlserver', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:database => 'activerecord_unittest2' | |||
} | |||
} | |||
|
|||
ActiveRecord::Base.establish_connection 'arunit' | |||
Course.establish_connection 'arunit2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
print "Using native SQLServer via ODBC\n" | |||
require_dependency 'fixtures/course' | |||
require 'logger' | |||
|
|||
ActiveRecord::Base.logger = Logger.new("debug.log") | |||
|
|||
ActiveRecord::Base.configurations = { | |||
'arunit' => { | |||
:adapter => 'sqlserver', | |||
:mode => 'ODBC', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:dsn => 'activerecord_unittest' | |||
}, | |||
'arunit2' => { | |||
:adapter => 'sqlserver', | |||
:mode => 'ODBC', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:dsn => 'activerecord_unittest2' | |||
} | |||
} | |||
|
|||
ActiveRecord::Base.establish_connection 'arunit' | |||
Course.establish_connection 'arunit2' | |||
print "Using native SQLServer via ODBC\n" | |||
require_dependency 'fixtures/course' | |||
require 'logger' | |||
|
|||
ActiveRecord::Base.logger = Logger.new("debug.log") | |||
|
|||
ActiveRecord::Base.configurations = { | |||
'arunit' => { | |||
:adapter => 'sqlserver', | |||
:mode => 'ODBC', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:dsn => 'activerecord_unittest' | |||
}, | |||
'arunit2' => { | |||
:adapter => 'sqlserver', | |||
:mode => 'ODBC', | |||
:host => 'localhost', | |||
:username => 'rails', | |||
:dsn => 'activerecord_unittest2' | |||
} | |||
} | |||
|
|||
ActiveRecord::Base.establish_connection 'arunit' | |||
Course.establish_connection 'arunit2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,70 @@ | |||
DROP TABLE accounts; | |||
DROP TABLE funny_jokes; | |||
DROP TABLE companies; | |||
DROP TABLE topics; | |||
DROP TABLE developers; | |||
DROP TABLE projects; | |||
DROP TABLE developers_projects; | |||
DROP TABLE customers; | |||
DROP TABLE orders; | |||
DROP TABLE movies; | |||
DROP TABLE subscribers; | |||
DROP TABLE booleantests; | |||
DROP TABLE defaults; | |||
DROP TABLE auto_id_tests; | |||
DROP TABLE entrants; | |||
DROP TABLE colnametests; | |||
DROP TABLE mixins; | |||
DROP TABLE people; | |||
DROP TABLE readers; | |||
DROP TABLE binaries; | |||
DROP TABLE computers; | |||
DROP TABLE posts; | |||
DROP TABLE comments; | |||
DROP TABLE authors; | |||
DROP TABLE tasks; | |||
DROP TABLE categories; | |||
DROP TABLE categories_posts; | |||
DROP TABLE fk_test_has_fk; | |||
DROP TABLE fk_test_has_pk; | |||
DROP TABLE keyboards; | |||
DROP TABLE legacy_things; | |||
DROP TABLE numeric_data; | |||
DROP TABLE [order]; | |||
DROP TABLE mixed_case_monkeys; | |||
DROP TABLE minimalistics; | |||
DROP TABLE accounts; | |||
DROP TABLE funny_jokes; | |||
DROP TABLE companies; | |||
DROP TABLE topics; | |||
DROP TABLE developers; | |||
DROP TABLE projects; | |||
DROP TABLE developers_projects; | |||
DROP TABLE customers; | |||
DROP TABLE orders; | |||
DROP TABLE movies; | |||
DROP TABLE subscribers; | |||
DROP TABLE booleantests; | |||
DROP TABLE defaults; | |||
DROP TABLE auto_id_tests; | |||
DROP TABLE entrants; | |||
DROP TABLE colnametests; | |||
DROP TABLE mixins; | |||
DROP TABLE people; | |||
DROP TABLE readers; | |||
DROP TABLE binaries; | |||
DROP TABLE computers; | |||
DROP TABLE posts; | |||
DROP TABLE comments; | |||
DROP TABLE authors; | |||
DROP TABLE tasks; | |||
DROP TABLE categories; | |||
DROP TABLE categories_posts; | |||
DROP TABLE fk_test_has_fk; | |||
DROP TABLE fk_test_has_pk; | |||
DROP TABLE keyboards; | |||
DROP TABLE legacy_things; | |||
DROP TABLE numeric_data; | |||
DROP TABLE [order]; | |||
DROP TABLE mixed_case_monkeys; | |||
DROP TABLE minimalistics; |
Oops, something went wrong.