Skip to content

Commit 7d65d79

Browse files
committed
Fix tests
1 parent ccb2021 commit 7d65d79

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ def delete(arel, name = nil, binds = [])
7878

7979
# Add `SELECT @@ROWCOUNT` to the end of the SQL to get the number of affected rows. This is needed because SQL Server does not return the number of affected rows in the same way as other databases.
8080
sql = intent.processed_sql.present? ? intent.processed_sql : intent.raw_sql
81+
ensure_writes_are_allowed(sql) if write_query?(sql)
8182
intent.processed_sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows"
8283

8384
affected_rows(raw_execute(intent))
8485
end
8586

8687
# Executes the update statement and returns the number of rows affected.
8788
def update(arel, name = nil, binds = [])
88-
# Clear query cache if the connection pool is configured to do so.
89+
# Clear query cache if the connection pool is configured to do so.
8990
if pool.dirties_query_cache
9091
ActiveRecord::Base.clear_query_caches_for_current_thread
9192
end
@@ -97,6 +98,7 @@ def update(arel, name = nil, binds = [])
9798

9899
# Add `SELECT @@ROWCOUNT` to the end of the SQL to get the number of affected rows. This is needed because SQL Server does not return the number of affected rows in the same way as other databases.
99100
sql = intent.processed_sql.present? ? intent.processed_sql : intent.raw_sql
101+
ensure_writes_are_allowed(sql) if write_query?(sql)
100102
intent.processed_sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows"
101103

102104
affected_rows(raw_execute(intent))

test/support/query_assertions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def assert_queries_count(count = nil, include_schema: false, &block)
1414
# End of monkey-patch
1515

1616
if count
17-
assert_equal count, queries.size, "#{queries.size} instead of #{count} queries were executed#{queries.empty? ? '' : ". Queries:\n\n#{queries.join("\n\n")}"}"
17+
assert_equal count, queries.size, "#{queries.size} instead of #{count} queries were executed#{". Queries:\n\n#{queries.join("\n\n")}" unless queries.empty?}"
1818
else
1919
assert_operator queries.size, :>=, 1, "1 or more queries expected, but none were executed"
2020
end

0 commit comments

Comments
 (0)