Skip to content

Commit 3fd7d44

Browse files
authored
Merge pull request rails#54532 from aidanharan/index-test-index-include
Use adapter support flags instead of checking adapter type in `INDEX INCLUDE` tests
2 parents 3b79de3 + b10bcc3 commit 3fd7d44

File tree

1 file changed

+46
-49
lines changed

1 file changed

+46
-49
lines changed

activerecord/test/cases/migration/index_test.rb

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -257,71 +257,68 @@ def test_add_index
257257
connection.add_index("testings", %w(last_name first_name administrator), name: "named_admin")
258258
connection.remove_index("testings", name: "named_admin")
259259

260-
# Selected adapters support index sort order
261-
if current_adapter?(:SQLite3Adapter, :Mysql2Adapter, :TrilogyAdapter, :PostgreSQLAdapter)
262-
connection.add_index("testings", ["last_name"], order: { last_name: :desc })
263-
connection.remove_index("testings", ["last_name"])
264-
connection.add_index("testings", ["last_name", "first_name"], order: { last_name: :desc })
265-
connection.remove_index("testings", ["last_name", "first_name"])
266-
connection.add_index("testings", ["last_name", "first_name"], order: { last_name: :desc, first_name: :asc })
267-
connection.remove_index("testings", ["last_name", "first_name"])
268-
connection.add_index("testings", ["last_name", "first_name"], order: :desc)
269-
connection.remove_index("testings", ["last_name", "first_name"])
270-
end
260+
connection.add_index("testings", ["last_name"], order: { last_name: :desc })
261+
connection.remove_index("testings", ["last_name"])
262+
connection.add_index("testings", ["last_name", "first_name"], order: { last_name: :desc })
263+
connection.remove_index("testings", ["last_name", "first_name"])
264+
connection.add_index("testings", ["last_name", "first_name"], order: { last_name: :desc, first_name: :asc })
265+
connection.remove_index("testings", ["last_name", "first_name"])
266+
connection.add_index("testings", ["last_name", "first_name"], order: :desc)
267+
connection.remove_index("testings", ["last_name", "first_name"])
271268
end
272269

273-
if current_adapter?(:PostgreSQLAdapter)
274-
def test_add_partial_index
275-
connection.add_index("testings", "last_name", where: "first_name = 'john doe'")
276-
assert connection.index_exists?("testings", "last_name")
270+
def test_add_partial_index
271+
skip("current adapter doesn't support partial indexes") unless supports_partial_index?
277272

278-
connection.remove_index("testings", "last_name")
279-
assert_not connection.index_exists?("testings", "last_name")
280-
end
273+
connection.add_index("testings", "last_name", where: "first_name = 'john doe'")
274+
assert connection.index_exists?("testings", "last_name")
281275

282-
def test_add_index_with_included_column
283-
skip("current adapter doesn't support include indexes") unless supports_index_include?
276+
connection.remove_index("testings", "last_name")
277+
assert_not connection.index_exists?("testings", "last_name")
278+
end
284279

285-
connection.add_index("testings", "last_name", include: :foo)
286-
assert connection.index_exists?("testings", "last_name", include: :foo)
280+
def test_add_index_with_included_column
281+
skip("current adapter doesn't support include indexes") unless supports_index_include?
287282

288-
connection.remove_index("testings", "last_name")
289-
assert_not connection.index_exists?("testings", "last_name")
290-
end
283+
connection.add_index("testings", "last_name", include: :foo)
284+
assert connection.index_exists?("testings", "last_name", include: :foo)
291285

292-
def test_add_index_with_multiple_included_columns
293-
skip("current adapter doesn't support include indexes") unless supports_index_include?
286+
connection.remove_index("testings", "last_name")
287+
assert_not connection.index_exists?("testings", "last_name")
288+
end
294289

295-
connection.add_index("testings", "last_name", include: [:foo, :bar])
296-
assert connection.index_exists?("testings", "last_name", include: [:foo, :bar])
290+
def test_add_index_with_multiple_included_columns
291+
skip("current adapter doesn't support include indexes") unless supports_index_include?
297292

298-
connection.remove_index("testings", "last_name")
299-
assert_not connection.index_exists?("testings", "last_name")
300-
end
293+
connection.add_index("testings", "last_name", include: [:foo, :bar])
294+
assert connection.index_exists?("testings", "last_name", include: [:foo, :bar])
301295

302-
def test_add_index_with_included_column_and_where_clause
303-
skip("current adapter doesn't support include indexes") unless supports_index_include?
296+
connection.remove_index("testings", "last_name")
297+
assert_not connection.index_exists?("testings", "last_name")
298+
end
304299

305-
connection.add_index("testings", "last_name", include: :foo, where: "first_name = 'john doe'")
306-
assert connection.index_exists?("testings", "last_name", include: :foo, where: "first_name = 'john doe'")
300+
def test_add_index_with_included_column_and_where_clause
301+
skip("current adapter doesn't support include indexes") unless supports_index_include?
307302

308-
connection.remove_index("testings", "last_name")
309-
assert_not connection.index_exists?("testings", "last_name", include: :foo, where: "first_name = 'john doe'")
310-
end
303+
connection.add_index("testings", "last_name", include: :foo, where: "first_name = 'john doe'")
304+
assert connection.index_exists?("testings", "last_name", include: :foo, where: "first_name = 'john doe'")
311305

312-
def test_add_index_with_nulls_not_distinct_assert_exists_with_same_values
313-
skip("current adapter doesn't support nulls not distinct") unless supports_nulls_not_distinct?
306+
connection.remove_index("testings", "last_name")
307+
assert_not connection.index_exists?("testings", "last_name", include: :foo, where: "first_name = 'john doe'")
308+
end
314309

315-
connection.add_index("testings", "last_name", nulls_not_distinct: true)
316-
assert connection.index_exists?("testings", "last_name", nulls_not_distinct: true)
317-
end
310+
def test_add_index_with_nulls_not_distinct_assert_exists_with_same_values
311+
skip("current adapter doesn't support nulls not distinct") unless supports_nulls_not_distinct?
318312

319-
def test_add_index_with_nulls_not_distinct_assert_exists_with_different_values
320-
skip("current adapter doesn't support nulls not distinct") unless supports_nulls_not_distinct?
313+
connection.add_index("testings", "last_name", nulls_not_distinct: true)
314+
assert connection.index_exists?("testings", "last_name", nulls_not_distinct: true)
315+
end
321316

322-
connection.add_index("testings", "last_name", nulls_not_distinct: false)
323-
assert_not connection.index_exists?("testings", "last_name", nulls_not_distinct: true)
324-
end
317+
def test_add_index_with_nulls_not_distinct_assert_exists_with_different_values
318+
skip("current adapter doesn't support nulls not distinct") unless supports_nulls_not_distinct?
319+
320+
connection.add_index("testings", "last_name", nulls_not_distinct: false)
321+
assert_not connection.index_exists?("testings", "last_name", nulls_not_distinct: true)
325322
end
326323

327324
private

0 commit comments

Comments
 (0)