Skip to content

Fixed tests #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _calculate(operation, column_name)
if operation == "count"
unless distinct_value || distinct_select?(column_name || select_for_count)
relation.distinct!
relation.select_values = [ klass.primary_key || table[Arel.star] ]
relation.select_values = Array(klass.primary_key || table[Arel.star])
end
# PostgreSQL: ORDER BY expressions must appear in SELECT list when using DISTINCT
# Start of monkey-patch
Expand Down
44 changes: 41 additions & 3 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ def test_update_date_time_attributes_with_default_timezone_local
end
end

class HasManyThroughAssociationsTest < ActiveRecord::TestCase
# SQL Server does not have query for release_savepoint
coerce_tests! :test_associate_existing
def test_associate_existing_coerced
post = posts(:thinking)
person = people(:david)

assert_queries_count(2) do
post.people << person
end

assert_queries_count(1) do
assert_includes post.people, person
end

assert_includes post.reload.people.reload, person
end
end

class BelongsToAssociationsTest < ActiveRecord::TestCase
# Since @client.firm is a single first/top, and we use FETCH the order clause is used.
coerce_tests! :test_belongs_to_does_not_use_order_by
Expand Down Expand Up @@ -1492,11 +1511,11 @@ def self.search_as_method(term)
}
end

assert_queries_match(/LIKE N'20!% !_reduction!_!!'/) do
assert_queries_match(/LIKE @0/) do
searchable_post.search_as_method("20% _reduction_!").to_a
end

assert_queries_match(/LIKE N'20!% !_reduction!_!!'/) do
assert_queries_match(/LIKE @0/) do
searchable_post.search_as_scope("20% _reduction_!").to_a
end
end
Expand Down Expand Up @@ -2103,7 +2122,7 @@ def test_merge_doesnt_duplicate_same_clauses_coerced

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

assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \(1\)\)\z/) do
assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \(@\d\)\)/) do
assert_equal [david], only_david.merge(only_david)
end
end
Expand Down Expand Up @@ -2456,6 +2475,25 @@ def test_sqlcommenter_format_value_string_coercible_coerced
end
end

# SQL requires double single-quotes.
coerce_tests! :test_sqlcommenter_format_allows_string_keys
def test_sqlcommenter_format_allows_string_keys_coerced
ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)

ActiveRecord::QueryLogs.tags = [
:application,
{
"string" => "value",
tracestate: "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7",
custom_proc: -> { "Joe's Shack" }
},
]

assert_queries_match(%r{custom_proc=''Joe%27s%20Shack'',string=''value'',tracestate=''congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7''\*/}) do
Dashboard.first
end
end

# Invalid character encoding causes `ActiveRecord::StatementInvalid` error similar to Postgres.
coerce_tests! :test_invalid_encoding_query
def test_invalid_encoding_query_coerced
Expand Down
Loading