Skip to content

Commit e872d91

Browse files
committed
Changed query cached test
Space already being added by ORDER BY string Changed test to include resetting column information
1 parent 5185b3c commit e872d91

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/arel/visitors/sqlserver.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ def visit_Arel_Nodes_SelectStatement_SQLServer_Lock collector, options = {}
153153
def visit_Orders_And_Let_Fetch_Happen o, collector
154154
make_Fetch_Possible_And_Deterministic o
155155
unless o.orders.empty?
156-
collector << " "
157156
collector << " ORDER BY "
158157
len = o.orders.length - 1
159158
o.orders.each_with_index { |x, i|

test/cases/coerced_tests.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,33 @@ def test_cache_does_not_wrap_results_in_arrays_coerced
756756
assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
757757
end
758758
end
759+
760+
761+
# Same as original test except that we expect one query to be performed to retrieve the table's primary key.
762+
# When we generate the SQL for the `find` it includes ordering on the primary key. If we reset the column
763+
# information then the primary key needs to be retrieved from the database again to generate the SQL causing the
764+
# original test's `assert_no_queries` assertion to fail. Assert that the query was to get the primary key.
765+
coerce_tests! :test_query_cached_even_when_types_are_reset
766+
def test_query_cached_even_when_types_are_reset_coerced
767+
Task.cache do
768+
# Warm the cache
769+
Task.find(1)
770+
771+
# Preload the type cache again (so we don't have those queries issued during our assertions)
772+
Task.connection.send(:reload_type_map)
773+
774+
# Clear places where type information is cached
775+
Task.reset_column_information
776+
Task.initialize_find_by_cache
777+
Task.define_attribute_methods
778+
779+
assert_queries(1, ignore_none: true) do
780+
Task.find(1)
781+
end
782+
783+
assert_includes ActiveRecord::SQLCounter.log_all.first , "TC.CONSTRAINT_TYPE = N''PRIMARY KEY''"
784+
end
785+
end
759786
end
760787

761788

0 commit comments

Comments
 (0)