aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/statement_cache_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-03-31 13:33:42 -0600
committerSean Griffin <sean@seantheprogrammer.com>2016-03-31 13:41:36 -0600
commit3af40b71f34c70a274e261cd6e6468c613de648e (patch)
tree32fb92f750ed000c58d25c2691b6ea9614bff741 /activerecord/test/cases/statement_cache_test.rb
parent7b82e1c77b48cb351da4e0ed6ea0bac806d4925c (diff)
downloadrails-3af40b71f34c70a274e261cd6e6468c613de648e.tar.gz
rails-3af40b71f34c70a274e261cd6e6468c613de648e.tar.bz2
rails-3af40b71f34c70a274e261cd6e6468c613de648e.zip
Prepared statements shouldn't share a cache with unprepared statements
When prepared statements are enabled, the statement cache caches the SQL directly, including the bind parameters. If a similar query is run later with prepared statements disabled, we need to use a separate cache instead of trying to share the same one. Fixes #24351
Diffstat (limited to 'activerecord/test/cases/statement_cache_test.rb')
-rw-r--r--activerecord/test/cases/statement_cache_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/statement_cache_test.rb b/activerecord/test/cases/statement_cache_test.rb
index a704b861cb..104226010a 100644
--- a/activerecord/test/cases/statement_cache_test.rb
+++ b/activerecord/test/cases/statement_cache_test.rb
@@ -94,5 +94,17 @@ module ActiveRecord
additional_books = cache.execute([], Book, Book.connection)
assert first_books != additional_books
end
+
+ def test_unprepared_statements_dont_share_a_cache_with_prepared_statements
+ Book.create(name: "my book")
+ Book.create(name: "my other book")
+
+ book = Book.find_by(name: "my book")
+ other_book = Book.connection.unprepared_statement do
+ Book.find_by(name: "my other book")
+ end
+
+ refute_equal book, other_book
+ end
end
end