File: connection_spec.rb

package info (click to toggle)
ruby-dataobjects-postgres 0.10.17-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 344 kB
  • sloc: ansic: 1,509; ruby: 511; sh: 60; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 1,597 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# encoding: utf-8

require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
require 'data_objects/spec/shared/connection_spec'

describe DataObjects::Postgres::Connection do

  before :all do
    @driver = CONFIG.scheme
    @user   = CONFIG.user
    @password = CONFIG.pass
    @host   = CONFIG.host
    @port   = CONFIG.port
    @database = CONFIG.database
  end

  it_should_behave_like 'a Connection'
  it_should_behave_like 'a Connection with authentication support'
  it_should_behave_like 'a Connection allowing default database' unless JRUBY
  it_should_behave_like 'a Connection with JDBC URL support' if JRUBY

  describe 'byte array quoting' do

    before do
      @connection = DataObjects::Connection.new(CONFIG.uri)
    end

    after do
      @connection.close
    end

    # There are two possible byte array quotings available: hex or escape.
    # The default changed from escape to hex in version 9, so these specs
    # check for either.
    #
    # http://developer.postgresql.org/pgdocs/postgres/datatype-binary.html
    # http://developer.postgresql.org/pgdocs/postgres/release-9-0.html (E.3.2.3.)
    it 'should properly escape non-printable ASCII characters' do
      ["'\\001'", "'\\x01'"].should include @connection.quote_byte_array("\001")
    end

    it 'should properly escape bytes with the high bit set' do
      ["'\\210'", "'\\x88'"].should include @connection.quote_byte_array("\210")
    end

    it 'should not escape printable ASCII characters' do
      ["'a'", "'\\x61'"].should include @connection.quote_byte_array("a")
    end
  end
end