Skip to content

Instantly share code, notes, and snippets.

@apohllo
Created October 24, 2009 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apohllo/217329 to your computer and use it in GitHub Desktop.
Save apohllo/217329 to your computer and use it in GitHub Desktop.
# encoding: iso-8859-2
require 'rubygems'
require 'spec'
$LOAD_PATH.unshift('ext')
require 'pg'
describe PGconn do
before( :all ) do
puts "====== TESTING PGresult ======"
@test_directory = File.join(Dir.getwd, "tmp_test_#{rand}")
@test_pgdata = File.join(@test_directory, 'data')
if File.exists?(@test_directory) then
raise "test directory exists!"
end
@port = 54321
@conninfo = "host=localhost port=#{@port} dbname=test"
Dir.mkdir(@test_directory)
Dir.mkdir(@test_pgdata)
cmds = []
cmds << "initdb -D \"#{@test_pgdata}\""
cmds << "pg_ctl -o \"-p #{@port}\" -D \"#{@test_pgdata}\" start"
cmds << "createdb -p #{@port} test"
cmds.each_with_index do |cmd,index|
sleep(5) if index == 2
if not system(cmd) then
raise "Error executing cmd: #{cmd}: #{$?}"
end
end
puts "\n\n"
@conn = PGconn.connect(@conninfo)
@conn.exec("CREATE TABLE test(string_field VARCHAR(255));")
end
after( :all ) do
puts ""
@conn.finish
cmds = []
cmds << "pg_ctl -D \"#{@test_pgdata}\" stop"
cmds << "rm -rf \"#{@test_directory}\""
cmds.each do |cmd|
if not system(cmd) then
raise "Error executing cmd: #{cmd}: #{$?}"
end
end
puts "====== COMPLETED TESTING PGresult ======"
puts ""
end
it "should allow to store ISO-8859-2 string if the client encoding is set to ISO-8859-2" do
@conn.set_client_encoding("ISO-8859-2")
str = "Za\xBF\xF3\xB3\xE6 g\xEA\xB6l\xB1 ja\xBC\xF11"
res = @conn.exec("INSERT INTO test VALUES('#{str}')")
end
it "should allow to store ISO-8859-2 string if the client encoding is set to UTF-8" do
@conn.set_client_encoding("UTF-8")
str = "Za\xBF\xF3\xB3\xE6 g\xEA\xB6l\xB1 ja\xBC\xF12"
res = @conn.exec("INSERT INTO test VALUES('#{str}')")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment