Skip to content

Commit 8b030ac

Browse files
committed
Replace connection with lease_connection
1 parent bbc3bcf commit 8b030ac

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

Diff for: lib/arel/visitors/sqlserver.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def visit_Arel_Table(o, collector)
129129
# github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/450
130130
table_name =
131131
begin
132-
if o.class.engine.connection.respond_to?(:sqlserver?) && o.class.engine.connection.database_prefix_remote_server?
132+
if o.class.engine.lease_connection.respond_to?(:sqlserver?) && o.class.engine.lease_connection.database_prefix_remote_server?
133133
remote_server_table_name(o)
134134
else
135135
quote_table_name(o.name)
@@ -316,7 +316,7 @@ def primary_Key_From_Table(t)
316316

317317
def remote_server_table_name(o)
318318
ActiveRecord::ConnectionAdapters::SQLServer::Utils.extract_identifiers(
319-
"#{o.class.engine.connection.database_prefix}#{o.name}"
319+
"#{o.class.engine.lease_connection.database_prefix}#{o.name}"
320320
).quoted
321321
end
322322

Diff for: test/cases/adapter_test_sqlserver.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
3131
end
3232

3333
it "raises invalid statement error for bad SQL" do
34-
assert_raise(ActiveRecord::StatementInvalid) { Topic.connection.update("UPDATE XXX") }
34+
assert_raise(ActiveRecord::StatementInvalid) { Topic.lease_connection.update("UPDATE XXX") }
3535
end
3636

3737
it "is has our adapter_name" do
@@ -285,23 +285,23 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
285285
end
286286

287287
it "NOT ALLOW by default the deletion of a referenced parent" do
288-
SSTestHasPk.connection.disable_referential_integrity {}
288+
SSTestHasPk.lease_connection.disable_referential_integrity {}
289289
assert_raise(ActiveRecord::StatementInvalid) { @parent.destroy }
290290
end
291291

292292
it "ALLOW deletion of referenced parent using #disable_referential_integrity block" do
293-
SSTestHasPk.connection.disable_referential_integrity { @parent.destroy }
293+
SSTestHasPk.lease_connection.disable_referential_integrity { @parent.destroy }
294294
end
295295

296296
it "again NOT ALLOW deletion of referenced parent after #disable_referential_integrity block" do
297297
assert_raise(ActiveRecord::StatementInvalid) do
298-
SSTestHasPk.connection.disable_referential_integrity {}
298+
SSTestHasPk.lease_connection.disable_referential_integrity {}
299299
@parent.destroy
300300
end
301301
end
302302

303303
it "not disable referential integrity for the same table twice" do
304-
tables = SSTestHasPk.connection.tables_with_referential_integrity
304+
tables = SSTestHasPk.lease_connection.tables_with_referential_integrity
305305
assert_equal tables.size, tables.uniq.size
306306
end
307307
end
@@ -396,7 +396,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
396396

397397
it "allows connection#view_information to work across databases when using qualified object names" do
398398
# College is defined in activerecord_unittest2 database.
399-
view_info = College.connection.send(:view_information, "[activerecord_unittest].[dbo].[sst_customers_view]")
399+
view_info = College.lease_connection.send(:view_information, "[activerecord_unittest].[dbo].[sst_customers_view]")
400400
assert_equal("sst_customers_view", view_info["TABLE_NAME"])
401401
assert_match(/CREATE VIEW sst_customers_view/, view_info["VIEW_DEFINITION"])
402402
end
@@ -407,8 +407,8 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
407407
end
408408

409409
it "allow the connection#view_table_name method to return true table_name for the view for other connections" do
410-
assert_equal "customers", College.connection.send(:view_table_name, "[activerecord_unittest].[dbo].[sst_customers_view]")
411-
assert_equal "topics", College.connection.send(:view_table_name, "topics"), "No view here, the same table name should come back."
410+
assert_equal "customers", College.lease_connection.send(:view_table_name, "[activerecord_unittest].[dbo].[sst_customers_view]")
411+
assert_equal "topics", College.lease_connection.send(:view_table_name, "topics"), "No view here, the same table name should come back."
412412
end
413413
# With same column names
414414

@@ -434,7 +434,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
434434
end
435435

436436
it "respond true to data_source_exists?" do
437-
assert SSTestCustomersView.connection.data_source_exists?(SSTestCustomersView.table_name)
437+
assert SSTestCustomersView.lease_connection.data_source_exists?(SSTestCustomersView.table_name)
438438
end
439439

440440
# With aliased column names
@@ -462,7 +462,7 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
462462
end
463463

464464
it "respond true to data_source_exists?" do
465-
assert SSTestStringDefaultsView.connection.data_source_exists?(SSTestStringDefaultsView.table_name)
465+
assert SSTestStringDefaultsView.lease_connection.data_source_exists?(SSTestStringDefaultsView.table_name)
466466
end
467467

468468
# That have more than 4000 chars for their defintion
@@ -554,7 +554,7 @@ def test_doesnt_error_when_a_select_query_is_called_while_preventing_writes
554554
end
555555

556556
it 'records can be inserted using SQL' do
557-
Alien.connection.exec_insert("insert into [test].[aliens] (id, name) VALUES(1, 'Trisolarans'), (2, 'Xenomorph')")
557+
Alien.lease_connection.exec_insert("insert into [test].[aliens] (id, name) VALUES(1, 'Trisolarans'), (2, 'Xenomorph')")
558558
end
559559
end
560560

Diff for: test/cases/coerced_tests.rb

+29-29
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def migrate(x)
657657
ensure
658658
Person.reset_column_information
659659
if Person.column_names.include?("last_name")
660-
Person.connection.remove_column("people", "last_name")
660+
Person.lease_connection.remove_column("people", "last_name")
661661
end
662662
end
663663
end
@@ -1334,7 +1334,7 @@ class QueryCacheTest < ActiveRecord::TestCase
13341334
coerce_tests! :test_cache_does_not_wrap_results_in_arrays
13351335
def test_cache_does_not_wrap_results_in_arrays_coerced
13361336
Task.cache do
1337-
assert_equal 2, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
1337+
assert_equal 2, Task.lease_connection.select_value("SELECT count(*) AS count_all FROM tasks")
13381338
end
13391339
end
13401340

@@ -1493,7 +1493,7 @@ class RelationTest < ActiveRecord::TestCase
14931493

14941494
coerce_tests! :test_does_not_duplicate_optimizer_hints_on_merge
14951495
def test_does_not_duplicate_optimizer_hints_on_merge_coerced
1496-
escaped_table = Post.connection.quote_table_name("posts")
1496+
escaped_table = Post.lease_connection.quote_table_name("posts")
14971497
expected = "SELECT #{escaped_table}.* FROM #{escaped_table} OPTION (OMGHINT)"
14981498
query = Post.optimizer_hints("OMGHINT").merge(Post.optimizer_hints("OMGHINT")).to_sql
14991499
assert_equal expected, query
@@ -1634,19 +1634,19 @@ class TransactionTest < ActiveRecord::TestCase
16341634
coerce_tests! :test_releasing_named_savepoints
16351635
def test_releasing_named_savepoints_coerced
16361636
Topic.transaction do
1637-
Topic.connection.materialize_transactions
1637+
Topic.lease_connection.materialize_transactions
16381638

1639-
Topic.connection.create_savepoint("another")
1640-
Topic.connection.release_savepoint("another")
1639+
Topic.lease_connection.create_savepoint("another")
1640+
Topic.lease_connection.release_savepoint("another")
16411641
# We do not have a notion of releasing, so this does nothing vs raise an error.
1642-
Topic.connection.release_savepoint("another")
1642+
Topic.lease_connection.release_savepoint("another")
16431643
end
16441644
end
16451645

16461646
# SQL Server does not have query for release_savepoint.
16471647
coerce_tests! :test_nested_transactions_after_disable_lazy_transactions
16481648
def test_nested_transactions_after_disable_lazy_transactions_coerced
1649-
Topic.connection.disable_lazy_transactions!
1649+
Topic.lease_connection.disable_lazy_transactions!
16501650

16511651
capture_sql do
16521652
# RealTransaction (begin..commit)
@@ -1889,12 +1889,12 @@ class StatementCacheTest < ActiveRecord::TestCase
18891889
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
18901890
coerce_tests! :test_statement_cache_values_differ
18911891
def test_statement_cache_values_differ_coerced
1892-
Book.connection.remove_index(:books, column: [:author_id, :name])
1892+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
18931893

18941894
original_test_statement_cache_values_differ
18951895
ensure
18961896
Book.where(author_id: nil, name: 'my book').delete_all
1897-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
1897+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
18981898
end
18991899
end
19001900
end
@@ -2124,7 +2124,7 @@ def test_merge_doesnt_duplicate_same_clauses_coerced
21242124

21252125
non_mary_and_bob = Author.where.not(id: [mary, bob])
21262126

2127-
author_id = Author.connection.quote_table_name("authors.id")
2127+
author_id = Author.lease_connection.quote_table_name("authors.id")
21282128
assert_queries_match(/WHERE #{Regexp.escape(author_id)} NOT IN \((@\d), \g<1>\)'/) do
21292129
assert_equal [david], non_mary_and_bob.merge(non_mary_and_bob)
21302130
end
@@ -2151,56 +2151,56 @@ class EnumTest < ActiveRecord::TestCase
21512151
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
21522152
coerce_tests! %r{enums are distinct per class}
21532153
test "enums are distinct per class coerced" do
2154-
Book.connection.remove_index(:books, column: [:author_id, :name])
2154+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
21552155

21562156
send(:'original_enums are distinct per class')
21572157
ensure
21582158
Book.where(author_id: nil, name: nil).delete_all
2159-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2159+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
21602160
end
21612161

21622162
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
21632163
coerce_tests! %r{creating new objects with enum scopes}
21642164
test "creating new objects with enum scopes coerced" do
2165-
Book.connection.remove_index(:books, column: [:author_id, :name])
2165+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
21662166

21672167
send(:'original_creating new objects with enum scopes')
21682168
ensure
21692169
Book.where(author_id: nil, name: nil).delete_all
2170-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2170+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
21712171
end
21722172

21732173
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
21742174
coerce_tests! %r{enums are inheritable}
21752175
test "enums are inheritable coerced" do
2176-
Book.connection.remove_index(:books, column: [:author_id, :name])
2176+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
21772177

21782178
send(:'original_enums are inheritable')
21792179
ensure
21802180
Book.where(author_id: nil, name: nil).delete_all
2181-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2181+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
21822182
end
21832183

21842184
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
21852185
coerce_tests! %r{declare multiple enums at a time}
21862186
test "declare multiple enums at a time coerced" do
2187-
Book.connection.remove_index(:books, column: [:author_id, :name])
2187+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
21882188

21892189
send(:'original_declare multiple enums at a time')
21902190
ensure
21912191
Book.where(author_id: nil, name: nil).delete_all
2192-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2192+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
21932193
end
21942194

21952195
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
21962196
coerce_tests! %r{serializable\? with large number label}
21972197
test "serializable? with large number label coerced" do
2198-
Book.connection.remove_index(:books, column: [:author_id, :name])
2198+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
21992199

22002200
send(:'original_serializable\? with large number label')
22012201
ensure
22022202
Book.where(author_id: nil, name: nil).delete_all
2203-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2203+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
22042204
end
22052205
end
22062206

@@ -2401,45 +2401,45 @@ class FieldOrderedValuesTest < ActiveRecord::TestCase
24012401
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
24022402
coerce_tests! :test_in_order_of_with_enums_values
24032403
def test_in_order_of_with_enums_values_coerced
2404-
Book.connection.remove_index(:books, column: [:author_id, :name])
2404+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
24052405

24062406
original_test_in_order_of_with_enums_values
24072407
ensure
24082408
Book.where(author_id: nil, name: nil).delete_all
2409-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2409+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
24102410
end
24112411

24122412
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
24132413
coerce_tests! :test_in_order_of_with_string_column
24142414
def test_in_order_of_with_string_column_coerced
2415-
Book.connection.remove_index(:books, column: [:author_id, :name])
2415+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
24162416

24172417
original_test_in_order_of_with_string_column
24182418
ensure
24192419
Book.where(author_id: nil, name: nil).delete_all
2420-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2420+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
24212421
end
24222422

24232423
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
24242424
coerce_tests! :test_in_order_of_with_enums_keys
24252425
def test_in_order_of_with_enums_keys_coerced
2426-
Book.connection.remove_index(:books, column: [:author_id, :name])
2426+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
24272427

24282428
original_test_in_order_of_with_enums_keys
24292429
ensure
24302430
Book.where(author_id: nil, name: nil).delete_all
2431-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2431+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
24322432
end
24332433

24342434
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
24352435
coerce_tests! :test_in_order_of_with_nil
24362436
def test_in_order_of_with_nil_coerced
2437-
Book.connection.remove_index(:books, column: [:author_id, :name])
2437+
Book.lease_connection.remove_index(:books, column: [:author_id, :name])
24382438

24392439
original_test_in_order_of_with_nil
24402440
ensure
24412441
Book.where(author_id: nil, name: nil).delete_all
2442-
Book.connection.add_index(:books, [:author_id, :name], unique: true)
2442+
Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
24432443
end
24442444
end
24452445

0 commit comments

Comments
 (0)