aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-05-06 11:55:21 -0500
committerSean Griffin <sean@seantheprogrammer.com>2016-05-06 11:58:01 -0500
commit96f3f3d8267167d5d4c5697f2299756cfa7e37d4 (patch)
tree4159b2de70d916cb85d420906d4a2acf6b414950 /activerecord/test
parentc763c00b5e7cdfc7e5523502f7be77314cbfff7b (diff)
downloadrails-96f3f3d8267167d5d4c5697f2299756cfa7e37d4.tar.gz
rails-96f3f3d8267167d5d4c5697f2299756cfa7e37d4.tar.bz2
rails-96f3f3d8267167d5d4c5697f2299756cfa7e37d4.zip
Allow the connection adapters to determine the order of bind params
In 5.0 we use bind parameters for limit and offset, while in 4.2 we used the values directly. The code as it was written assumed that limit and offset worked as `LIMIT ? OFFSET ?`. Both Oracle and SQL Server have a different syntax, where the offset is stated before the limit. We delegate this behavior to the connection adapter so that these adapters are able to determine how the bind parameters are flattened based on what order their specification has the various clauses appear. Fixes #24775
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 95e4230a58..3e2fadc294 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1989,4 +1989,22 @@ class RelationTest < ActiveRecord::TestCase
def test_relation_join_method
assert_equal 'Thank you for the welcome,Thank you again for the welcome', Post.first.comments.join(",")
end
+
+ def test_connection_adapters_can_reorder_binds
+ posts = Post.limit(1).offset(2)
+
+ stubbed_connection = Post.connection.dup
+ def stubbed_connection.combine_bind_parameters(**kwargs)
+ offset = kwargs[:offset]
+ kwargs[:offset] = kwargs[:limit]
+ kwargs[:limit] = offset
+ super(**kwargs)
+ end
+
+ posts.define_singleton_method(:connection) do
+ stubbed_connection
+ end
+
+ assert_equal 2, posts.to_a.length
+ end
end