Skip to content

Commit f38562b

Browse files
authored
Coerce query assertion test (#1184)
1 parent f3b83d0 commit f38562b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/cases/coerced_tests.rb

+23
Original file line numberDiff line numberDiff line change
@@ -2711,3 +2711,26 @@ def test_relation_explain_with_last_coerced
27112711
assert_match(expected_query, message)
27122712
end
27132713
end
2714+
2715+
module ActiveRecord
2716+
module Assertions
2717+
class QueryAssertionsTest < ActiveSupport::TestCase
2718+
# Query slightly different in original test.
2719+
coerce_tests! :test_assert_queries_match
2720+
def test_assert_queries_match_coerced
2721+
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 1) { Post.first }
2722+
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i) { Post.first }
2723+
2724+
error = assert_raises(Minitest::Assertion) {
2725+
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 2) { Post.first }
2726+
}
2727+
assert_match(/1 instead of 2 queries/, error.message)
2728+
2729+
error = assert_raises(Minitest::Assertion) {
2730+
assert_queries_match(/ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY/i, count: 0) { Post.first }
2731+
}
2732+
assert_match(/1 instead of 0 queries/, error.message)
2733+
end
2734+
end
2735+
end
2736+
end

0 commit comments

Comments
 (0)