Skip to content

Commit

Permalink
Add some specs for increased coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Feb 26, 2013
1 parent af2eb1d commit 315fbe9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/core/connection_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@
t.join
end

specify "should wait until a connection is available if all are checked out" do
pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:max_connections=>1, :pool_timeout=>0.1, :pool_sleep_time=>0))
q, q1 = Queue.new, Queue.new
t = Thread.new do
pool.hold do |c|
q1.push nil
3.times{Thread.pass}
q.pop
end
end
q1.pop
proc{pool.hold{}}.should raise_error(Sequel::PoolTimeout)
q.push nil
t.join
end

specify "should not have all_connections yield all available connections" do
pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:max_connections=>2, :pool_timeout=>0))
q, q1 = Queue.new, Queue.new
Expand Down
27 changes: 27 additions & 0 deletions spec/core/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2308,3 +2308,30 @@ class << Sequel
proc{@db.extension(:foo2)}.should raise_error(Sequel::Error)
end
end

describe "Database specific exception classes" do
before do
@db = Sequel.mock
class << @db
attr_accessor :sql_state

def database_exception_sqlstate(exception, opts={})
@sql_state
end
end
end

specify "should use appropriate exception classes for given SQL states" do
@db.fetch = ArgumentError
@db.sql_state = '23502'
proc{@db.get(1)}.should raise_error(Sequel::NotNullConstraintViolation)
@db.sql_state = '23503'
proc{@db.get(1)}.should raise_error(Sequel::ForeignKeyConstraintViolation)
@db.sql_state = '23505'
proc{@db.get(1)}.should raise_error(Sequel::UniqueConstraintViolation)
@db.sql_state = '23513'
proc{@db.get(1)}.should raise_error(Sequel::CheckConstraintViolation)
@db.sql_state = '40001'
proc{@db.get(1)}.should raise_error(Sequel::SerializationFailure)
end
end
26 changes: 26 additions & 0 deletions spec/core/expression_filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1025,3 +1025,29 @@ def (Sequel::JSON).parse(json, opts={})
Sequel.parse_json('[]').should == ['[]', {:create_additions=>false}]
end
end

describe "Sequel::LiteralString" do
before do
@s = Sequel::LiteralString.new("? = ?")
end

specify "should have lit return self if no arguments" do
@s.lit.should equal(@s)
end

specify "should have lit return self if return a placeholder literal string if arguments" do
@s.lit(1, 2).should be_a_kind_of(Sequel::SQL::PlaceholderLiteralString)
Sequel.mock.literal(@s.lit(1, :a)).should == '1 = a'
end

specify "should have to_sequel_blob convert to blob" do
@s.to_sequel_blob.should == @s
@s.to_sequel_blob.should be_a_kind_of(Sequel::SQL::Blob)
end
end

describe "Sequel core extensions" do
specify "should have Sequel.core_extensions? be false by default" do
Sequel.core_extensions?.should be_false
end
end
4 changes: 4 additions & 0 deletions spec/core/mock_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ class Sequel::Database; @@identifier_output_method=nil; end
Sequel.mock(:host=>'postgres').primary_key(:t).should == :id
end

specify "should stub out the bound_variable_arg method for postgres" do
Sequel.mock(:host=>'postgres').bound_variable_arg(:t, nil).should == :t
end

specify "should handle creating tables on oracle" do
proc{Sequel.mock(:host=>'oracle').create_table(:a){String :b}}.should_not raise_error
end
Expand Down

0 comments on commit 315fbe9

Please sign in to comment.