Skip to content

Commit 3b69b66

Browse files
authored
Coerce tests that use LIMIT in SQL (#1311)
1 parent 6f9c242 commit 3b69b66

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/cases/coerced_tests.rb

+28-2
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,8 @@ def test_member_on_unloaded_relation_without_match_coerced
11011101
end
11021102

11031103
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
1104-
coerce_tests! :test_implicit_order_column_is_configurable
1105-
def test_implicit_order_column_is_configurable_coerced
1104+
coerce_tests! :test_implicit_order_column_is_configurable_with_a_single_value
1105+
def test_implicit_order_column_is_configurable_with_a_single_value_coerced
11061106
old_implicit_order_column = Topic.implicit_order_column
11071107
Topic.implicit_order_column = "title"
11081108

@@ -1117,6 +1117,32 @@ def test_implicit_order_column_is_configurable_coerced
11171117
Topic.implicit_order_column = old_implicit_order_column
11181118
end
11191119

1120+
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
1121+
coerce_tests! :test_implicit_order_column_is_configurable_with_multiple_values
1122+
def test_implicit_order_column_is_configurable_with_multiple_values_coerced
1123+
old_implicit_order_column = Topic.implicit_order_column
1124+
Topic.implicit_order_column = ["title", "author_name"]
1125+
1126+
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) {
1127+
Topic.last
1128+
}
1129+
ensure
1130+
Topic.implicit_order_column = old_implicit_order_column
1131+
end
1132+
1133+
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
1134+
coerce_tests! :test_ordering_does_not_append_primary_keys_or_query_constraints_if_passed_an_implicit_order_column_array_ending_in_nil
1135+
def test_ordering_does_not_append_primary_keys_or_query_constraints_if_passed_an_implicit_order_column_array_ending_in_nil_coerced
1136+
old_implicit_order_column = Topic.implicit_order_column
1137+
Topic.implicit_order_column = ["author_name", nil]
1138+
1139+
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) {
1140+
Topic.last
1141+
}
1142+
ensure
1143+
Topic.implicit_order_column = old_implicit_order_column
1144+
end
1145+
11201146
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
11211147
coerce_tests! :test_implicit_order_set_to_primary_key
11221148
def test_implicit_order_set_to_primary_key_coerced

0 commit comments

Comments
 (0)