Skip to content

Commit 7f66791

Browse files
snowblinkh-lame
authored andcommitted
Moving test cases to test/cases
Adding adapter_test_sqlserver.rb to test/cases - I think this file should be maintained with the adapter.
1 parent 57240a8 commit 7f66791

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

test/aaaa_create_tables_test_sqlserver.rb renamed to test/cases/aaaa_create_tables_test_sqlserver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class AAAACreateTablesTestSqlserver < ActiveRecord::TestCase
55
self.use_transactional_fixtures = false
66

77
def setup
8-
@ar_path = "../../../rails/activerecord/test/schema"
9-
@base_path = "#{File.dirname(__FILE__)}/fixtures/db_definitions"
8+
@ar_path = "#{File.dirname(__FILE__)}/../schema"
9+
@base_path = "#{File.dirname(__FILE__)}/../fixtures/db_definitions"
1010
end
1111

1212
def __test_sqlserver_load_test_schema
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
require "cases/helper"
2+
require 'models/default'
3+
require 'models/post'
4+
require 'models/task'
5+
6+
class SqlServerAdapterTest < ActiveRecord::TestCase
7+
class TableWithRealColumn < ActiveRecord::Base; end
8+
9+
fixtures :posts, :tasks
10+
11+
def setup
12+
@connection = ActiveRecord::Base.connection
13+
end
14+
15+
def teardown
16+
@connection.execute("SET LANGUAGE us_english") rescue nil
17+
end
18+
19+
def test_real_column_has_float_type
20+
assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
21+
end
22+
23+
# SQL Server 2000 has a bug where some unambiguous date formats are not
24+
# correctly identified if the session language is set to german
25+
def test_date_insertion_when_language_is_german
26+
@connection.execute("SET LANGUAGE deutsch")
27+
28+
assert_nothing_raised do
29+
Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
30+
end
31+
end
32+
33+
def test_indexes_with_descending_order
34+
# Make sure we have an index with descending order
35+
@connection.execute "CREATE INDEX idx_credit_limit ON accounts (credit_limit DESC)" rescue nil
36+
assert_equal ["credit_limit"], @connection.indexes('accounts').first.columns
37+
ensure
38+
@connection.execute "DROP INDEX accounts.idx_credit_limit"
39+
end
40+
41+
def test_execute_without_block_closes_statement
42+
assert_all_statements_used_are_closed do
43+
@connection.execute("SELECT 1")
44+
end
45+
end
46+
47+
def test_execute_with_block_closes_statement
48+
assert_all_statements_used_are_closed do
49+
@connection.execute("SELECT 1") do |sth|
50+
assert !sth.finished?, "Statement should still be alive within block"
51+
end
52+
end
53+
end
54+
55+
def test_insert_with_identity_closes_statement
56+
assert_all_statements_used_are_closed do
57+
@connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
58+
end
59+
end
60+
61+
def test_insert_without_identity_closes_statement
62+
assert_all_statements_used_are_closed do
63+
@connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
64+
end
65+
end
66+
67+
def test_active_closes_statement
68+
assert_all_statements_used_are_closed do
69+
@connection.active?
70+
end
71+
end
72+
73+
def assert_all_statements_used_are_closed(&block)
74+
existing_handles = []
75+
ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
76+
GC.disable
77+
78+
yield
79+
80+
used_handles = []
81+
ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
82+
83+
assert_block "No statements were used within given block" do
84+
used_handles.size > 0
85+
end
86+
87+
ObjectSpace.each_object(DBI::StatementHandle) do |handle|
88+
assert_block "Statement should have been closed within given block" do
89+
handle.finished?
90+
end
91+
end
92+
ensure
93+
GC.enable
94+
end
95+
end
File renamed without changes.

0 commit comments

Comments
 (0)