Skip to content

Commit af1cb58

Browse files
authored
Fix tests (#1055)
1 parent 9413096 commit af1cb58

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed

‎./workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
ruby: [2.5.9, 2.6.7, 2.7.3, 3.0.1]
16+
ruby:
17+
- 2.7.5
18+
- 3.0.3
1719

1820
steps:
1921
- name: Checkout code

‎Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ git_source(:) { |repo| "https://.com/#{repo}.git" }
77
gemspec
88

99
gem "bcrypt"
10-
gem "pg", ">= 0.18.0"
10+
gem "pg", "~> 1.3"
1111
gem "sqlite3", "~> 1.4"
1212
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
13+
gem "minitest", ">= 5.15.0", "< 5.16"
1314

1415
if ENV["RAILS_SOURCE"]
1516
gemspec path: ENV["RAILS_SOURCE"]

‎appveyor.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ build: off
55
matrix:
66
fast_finish: true
77
allow_failures:
8-
- ruby_version: "25"
9-
- ruby_version: "26"
10-
- ruby_version: "27"
118
- ruby_version: "27-x64"
9+
- ruby_version: "27"
10+
- ruby_version: "30"
11+
- ruby_version: "30-x64"
1212
services:
1313
- mssql2014
1414

@@ -38,9 +38,7 @@ environment:
3838
CI_AZURE_PASS:
3939
secure: cSQp8sk4urJYvq0utpsK+r7J+snJ2wpcdp8RdXJfB+w=
4040
matrix:
41-
- ruby_version: "25-x64"
42-
- ruby_version: "25"
43-
- ruby_version: "26-x64"
44-
- ruby_version: "26"
4541
- ruby_version: "27-x64"
4642
- ruby_version: "27"
43+
- ruby_version: "30"
44+
- ruby_version: "30-x64"

‎test/cases/coerced_tests.rb

+80-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,8 @@ class YamlSerializationTest < ActiveRecord::TestCase
10881088
coerce_tests! :test_types_of_virtual_columns_are_not_changed_on_round_trip
10891089
def test_types_of_virtual_columns_are_not_changed_on_round_trip_coerced
10901090
author = Author.select("authors.*, 5 as posts_count").first
1091-
dumped = YAML.load(YAML.dump(author))
1091+
dumped_author = YAML.dump(author)
1092+
dumped = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(dumped_author) : YAML.load(dumped_author)
10921093
assert_equal 5, author.posts_count
10931094
assert_equal 5, dumped.posts_count
10941095
end
@@ -1207,6 +1208,7 @@ def test_statement_cache_values_differ_coerced
12071208

12081209
original_test_statement_cache_values_differ
12091210
ensure
1211+
Book.where(author_id: nil, name: 'my book').delete_all
12101212
Book.connection.add_index(:books, [:author_id, :name], unique: true)
12111213
end
12121214
end
@@ -1399,6 +1401,7 @@ class EnumTest < ActiveRecord::TestCase
13991401

14001402
send(:'original_enums are distinct per class')
14011403
ensure
1404+
Book.where(author_id: nil, name: nil).delete_all
14021405
Book.connection.add_index(:books, [:author_id, :name], unique: true)
14031406
end
14041407

@@ -1409,6 +1412,7 @@ class EnumTest < ActiveRecord::TestCase
14091412

14101413
send(:'original_creating new objects with enum scopes')
14111414
ensure
1415+
Book.where(author_id: nil, name: nil).delete_all
14121416
Book.connection.add_index(:books, [:author_id, :name], unique: true)
14131417
end
14141418

@@ -1419,6 +1423,7 @@ class EnumTest < ActiveRecord::TestCase
14191423

14201424
send(:'original_enums are inheritable')
14211425
ensure
1426+
Book.where(author_id: nil, name: nil).delete_all
14221427
Book.connection.add_index(:books, [:author_id, :name], unique: true)
14231428
end
14241429

@@ -1429,6 +1434,7 @@ class EnumTest < ActiveRecord::TestCase
14291434

14301435
send(:'original_declare multiple enums at a time')
14311436
ensure
1437+
Book.where(author_id: nil, name: nil).delete_all
14321438
Book.connection.add_index(:books, [:author_id, :name], unique: true)
14331439
end
14341440
end
@@ -1522,3 +1528,76 @@ class ReloadModelsTest < ActiveRecord::TestCase
15221528
# `activesupport/lib/active_support/testing/isolation.rb` exceeds what Windows can handle.
15231529
coerce_tests! :test_has_one_with_reload if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
15241530
end
1531+
1532+
require "models/post"
1533+
class AnnotateTest < ActiveRecord::TestCase
1534+
# Same as original coerced test except our SQL starts with `EXEC sp_executesql`.
1535+
# TODO: Remove coerce after Rails 7 (see https://.com/rails/rails/pull/42027)
1536+
coerce_tests! :test_annotate_wraps_content_in_an_inline_comment
1537+
def test_annotate_wraps_content_in_an_inline_comment_coerced
1538+
quoted_posts_id, quoted_posts = regexp_escape_table_name("posts.id"), regexp_escape_table_name("posts")
1539+
1540+
assert_sql(%r{SELECT #{quoted_posts_id} FROM #{quoted_posts} /\* foo \*/}i) do
1541+
posts = Post.select(:id).annotate("foo")
1542+
assert posts.first
1543+
end
1544+
end
1545+
1546+
# Same as original coerced test except our SQL starts with `EXEC sp_executesql`.
1547+
# TODO: Remove coerce after Rails 7 (see https://.com/rails/rails/pull/42027)
1548+
coerce_tests! :test_annotate_is_sanitized
1549+
def test_annotate_is_sanitized_coerced
1550+
quoted_posts_id, quoted_posts = regexp_escape_table_name("posts.id"), regexp_escape_table_name("posts")
1551+
1552+
assert_sql(%r{SELECT #{quoted_posts_id} FROM #{quoted_posts} /\* \* /foo/ \* \*/}i) do
1553+
posts = Post.select(:id).annotate("*/foo/*")
1554+
assert posts.first
1555+
end
1556+
1557+
assert_sql(%r{SELECT #{quoted_posts_id} FROM #{quoted_posts} /\* \*\* //foo// \*\* \*/}i) do
1558+
posts = Post.select(:id).annotate("**//foo//**")
1559+
assert posts.first
1560+
end
1561+
1562+
assert_sql(%r{SELECT #{quoted_posts_id} FROM #{quoted_posts} /\* \* \* //foo// \* \* \*/}i) do
1563+
posts = Post.select(:id).annotate("* *//foo//* *")
1564+
assert posts.first
1565+
end
1566+
1567+
assert_sql(%r{SELECT #{quoted_posts_id} FROM #{quoted_posts} /\* \* /foo/ \* \*/ /\* \* /bar \*/}i) do
1568+
posts = Post.select(:id).annotate("*/foo/*").annotate("*/bar")
1569+
assert posts.first
1570+
end
1571+
1572+
assert_sql(%r{SELECT #{quoted_posts_id} FROM #{quoted_posts} /\* \+ MAX_EXECUTION_TIME\(1\) \*/}i) do
1573+
posts = Post.select(:id).annotate("+ MAX_EXECUTION_TIME(1)")
1574+
assert posts.first
1575+
end
1576+
end
1577+
end
1578+
1579+
class NestedThroughAssociationsTest < ActiveRecord::TestCase
1580+
# Same as original but replace order with "order(:id)" to ensure that assert_includes_and_joins_equal doesn't raise
1581+
# "A column has been specified more than once in the order by list"
1582+
# Example: original test generate queries like "ORDER BY authors.id, [authors].[id]". We don't support duplicate columns in the order list
1583+
coerce_tests! :test_has_many_through_has_many_with_has_many_through_habtm_source_reflection_preload_via_joins, :test_has_many_through_has_and_belongs_to_many_with_has_many_source_reflection_preload_via_joins
1584+
def test_has_many_through_has_many_with_has_many_through_habtm_source_reflection_preload_via_joins_coerced
1585+
# preload table schemas
1586+
Author.joins(:category_post_comments).first
1587+
1588+
assert_includes_and_joins_equal(
1589+
Author.where("comments.id" => comments(:does_it_hurt).id).order(:id),
1590+
[authors(:david), authors(:mary)], :category_post_comments
1591+
)
1592+
end
1593+
1594+
def test_has_many_through_has_and_belongs_to_many_with_has_many_source_reflection_preload_via_joins_coerced
1595+
# preload table schemas
1596+
Category.joins(:post_comments).first
1597+
1598+
assert_includes_and_joins_equal(
1599+
Category.where("comments.id" => comments(:more_greetings).id).order(:id),
1600+
[categories(:general), categories(:technology)], :post_comments
1601+
)
1602+
end
1603+
end

0 commit comments

Comments
 (0)