aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/adapter_test_sqlserver.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-07-10 18:24:35 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-07-10 18:24:35 +0000
commit5ad4f1ad94c71bfbb6aacc8a27addc4a0de54506 (patch)
treec2d1bd748ac91f5c9fd5a44a9f667d23fc5d5e01 /activerecord/test/adapter_test_sqlserver.rb
parent0293c34459aa95f268bdbd02f8a35a3cc8a1c6a2 (diff)
downloadrails-5ad4f1ad94c71bfbb6aacc8a27addc4a0de54506.tar.gz
rails-5ad4f1ad94c71bfbb6aacc8a27addc4a0de54506.tar.bz2
rails-5ad4f1ad94c71bfbb6aacc8a27addc4a0de54506.zip
SQLServer: added tests to ensure all database statements are closed, refactored identity_insert management code to use blocks, removed update/delete rowcount code out of execute and into update/delete, changed insert to go through execute method, removed unused quoting methods, disabled pessimistic locking tests as feature is currently unsupported, fixed RakeFile to load sqlserver specific tests whether running in ado or odbc mode, fixed support for recently added decimal types, added support for limits on integer types. Closes #5670.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4601 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/adapter_test_sqlserver.rb')
-rw-r--r--activerecord/test/adapter_test_sqlserver.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/activerecord/test/adapter_test_sqlserver.rb b/activerecord/test/adapter_test_sqlserver.rb
new file mode 100644
index 0000000000..11f244e9f7
--- /dev/null
+++ b/activerecord/test/adapter_test_sqlserver.rb
@@ -0,0 +1,67 @@
+require 'abstract_unit'
+require 'fixtures/default'
+require 'fixtures/post'
+require 'fixtures/task'
+
+class SqlServerAdapterTest < Test::Unit::TestCase
+ fixtures :posts, :tasks
+
+ def setup
+ @connection = ActiveRecord::Base.connection
+ end
+
+ def test_execute_without_block_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.execute("SELECT 1")
+ end
+ end
+
+ def test_execute_with_block_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.execute("SELECT 1") do |sth|
+ assert !sth.finished?, "Statement should still be alive within block"
+ end
+ end
+ end
+
+ def test_insert_with_identity_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
+ end
+ end
+
+ def test_insert_without_identity_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
+ end
+ end
+
+ def test_active_closes_statement
+ assert_all_statements_used_are_closed do
+ @connection.active?
+ end
+ end
+
+ def assert_all_statements_used_are_closed(&block)
+ existing_handles = []
+ ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
+ GC.disable
+
+ yield
+
+ used_handles = []
+ ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
+
+ assert_block "No statements were used within given block" do
+ used_handles.size > 0
+ end
+
+ ObjectSpace.each_object(DBI::StatementHandle) do |handle|
+ assert_block "Statement should have been closed within given block" do
+ handle.finished?
+ end
+ end
+ ensure
+ GC.enable
+ end
+end