File: error_sql_spec.rb

package info (click to toggle)
ruby-sequel 5.41.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,548 kB
  • sloc: ruby: 104,241; makefile: 3
file content (36 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require_relative "spec_helper"

describe "error_sql extension" do
  before do
    @db = Sequel.mock(:fetch=>proc{|sql| @db.synchronize{|c| @db.log_connection_yield(sql, c){raise StandardError}}}).extension(:error_sql)
  end

  it "should have Sequel::DatabaseError#sql give the SQL causing the error" do
    @db["SELECT"].all rescue (e = $!)
    e.sql.must_equal "SELECT"
  end

  it "should include connection information in SQL information if logging connection info" do
    @db.log_connection_info = true
    @db["SELECT"].all rescue (e = $!)
    e.sql.must_match(/\A\(conn: -?\d+\) SELECT\z/)
  end

  it "should include arguments in SQL information if given" do
    @db["SELECT"].with_fetch(proc{|sql| @db.synchronize{|c| @db.log_connection_yield(sql, c, [1, 2]){raise StandardError}}}).all rescue (e = $!)
    e.sql.must_equal "SELECT; [1, 2]"
  end

  it "should have Sequel::DatabaseError#sql give the SQL causing the error when using a logger" do
    l = Object.new
    def l.method_missing(*) end
    @db.loggers = [l]
    @db["SELECT"].all rescue (e = $!)
    e.sql.must_equal "SELECT"
  end

  it "should have Sequel::DatabaseError#sql be nil if there is no wrapped exception" do
    @db["SELECT"].with_fetch(proc{|sql| @db.log_connection_yield(sql, nil){raise Sequel::DatabaseError}}).all rescue (e = $!)
    e.sql.must_be_nil
  end
end