Skip to content

Coerce query assertion test #1184

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 1 commit into from
May 20, 2024
Merged
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
23 changes: 23 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2711,3 +2711,26 @@ def test_relation_explain_with_last_coerced
assert_match(expected_query, message)
end
end

module ActiveRecord
module Assertions
class QueryAssertionsTest < ActiveSupport::TestCase
# Query slightly different in original test.
coerce_tests! :test_assert_queries_match
def test_assert_queries_match_coerced
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 1) { Post.first }
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i) { Post.first }

error = assert_raises(Minitest::Assertion) {
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 2) { Post.first }
}
assert_match(/1 instead of 2 queries/, error.message)

error = assert_raises(Minitest::Assertion) {
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 0) { Post.first }
}
assert_match(/1 instead of 0 queries/, error.message)
end
end
end
end
Loading