Skip to content

Commit 94b977d

Browse files
author
Anna
committed
override test because sqlserver autoconnects
1 parent 17499e7 commit 94b977d

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

test/cases/connection_test_sqlserver.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,4 @@ def deadlock_victim_exception(sql)
272272
error
273273
end
274274

275-
276-
def with_auto_connect(boolean)
277-
existing = ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect
278-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = boolean
279-
yield
280-
ensure
281-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = existing
282-
end
283-
284275
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'cases/sqlserver_helper'
2+
3+
class TestDisconnectedAdapter < ActiveRecord::TestCase
4+
def setup
5+
skip "TestDisconnectedAdapterSqlserver instead "
6+
end
7+
end
8+
9+
class TestDisconnectedAdapterSqlserver < ActiveRecord::TestCase
10+
self.use_transactional_fixtures = false
11+
12+
def setup
13+
skip "in-memory database mustn't disconnect" if in_memory_db?
14+
@connection = ActiveRecord::Base.connection
15+
end
16+
17+
def teardown
18+
return if in_memory_db?
19+
spec = ActiveRecord::Base.connection_config
20+
ActiveRecord::Base.establish_connection(spec)
21+
end
22+
23+
test "can't execute statements while disconnected" do
24+
with_auto_connect(false) do
25+
@connection.execute "SELECT count(*) from products"
26+
@connection.disconnect!
27+
assert_raises(ActiveRecord::LostConnection) do
28+
@connection.execute "SELECT count(*) from products"
29+
end
30+
end
31+
end
32+
end

test/cases/migration_test_sqlserver.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,3 @@ class MigrationTest < ActiveRecord::TestCase
7070
def test_coerced_test_migrator_db_has_no_schema_migrations_table ; assert true ; end
7171
end
7272
end
73-
74-
class ChangeTableMigrationsTest < ActiveRecord::TestCase
75-
COERCED_TESTS = [:test_string_creates_string_column]
76-
include SqlserverCoercedTest
77-
def test_coerced_string_creates_string_column
78-
with_change_table do |t|
79-
@connection.expects(:add_column).with(:delete_me, :foo, 'nvarchar(255)', {})
80-
@connection.expects(:add_column).with(:delete_me, :bar, 'nvarchar(255)', {})
81-
t.string :foo, :bar
82-
end
83-
end
84-
end

test/cases/sqlserver_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ def with_enable_default_unicode_types(setting)
153153
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = old_text
154154
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = old_string
155155
end
156+
157+
def with_auto_connect(boolean)
158+
existing = ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect
159+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = boolean
160+
yield
161+
ensure
162+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = existing
163+
end
156164
end
157165
end
158166

0 commit comments

Comments
 (0)