-
Notifications
You must be signed in to change notification settings - Fork 563
/
Copy pathconnection_test_sqlserver.rb
71 lines (55 loc) · 1.83 KB
/
connection_test_sqlserver.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'cases/helper_sqlserver'
require 'models/reply'
require 'models/topic'
class ConnectionTestSQLServer < ActiveRecord::TestCase
self.use_transactional_tests = false
fixtures :topics, :accounts
before do
connection.reconnect!
assert connection.active?
end
it 'affect rows' do
topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
updated = Topic.update(topic_data.keys, topic_data.values)
assert_equal 2, updated.size
assert_equal "1 updated", Topic.find(1).content
assert_equal "2 updated", Topic.find(2).content
assert_equal 2, Topic.delete([1, 2])
end
it 'allow usage of :database connection option to remove setting from dsn' do
assert_equal 'activerecord_unittest', connection.current_database
begin
connection.use_database('activerecord_unittest2')
assert_equal 'activerecord_unittest2', connection.current_database
ensure
connection.use_database
assert_equal 'activerecord_unittest', connection.current_database, 'Would default back to connection options'
end
end unless connection_sqlserver_azure?
describe 'Connection management' do
it 'set spid on connect' do
['Fixnum', 'Integer'].must_include connection.spid.class.name
end
it 'reset spid on disconnect!' do
connection.disconnect!
assert connection.spid.nil?
end
it 'reset the connection' do
connection.disconnect!
connection.raw_connection.must_be_nil
end
it 'be able to disconnect and reconnect at will' do
disconnect_raw_connection!
assert !connection.active?
connection.reconnect!
assert connection.active?
end
end
private
def disconnect_raw_connection!
case connection_options[:mode]
when :dblib
connection.raw_connection.close rescue nil
end
end
end