Skip to content
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

Coerce tests that use LIMIT in SQL #1311

Merged
merged 1 commit into from
Mar 12, 2025
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
30 changes: 28 additions & 2 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ def test_member_on_unloaded_relation_without_match_coerced
end

# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
coerce_tests! :test_implicit_order_column_is_configurable
def test_implicit_order_column_is_configurable_coerced
coerce_tests! :test_implicit_order_column_is_configurable_with_a_single_value
def test_implicit_order_column_is_configurable_with_a_single_value_coerced
old_implicit_order_column = Topic.implicit_order_column
Topic.implicit_order_column = "title"

Expand All @@ -1117,6 +1117,32 @@ def test_implicit_order_column_is_configurable_coerced
Topic.implicit_order_column = old_implicit_order_column
end

# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
coerce_tests! :test_implicit_order_column_is_configurable_with_multiple_values
def test_implicit_order_column_is_configurable_with_multiple_values_coerced
old_implicit_order_column = Topic.implicit_order_column
Topic.implicit_order_column = ["title", "author_name"]

assert_queries_match(/ORDER BY #{Regexp.escape(quote_table_name("topics.title"))} DESC, #{Regexp.escape(quote_table_name("topics.author_name"))} DESC, #{Regexp.escape(quote_table_name("topics.id"))} DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i) {
Topic.last
}
ensure
Topic.implicit_order_column = old_implicit_order_column
end

# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
coerce_tests! :test_ordering_does_not_append_primary_keys_or_query_constraints_if_passed_an_implicit_order_column_array_ending_in_nil
def test_ordering_does_not_append_primary_keys_or_query_constraints_if_passed_an_implicit_order_column_array_ending_in_nil_coerced
old_implicit_order_column = Topic.implicit_order_column
Topic.implicit_order_column = ["author_name", nil]

assert_queries_match(/ORDER BY #{Regexp.escape(quote_table_name("topics.author_name"))} DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i) {
Topic.last
}
ensure
Topic.implicit_order_column = old_implicit_order_column
end

# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
coerce_tests! :test_implicit_order_set_to_primary_key
def test_implicit_order_set_to_primary_key_coerced
Expand Down