aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/statement_cache_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-01-15 14:24:11 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-01-15 14:24:11 -0800
commitf3e379f0c97149bb29a63dc9db8a2836addcd957 (patch)
tree70dbb789f50942d722f98ce98df5db89a7437309 /activerecord/test/cases/statement_cache_test.rb
parent7fff71b357150519002e1f92dbcb11fc75f56a9b (diff)
downloadrails-f3e379f0c97149bb29a63dc9db8a2836addcd957.tar.gz
rails-f3e379f0c97149bb29a63dc9db8a2836addcd957.tar.bz2
rails-f3e379f0c97149bb29a63dc9db8a2836addcd957.zip
use a params hash so we know what bind parameters are used
Diffstat (limited to 'activerecord/test/cases/statement_cache_test.rb')
-rw-r--r--activerecord/test/cases/statement_cache_test.rb31
1 files changed, 16 insertions, 15 deletions
diff --git a/activerecord/test/cases/statement_cache_test.rb b/activerecord/test/cases/statement_cache_test.rb
index 88ac2cf2eb..efd2d94b57 100644
--- a/activerecord/test/cases/statement_cache_test.rb
+++ b/activerecord/test/cases/statement_cache_test.rb
@@ -7,6 +7,7 @@ require 'models/electron'
module ActiveRecord
class StatementCacheTest < ActiveRecord::TestCase
def setup
+ skip if current_adapter?(:Mysql2Adapter)
@connection = ActiveRecord::Base.connection
end
@@ -15,13 +16,13 @@ module ActiveRecord
Book.create(name: "my book")
Book.create(name: "my other book")
- cache = StatementCache.new do |name|
- Book.where(:name => name)
+ cache = StatementCache.new do |params|
+ Book.where(:name => params[:name])
end
- b = cache.execute "my book"
+ b = cache.execute name: "my book"
assert_equal "my book", b[0].name
- b = cache.execute "my other book"
+ b = cache.execute name: "my other book"
assert_equal "my other book", b[0].name
end
@@ -30,13 +31,13 @@ module ActiveRecord
b1 = Book.create(name: "my book")
b2 = Book.create(name: "my other book")
- cache = StatementCache.new do |id|
- Book.where(id: id)
+ cache = StatementCache.new do |params|
+ Book.where(id: params[:id])
end
- b = cache.execute b1.id
+ b = cache.execute id: b1.id
assert_equal b1.name, b[0].name
- b = cache.execute b2.id
+ b = cache.execute id: b2.id
assert_equal b2.name, b[0].name
end
@@ -53,18 +54,18 @@ module ActiveRecord
#End
def test_statement_cache_with_simple_statement
- cache = ActiveRecord::StatementCache.new do
+ cache = ActiveRecord::StatementCache.new do |params|
Book.where(name: "my book").where("author_id > 3")
end
Book.create(name: "my book", author_id: 4)
- books = cache.execute
+ books = cache.execute({})
assert_equal "my book", books[0].name
end
def test_statement_cache_with_complex_statement
- cache = ActiveRecord::StatementCache.new do
+ cache = ActiveRecord::StatementCache.new do |params|
Liquid.joins(:molecules => :electrons).where('molecules.name' => 'dioxane', 'electrons.name' => 'lepton')
end
@@ -72,12 +73,12 @@ module ActiveRecord
molecule = salty.molecules.create(name: 'dioxane')
molecule.electrons.create(name: 'lepton')
- liquids = cache.execute
+ liquids = cache.execute({})
assert_equal "salty", liquids[0].name
end
def test_statement_cache_values_differ
- cache = ActiveRecord::StatementCache.new do
+ cache = ActiveRecord::StatementCache.new do |params|
Book.where(name: "my book")
end
@@ -85,13 +86,13 @@ module ActiveRecord
Book.create(name: "my book")
end
- first_books = cache.execute
+ first_books = cache.execute({})
3.times do
Book.create(name: "my book")
end
- additional_books = cache.execute
+ additional_books = cache.execute({})
assert first_books != additional_books
end
end