Skip to content

Commit d67c2f6

Browse files
authored
Rails 6.1 fixes: Use renamed connection_config method and rewrite coerced tests using unsafe raw SQL (#882)
* Use renamed ARTest.connfiguration_config method See more: rails/rails#38007 * rewrite coerced specs using unsafe raw SQL Support for using unsafe raw SQL in `ActiveRecord::Relation` methods has been removed. See rails/rails@317465a
1 parent 31bc074 commit d67c2f6

File tree

2 files changed

+24
-43
lines changed

2 files changed

+24
-43
lines changed

test/cases/coerced_tests.rb

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,111 +1233,92 @@ class UnsafeRawSqlTest < ActiveRecord::TestCase
12331233
# Use LEN() vs length() function.
12341234
coerce_tests! %r{order: always allows Arel}
12351235
test "order: always allows Arel" do
1236-
ids_depr = with_unsafe_raw_sql_deprecated { Post.order(Arel.sql("len(title)")).pluck(:title) }
1237-
ids_disabled = with_unsafe_raw_sql_disabled { Post.order(Arel.sql("len(title)")).pluck(:title) }
1236+
titles = Post.order(Arel.sql("len(title)")).pluck(:title)
12381237

1239-
assert_equal ids_depr, ids_disabled
1238+
assert_not_empty titles
12401239
end
12411240

12421241
# Use LEN() vs length() function.
12431242
coerce_tests! %r{pluck: always allows Arel}
12441243
test "pluck: always allows Arel" do
1245-
values_depr = with_unsafe_raw_sql_deprecated { Post.includes(:comments).pluck(:title, Arel.sql("len(title)")) }
1246-
values_disabled = with_unsafe_raw_sql_disabled { Post.includes(:comments).pluck(:title, Arel.sql("len(title)")) }
1244+
excepted_values = Post.includes(:comments).pluck(:title).map { |title| [title, title.size] }
1245+
values = Post.includes(:comments).pluck(:title, Arel.sql("len(title)"))
12471246

1248-
assert_equal values_depr, values_disabled
1247+
assert_equal excepted_values, values
12491248
end
12501249

12511250
# Use LEN() vs length() function.
12521251
coerce_tests! %r{order: allows valid Array arguments}
12531252
test "order: allows valid Array arguments" do
12541253
ids_expected = Post.order(Arel.sql("author_id, len(title)")).pluck(:id)
12551254

1256-
ids_depr = with_unsafe_raw_sql_deprecated { Post.order(["author_id", "len(title)"]).pluck(:id) }
1257-
ids_disabled = with_unsafe_raw_sql_disabled { Post.order(["author_id", "len(title)"]).pluck(:id) }
1255+
ids = Post.order(["author_id", "len(title)"]).pluck(:id)
12581256

1259-
assert_equal ids_expected, ids_depr
1260-
assert_equal ids_expected, ids_disabled
1257+
assert_equal ids_expected, ids
12611258
end
12621259

12631260
test "order: allows string column names that are quoted" do
12641261
ids_expected = Post.order(Arel.sql("id")).pluck(:id)
12651262

1266-
ids_depr = with_unsafe_raw_sql_deprecated { Post.order("[id]").pluck(:id) }
1267-
ids_disabled = with_unsafe_raw_sql_disabled { Post.order("[id]").pluck(:id) }
1263+
ids = Post.order("[id]").pluck(:id)
12681264

1269-
assert_equal ids_expected, ids_depr
1270-
assert_equal ids_expected, ids_disabled
1265+
assert_equal ids_expected, ids
12711266
end
12721267

12731268
test "order: allows string column names that are quoted with table" do
12741269
ids_expected = Post.order(Arel.sql("id")).pluck(:id)
12751270

1276-
ids_depr = with_unsafe_raw_sql_deprecated { Post.order("[posts].[id]").pluck(:id) }
1277-
ids_disabled = with_unsafe_raw_sql_disabled { Post.order("[posts].[id]").pluck(:id) }
1271+
ids = Post.order("[posts].[id]").pluck(:id)
12781272

1279-
assert_equal ids_expected, ids_depr
1280-
assert_equal ids_expected, ids_disabled
1273+
assert_equal ids_expected, ids
12811274
end
12821275

12831276
test "order: allows string column names that are quoted with table and user" do
12841277
ids_expected = Post.order(Arel.sql("id")).pluck(:id)
12851278

1286-
ids_depr = with_unsafe_raw_sql_deprecated { Post.order("[dbo].[posts].[id]").pluck(:id) }
1287-
ids_disabled = with_unsafe_raw_sql_disabled { Post.order("[dbo].[posts].[id]").pluck(:id) }
1279+
ids = Post.order("[dbo].[posts].[id]").pluck(:id)
12881280

1289-
assert_equal ids_expected, ids_depr
1290-
assert_equal ids_expected, ids_disabled
1281+
assert_equal ids_expected, ids
12911282
end
12921283

12931284
test "order: allows string column names that are quoted with table, user and database" do
12941285
ids_expected = Post.order(Arel.sql("id")).pluck(:id)
12951286

1296-
ids_depr = with_unsafe_raw_sql_deprecated { Post.order("[activerecord_unittest].[dbo].[posts].[id]").pluck(:id) }
1297-
ids_disabled = with_unsafe_raw_sql_disabled { Post.order("[activerecord_unittest].[dbo].[posts].[id]").pluck(:id) }
1287+
ids = Post.order("[activerecord_unittest].[dbo].[posts].[id]").pluck(:id)
12981288

1299-
assert_equal ids_expected, ids_depr
1300-
assert_equal ids_expected, ids_disabled
1289+
assert_equal ids_expected, ids
13011290
end
13021291

13031292
test "pluck: allows string column name that are quoted" do
13041293
titles_expected = Post.pluck(Arel.sql("title"))
13051294

1306-
titles_depr = with_unsafe_raw_sql_deprecated { Post.pluck("[title]") }
1307-
titles_disabled = with_unsafe_raw_sql_disabled { Post.pluck("[title]") }
1295+
titles = Post.pluck("[title]")
13081296

1309-
assert_equal titles_expected, titles_depr
1310-
assert_equal titles_expected, titles_disabled
1297+
assert_equal titles_expected, titles
13111298
end
13121299

13131300
test "pluck: allows string column name that are quoted with table" do
13141301
titles_expected = Post.pluck(Arel.sql("title"))
13151302

1316-
titles_depr = with_unsafe_raw_sql_deprecated { Post.pluck("[posts].[title]") }
1317-
titles_disabled = with_unsafe_raw_sql_disabled { Post.pluck("[posts].[title]") }
1303+
titles = Post.pluck("[posts].[title]")
13181304

1319-
assert_equal titles_expected, titles_depr
1320-
assert_equal titles_expected, titles_disabled
1305+
assert_equal titles_expected, titles
13211306
end
13221307

13231308
test "pluck: allows string column name that are quoted with table and user" do
13241309
titles_expected = Post.pluck(Arel.sql("title"))
13251310

1326-
titles_depr = with_unsafe_raw_sql_deprecated { Post.pluck("[dbo].[posts].[title]") }
1327-
titles_disabled = with_unsafe_raw_sql_disabled { Post.pluck("[dbo].[posts].[title]") }
1311+
titles = Post.pluck("[dbo].[posts].[title]")
13281312

1329-
assert_equal titles_expected, titles_depr
1330-
assert_equal titles_expected, titles_disabled
1313+
assert_equal titles_expected, titles
13311314
end
13321315

13331316
test "pluck: allows string column name that are quoted with table, user and database" do
13341317
titles_expected = Post.pluck(Arel.sql("title"))
13351318

1336-
titles_depr = with_unsafe_raw_sql_deprecated { Post.pluck("[activerecord_unittest].[dbo].[posts].[title]") }
1337-
titles_disabled = with_unsafe_raw_sql_disabled { Post.pluck("[activerecord_unittest].[dbo].[posts].[title]") }
1319+
titles = Post.pluck("[activerecord_unittest].[dbo].[posts].[title]")
13381320

1339-
assert_equal titles_expected, titles_depr
1340-
assert_equal titles_expected, titles_disabled
1321+
assert_equal titles_expected, titles
13411322
end
13421323
end
13431324

test/cases/rake_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SQLServerRakeTest < ActiveRecord::TestCase
1010

1111
let(:db_tasks) { ActiveRecord::Tasks::DatabaseTasks }
1212
let(:new_database) { "activerecord_unittest_tasks" }
13-
let(:default_configuration) { ARTest.connection_config["arunit"] }
13+
let(:default_configuration) { ARTest.test_configuration_hashes["arunit"] }
1414
let(:configuration) { default_configuration.merge("database" => new_database) }
1515

1616
before { skip "on azure" if azure_skip }

0 commit comments

Comments
 (0)