Skip to content

Commit

Permalink
Test that statement cache is cleared when limit is reached.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeigarts committed Sep 16, 2011
1 parent 2c9b36f commit cf746de
Showing 1 changed file with 18 additions and 1 deletion.
Expand Up @@ -668,8 +668,9 @@ class ::TestComment < ActiveRecord::Base


end if ENV['RAILS_GEM_VERSION'] >= '3.1' end if ENV['RAILS_GEM_VERSION'] >= '3.1'


describe "with statements pool" do describe "with statement pool" do
before(:all) do before(:all) do
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS.merge(:statement_limit => 3))
@conn = ActiveRecord::Base.connection @conn = ActiveRecord::Base.connection
schema_define do schema_define do
drop_table :test_posts rescue nil drop_table :test_posts rescue nil
Expand All @@ -680,6 +681,10 @@ class ::TestPost < ActiveRecord::Base
@statements = @conn.instance_variable_get(:@statements) @statements = @conn.instance_variable_get(:@statements)
end end


before(:each) do
@conn.clear_cache!
end

after(:all) do after(:all) do
schema_define do schema_define do
drop_table :test_posts drop_table :test_posts
Expand All @@ -688,6 +693,18 @@ class ::TestPost < ActiveRecord::Base
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!") ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
end end


it "should clear older cursors when statement limit is reached" do
pk = TestPost.columns.find { |c| c.primary }
sub = @conn.substitute_at(pk, 0)
binds = [[pk, 1]]

lambda {
4.times do |i|
@conn.exec_query("SELECT * FROM test_posts WHERE #{i}=#{i} AND id = #{sub}", "SQL", binds)
end
}.should change(@statements, :length).by(+3)
end

it "should cache UPDATE statements with bind variables" do it "should cache UPDATE statements with bind variables" do
lambda { lambda {
pk = TestPost.columns.find { |c| c.primary } pk = TestPost.columns.find { |c| c.primary }
Expand Down

0 comments on commit cf746de

Please sign in to comment.