make Connection#prepared_statements? readonly

This commit is contained in:
Brian J. Cardiff 2016-12-04 15:19:15 -03:00
parent d55b088216
commit 4721ecbf6b
4 changed files with 8 additions and 14 deletions

View File

@ -111,21 +111,17 @@ describe DB::Database do
end
end
it "is copied to connections and can be changed (false)" do
it "is copied to connections (false)" do
with_dummy "dummy://localhost:1027?prepared_statements=false&initial_pool_size=1" do |db|
connection = DummyDriver::DummyConnection.connections.first
connection.prepared_statements?.should be_false
connection.prepared_statements = true
connection.prepared_statements?.should be_true
end
end
it "is copied to connections and can be changed (true)" do
it "is copied to connections (true)" do
with_dummy "dummy://localhost:1027?prepared_statements=true&initial_pool_size=1" do |db|
connection = DummyDriver::DummyConnection.connections.first
connection.prepared_statements?.should be_true
connection.prepared_statements = false
connection.prepared_statements?.should be_false
end
end

View File

@ -212,8 +212,8 @@ def with_dummy(uri : String = "dummy://host?checkout_timeout=0.5")
end
end
def with_dummy_connection
with_dummy do |db|
def with_dummy_connection(options = "")
with_dummy("dummy://host?checkout_timeout=0.5&#{options}") do |db|
db.using_connection do |cnn|
yield cnn.as(DummyDriver::DummyConnection)
end

View File

@ -10,7 +10,7 @@ describe DB::Statement do
end
it "should build unprepared statements" do
with_dummy_connection do |cnn|
with_dummy_connection("prepared_statements=false") do |cnn|
prepared = cnn.unprepared("the query")
prepared.should be_a(DB::Statement)
prepared.as(DummyDriver::DummyStatement).prepared?.should be_false
@ -19,16 +19,14 @@ describe DB::Statement do
describe "prepared_statements flag" do
it "should build prepared statements if true" do
with_dummy_connection do |cnn|
cnn.prepared_statements = true
with_dummy_connection("prepared_statements=true") do |cnn|
stmt = cnn.query("the query").statement
stmt.as(DummyDriver::DummyStatement).prepared?.should be_true
end
end
it "should build unprepared statements if false" do
with_dummy_connection do |cnn|
cnn.prepared_statements = false
with_dummy_connection("prepared_statements=false") do |cnn|
stmt = cnn.query("the query").statement
stmt.as(DummyDriver::DummyStatement).prepared?.should be_false
end

View File

@ -25,7 +25,7 @@ module DB
# :nodoc:
getter database
@statements_cache = StringKeyCache(Statement).new
property? prepared_statements : Bool
getter? prepared_statements : Bool
def initialize(@database : Database)
@prepared_statements = @database.prepared_statements?