Skip to content

Commit 9849019

Browse files
authored
Fixed tests (#1167)
1 parent e7c4f6d commit 9849019

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _calculate(operation, column_name)
4141
if operation == "count"
4242
unless distinct_value || distinct_select?(column_name || select_for_count)
4343
relation.distinct!
44-
relation.select_values = [ klass.primary_key || table[Arel.star] ]
44+
relation.select_values = Array(klass.primary_key || table[Arel.star])
4545
end
4646
# PostgreSQL: ORDER BY expressions must appear in SELECT list when using DISTINCT
4747
# Start of monkey-patch

test/cases/coerced_tests.rb

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,25 @@ def test_update_date_time_attributes_with_default_timezone_local
243243
end
244244
end
245245

246+
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
247+
# SQL Server does not have query for release_savepoint
248+
coerce_tests! :test_associate_existing
249+
def test_associate_existing_coerced
250+
post = posts(:thinking)
251+
person = people(:david)
252+
253+
assert_queries_count(2) do
254+
post.people << person
255+
end
256+
257+
assert_queries_count(1) do
258+
assert_includes post.people, person
259+
end
260+
261+
assert_includes post.reload.people.reload, person
262+
end
263+
end
264+
246265
class BelongsToAssociationsTest < ActiveRecord::TestCase
247266
# Since @client.firm is a single first/top, and we use FETCH the order clause is used.
248267
coerce_tests! :test_belongs_to_does_not_use_order_by
@@ -1492,11 +1511,11 @@ def self.search_as_method(term)
14921511
}
14931512
end
14941513

1495-
assert_queries_match(/LIKE N'20!% !_reduction!_!!'/) do
1514+
assert_queries_match(/LIKE @0/) do
14961515
searchable_post.search_as_method("20% _reduction_!").to_a
14971516
end
14981517

1499-
assert_queries_match(/LIKE N'20!% !_reduction!_!!'/) do
1518+
assert_queries_match(/LIKE @0/) do
15001519
searchable_post.search_as_scope("20% _reduction_!").to_a
15011520
end
15021521
end
@@ -2103,7 +2122,7 @@ def test_merge_doesnt_duplicate_same_clauses_coerced
21032122

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

2106-
assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \(1\)\)\z/) do
2125+
assert_queries_match(/WHERE \(#{Regexp.escape(author_id)} IN \(@\d\)\)/) do
21072126
assert_equal [david], only_david.merge(only_david)
21082127
end
21092128
end
@@ -2456,6 +2475,25 @@ def test_sqlcommenter_format_value_string_coercible_coerced
24562475
end
24572476
end
24582477

2478+
# SQL requires double single-quotes.
2479+
coerce_tests! :test_sqlcommenter_format_allows_string_keys
2480+
def test_sqlcommenter_format_allows_string_keys_coerced
2481+
ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
2482+
2483+
ActiveRecord::QueryLogs.tags = [
2484+
:application,
2485+
{
2486+
"string" => "value",
2487+
tracestate: "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7",
2488+
custom_proc: -> { "Joe's Shack" }
2489+
},
2490+
]
2491+
2492+
assert_queries_match(%r{custom_proc=''Joe%27s%20Shack'',string=''value'',tracestate=''congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7''\*/}) do
2493+
Dashboard.first
2494+
end
2495+
end
2496+
24592497
# Invalid character encoding causes `ActiveRecord::StatementInvalid` error similar to Postgres.
24602498
coerce_tests! :test_invalid_encoding_query
24612499
def test_invalid_encoding_query_coerced

0 commit comments

Comments
 (0)