Skip to content

Commit

Permalink
fix more
Browse files Browse the repository at this point in the history
  • Loading branch information
BuonOmo committed Aug 29, 2024
1 parent f4d08cd commit 0038f30
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ group :development, :test do
gem "mocha", "~> 1.14.0"
gem "sqlite3", "~> 1.4.4"

gem "minitest", "~> 5.15.0"
gem "minitest", "~> 5.15"
end
2 changes: 1 addition & 1 deletion test/cases/associations/eager_load_nested_include_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def generate_test_object_graphs
def test_include_query
res = ShapeExpression.all.merge!(includes: [ :shape, { paint: :non_poly } ]).to_a
assert_equal NUM_SHAPE_EXPRESSIONS, res.size
assert_queries(0) do
assert_queries_count(0) do
res.each do |se|
assert_not_nil se.paint.non_poly, "this is the association that was loading incorrectly before the change"
assert_not_nil se.shape, "just making sure other associations still work"
Expand Down
12 changes: 6 additions & 6 deletions test/cases/associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_belongs_to_with_annotation_includes_a_query_comment
assert_not_predicate log, :empty?
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?

assert_sql(%r{/\* that tells jokes \*/}) do
assert_queries_match(%r{/\* that tells jokes \*/}) do
pirate.parrot_with_annotation
end
end
Expand All @@ -40,7 +40,7 @@ def test_has_and_belongs_to_many_with_annotation_includes_a_query_comment
assert_not_predicate log, :empty?
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?

assert_sql(%r{/\* that are very colorful \*/}) do
assert_queries_match(%r{/\* that are very colorful \*/}) do
pirate.parrots_with_annotation.first
end
end
Expand All @@ -55,7 +55,7 @@ def test_has_one_with_annotation_includes_a_query_comment
assert_not_predicate log, :empty?
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?

assert_sql(%r{/\* that is a rocket \*/}) do
assert_queries_match(%r{/\* that is a rocket \*/}) do
pirate.ship_with_annotation
end
end
Expand All @@ -70,7 +70,7 @@ def test_has_many_with_annotation_includes_a_query_comment
assert_not_predicate log, :empty?
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?

assert_sql(%r{/\* that are also parrots \*/}) do
assert_queries_match(%r{/\* that are also parrots \*/}) do
pirate.birds_with_annotation.first
end
end
Expand All @@ -85,7 +85,7 @@ def test_has_many_through_with_annotation_includes_a_query_comment
assert_not_predicate log, :empty?
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?

assert_sql(%r{/\* yarrr \*/}) do
assert_queries_match(%r{/\* yarrr \*/}) do
pirate.treasure_estimates_with_annotation.first
end
end
Expand All @@ -100,7 +100,7 @@ def test_has_many_through_with_annotation_includes_a_query_comment_when_eager_lo
assert_not_predicate log, :empty?
assert_predicate log.select { |query| query.match?(%r{/\*}) }, :empty?

assert_sql(%r{/\* yarrr \*/}) do
assert_queries_match(%r{/\* yarrr \*/}) do
SpacePirate.includes(:treasure_estimates_with_annotation, :treasures).first
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/cases/relation/merging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def test_merge_doesnt_duplicate_same_clauses
non_mary_and_bob = Author.where.not(id: [mary, bob])

author_id = Author.lease_connection.quote_table_name("authors.id")
assert_sql(/WHERE #{Regexp.escape(author_id)} NOT IN \((\?|\W?\w?\d), \g<1>\)\z/) do
assert_queries_match(/WHERE #{Regexp.escape(author_id)} NOT IN \((\?|\W?\w?\d), \g<1>\)\z/) do
assert_equal [david], non_mary_and_bob.merge(non_mary_and_bob)
end

only_david = Author.where("#{author_id} IN (?)", david)

# This is the only change between this and the ActiveRecord test.
# We need '' around the 1.
assert_sql(/WHERE \(#{Regexp.escape(author_id)} IN \('1'\)\)\z/) do
assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \('1'\)\)\z/) do
assert_equal [david], only_david.merge(only_david)
end
end
Expand Down
18 changes: 9 additions & 9 deletions test/cases/relation/table_hints_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ def test_add_hint
force_index = ->(q) { q.force_index("index_posts_on_author_id") }
index_hint = ->(q) { q.index_hint("NO_FULL_SCAN") }

assert_sql(/"posts"@\{FORCE_INDEX=index_posts_on_author_id\}/) do
assert_queries_match(/"posts"@\{FORCE_INDEX=index_posts_on_author_id\}/) do
Post.then(&force_index).take
end

assert_sql(/"posts"@\{NO_FULL_SCAN\}/) do
assert_queries_match(/"posts"@\{NO_FULL_SCAN\}/) do
Post.then(&index_hint).take
end

[force_index, index_hint].permutation do |procs|
assert_sql(/"posts"@\{NO_FULL_SCAN,FORCE_INDEX=index_posts_on_author_id\}/) do
assert_queries_match(/"posts"@\{NO_FULL_SCAN,FORCE_INDEX=index_posts_on_author_id\}/) do
Post.then(&procs.reduce(:<<)).take
end
end
end

def test_choose_index_order
idx = "index_posts_on_author_id"
assert_sql(/"posts"@\{FORCE_INDEX=#{idx},ASC\}/) do
assert_queries_match(/"posts"@\{FORCE_INDEX=#{idx},ASC\}/) do
Post.force_index(idx, direction: "ASC").take
end
assert_sql(/"posts"@\{FORCE_INDEX=#{idx},DESC\}/) do
assert_queries_match(/"posts"@\{FORCE_INDEX=#{idx},DESC\}/) do
Post.force_index(idx, direction: "DESC").take
end
assert_sql(/"posts"@\{NO_FULL_SCAN,FORCE_INDEX=#{idx},DESC\}/) do
assert_queries_match(/"posts"@\{NO_FULL_SCAN,FORCE_INDEX=#{idx},DESC\}/) do
Post.force_index(idx, direction: "DESC").index_hint("NO_FULL_SCAN").take
end
end
Expand All @@ -44,16 +44,16 @@ def test_use_other_table
index_hint = ->(q) { q.index_hint("NO_FULL_SCAN") }
post_from = Post.select(:id).from("subscribers")

assert_sql(/subscribers@\{FORCE_INDEX=index_subscribers_on_nick\}/) do
assert_queries_match(/subscribers@\{FORCE_INDEX=index_subscribers_on_nick\}/) do
post_from.then(&force_index).take
end

assert_sql(/subscribers@\{NO_FULL_SCAN\}/) do
assert_queries_match(/subscribers@\{NO_FULL_SCAN\}/) do
post_from.then(&index_hint).take
end

[force_index, index_hint].permutation do |procs|
assert_sql(/subscribers@\{NO_FULL_SCAN,FORCE_INDEX=index_subscribers_on_nick\}/) do
assert_queries_match(/subscribers@\{NO_FULL_SCAN,FORCE_INDEX=index_subscribers_on_nick\}/) do
post_from.then(&procs.reduce(:<<)).take
end
end
Expand Down

0 comments on commit 0038f30

Please sign in to comment.