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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
|
require_relative "spec_helper"
describe "pg_row extension" do
before do
@db = Sequel.connect('mock://postgres')
@db.extend_datasets{def quote_identifiers?; false end}
@db.extension(:pg_array, :pg_row)
@m = Sequel::Postgres::PGRow
@db.sqls
end
it "should parse record objects as arrays" do
a = @db.conversion_procs[2249].call("(a,b,c)")
a.class.must_equal(@m::ArrayRow)
a.to_a.must_be_kind_of(Array)
a[0].must_equal 'a'
a.must_equal %w'a b c'
a.db_type.must_be_nil
@db.literal(a).must_equal "ROW('a', 'b', 'c')"
end
it "should parse arrays of record objects as arrays of arrays" do
as = @db.conversion_procs[2287].call('{"(a,b,c)","(d,e,f)"}')
as.must_equal [%w'a b c', %w'd e f']
as.each do |a|
a.class.must_equal(@m::ArrayRow)
a.to_a.must_be_kind_of(Array)
a.db_type.must_be_nil
end
@db.literal(as).must_equal "ARRAY[ROW('a', 'b', 'c'),ROW('d', 'e', 'f')]::record[]"
end
it "should not parse arrays of record objects as arrays of arrays if pg_array extension not loaded" do
@db = Sequel.connect('mock://postgres')
@db.extend_datasets{def quote_identifiers?; false end}
@db.extension(:pg_row, :pg_array)
@db.conversion_procs[2287].must_be_nil
a = @db.conversion_procs[2249].call("(a,b,c)")
a.class.must_equal(@m::ArrayRow)
a.to_a.must_be_kind_of(Array)
a[0].must_equal 'a'
a.must_equal %w'a b c'
a.db_type.must_be_nil
@db.literal(a).must_equal "ROW('a', 'b', 'c')"
end
it "should be able to register custom parsing of row types as array-like objects" do
klass = @m::ArrayRow.subclass(:foo)
parser = @m::Parser.new(:converter=>klass)
a = parser.call("(a,b,c)")
a.class.must_equal(klass)
a.to_a.must_be_kind_of(Array)
a[0].must_equal 'a'
a.must_equal %w'a b c'
a.db_type.must_equal :foo
@db.literal(a).must_equal "ROW('a', 'b', 'c')::foo"
end
it "should be able to register custom parsing of row types as hash-like objects" do
klass = @m::HashRow.subclass(:foo, [:a, :b, :c])
parser = @m::Parser.new(:converter=>klass, :columns=>[:a, :b, :c])
a = parser.call("(a,b,c)")
a.class.must_equal(klass)
a.to_hash.must_be_kind_of(Hash)
a[:a].must_equal 'a'
a.must_equal(:a=>'a', :b=>'b', :c=>'c')
a.db_type.must_equal :foo
a.columns.must_equal [:a, :b, :c]
@db.literal(a).must_equal "ROW('a', 'b', 'c')::foo"
end
it "should be able to register custom parsing of row types as hash-like objects without a database type" do
klass = @m::HashRow.subclass(nil, [:a, :b, :c])
parser = @m::Parser.new(:converter=>klass, :columns=>[:a, :b, :c])
a = parser.call("(a,b,c)")
a.class.must_equal(klass)
a.to_hash.must_be_kind_of(Hash)
a[:a].must_equal 'a'
a.must_equal(:a=>'a', :b=>'b', :c=>'c')
a.db_type.must_be_nil
a.columns.must_equal [:a, :b, :c]
@db.literal(a).must_equal "ROW('a', 'b', 'c')"
end
it "should raise an error if attempting to literalize a HashRow without column information" do
h = @m::HashRow.call(:a=>'a', :b=>'b', :c=>'c')
proc{@db.literal(h)}.must_raise(Sequel::Error)
end
it "should be able to manually override db_type per ArrayRow instance" do
a = @m::ArrayRow.call(%w'a b c')
a.db_type = :foo
@db.literal(a).must_equal "ROW('a', 'b', 'c')::foo"
end
it "should be able to manually override db_type and columns per HashRow instance" do
h = @m::HashRow.call(:a=>'a', :c=>'c', :b=>'b')
h.db_type = :foo
h.columns = [:a, :b, :c]
@db.literal(h).must_equal "ROW('a', 'b', 'c')::foo"
end
it "should correctly split an empty row" do
@m::Splitter.new("()").parse.must_equal [nil]
end
it "should correctly split a row with a single value" do
@m::Splitter.new("(1)").parse.must_equal %w'1'
end
it "should correctly split a row with multiple values" do
@m::Splitter.new("(1,2)").parse.must_equal %w'1 2'
end
it "should correctly NULL values when splitting" do
@m::Splitter.new("(1,)").parse.must_equal ['1', nil]
end
it "should correctly empty string values when splitting" do
@m::Splitter.new('(1,"")').parse.must_equal ['1', '']
end
it "should handle quoted values when splitting" do
@m::Splitter.new('("1","2")').parse.must_equal %w'1 2'
end
it "should handle escaped backslashes in quoted values when splitting" do
@m::Splitter.new('("\\\\1","2\\\\")').parse.must_equal ['\\1', '2\\']
end
it "should handle doubled quotes in quoted values when splitting" do
@m::Splitter.new('("""1","2""")').parse.must_equal ['"1', '2"']
end
it "should correctly convert types when parsing into an array" do
@m::Parser.new(:column_converters=>[proc{|s| s*2}, proc{|s| s*3}, proc{|s| s*4}]).call("(a,b,c)").must_equal %w'aa bbb cccc'
end
it "should correctly convert types into hashes if columns are known" do
@m::Parser.new(:columns=>[:a, :b, :c]).call("(a,b,c)").must_equal(:a=>'a', :b=>'b', :c=>'c')
end
it "should correctly handle type conversion when converting into hashes" do
@m::Parser.new(:column_converters=>[proc{|s| s*2}, proc{|s| s*3}, proc{|s| s*4}], :columns=>[:a, :b, :c]).call("(a,b,c)").must_equal(:a=>'aa', :b=>'bbb', :c=>'cccc')
end
it "should correctly wrap arrays when converting" do
@m::Parser.new(:converter=>proc{|s| [:foo, s]}).call("(a,b,c)").must_equal [:foo, %w'a b c']
end
it "should correctly wrap hashes when converting" do
@m::Parser.new(:converter=>proc{|s| [:foo, s]}, :columns=>[:a, :b, :c]).call("(a,b,c)").must_equal [:foo, {:a=>'a', :b=>'b', :c=>'c'}]
end
it "should have parser store reflection information" do
p = @m::Parser.new(:oid=>1, :column_oids=>[2], :columns=>[:a], :converter=>Array, :typecaster=>Hash, :column_converters=>[Array])
p.oid.must_equal 1
p.column_oids.must_equal [2]
p.columns.must_equal [:a]
p.converter.must_equal Array
p.typecaster.must_equal Hash
p.column_converters.must_equal [Array]
end
it "should handle ArrayRows and HashRows in bound variables" do
@db.bound_variable_arg(1, nil).must_equal 1
@db.bound_variable_arg(@m::ArrayRow.call(["1", "abc\\'\","]), nil).must_equal '("1","abc\\\\\'\\",")'
@db.bound_variable_arg(@m::HashRow.subclass(nil, [:a, :b]).call(:a=>"1", :b=>"abc\\'\","), nil).must_equal '("1","abc\\\\\'\\",")'
end
it "should handle ArrayRows and HashRows in arrays in bound variables" do
@db.bound_variable_arg(1, nil).must_equal 1
@db.bound_variable_arg([@m::ArrayRow.call(["1", "abc\\'\","])], nil).must_equal '{"(\\"1\\",\\"abc\\\\\\\\\'\\\\\\",\\")"}'
@db.bound_variable_arg([@m::HashRow.subclass(nil, [:a, :b]).call(:a=>"1", :b=>"abc\\'\",")], nil).must_equal '{"(\\"1\\",\\"abc\\\\\\\\\'\\\\\\",\\")"}'
end
it "should handle nils in bound variables" do
@db.bound_variable_arg(@m::ArrayRow.call([nil, nil]), nil).must_equal '(,)'
@db.bound_variable_arg(@m::HashRow.subclass(nil, [:a, :b]).call(:a=>nil, :b=>nil), nil).must_equal '(,)'
@db.bound_variable_arg([@m::ArrayRow.call([nil, nil])], nil).must_equal '{"(,)"}'
@db.bound_variable_arg([@m::HashRow.subclass(nil, [:a, :b]).call(:a=>nil, :b=>nil)], nil).must_equal '{"(,)"}'
end
it "should allow registering row type parsers by introspecting system tables" do
@db.conversion_procs[4] = p4 = proc{|s| s.to_i}
@db.conversion_procs[5] = p5 = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo)
@db.sqls.must_equal ["SELECT pg_type.oid, typrelid, typarray FROM pg_type WHERE ((typtype = 'c') AND (typname = 'foo')) LIMIT 1",
"SELECT attname, (CASE pg_type.typbasetype WHEN 0 THEN atttypid ELSE pg_type.typbasetype END) AS atttypid FROM pg_attribute INNER JOIN pg_type ON (pg_type.oid = pg_attribute.atttypid) WHERE ((attrelid = 2) AND (attnum > 0) AND NOT attisdropped) ORDER BY attnum"]
p1 = @db.conversion_procs[1]
p1.columns.must_equal [:bar, :baz]
p1.column_oids.must_equal [4, 5]
p1.column_converters.must_equal [p4, p5]
p1.oid.must_equal 1
@db.send(:schema_column_type, 'foo').must_equal :pg_row_foo
@db.send(:schema_column_type, 'integer').must_equal :integer
c = p1.converter
c.superclass.must_equal @m::HashRow
c.columns.must_equal [:bar, :baz]
c.db_type.must_equal :foo
p1.typecaster.must_equal c
p1.call('(1,b)').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo, %w'1 b').class.must_be :<, @m::HashRow
@db.typecast_value(:pg_row_foo, %w'1 b').must_equal(:bar=>'1', :baz=>'b')
@db.typecast_value(:pg_row_foo, :bar=>'1', :baz=>'b').must_equal(:bar=>'1', :baz=>'b')
@db.literal(p1.call('(1,b)')).must_equal "ROW(1, 'bb')::foo"
end
it "should allow registering row type parsers for schema qualify types" do
@db.conversion_procs[4] = p4 = proc{|s| s.to_i}
@db.conversion_procs[5] = p5 = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(Sequel[:foo][:bar])
@db.sqls.must_equal ["SELECT pg_type.oid, typrelid, typarray FROM pg_type INNER JOIN pg_namespace ON ((pg_namespace.oid = pg_type.typnamespace) AND (pg_namespace.nspname = 'foo')) WHERE ((typtype = 'c') AND (typname = 'bar')) LIMIT 1",
"SELECT attname, (CASE pg_type.typbasetype WHEN 0 THEN atttypid ELSE pg_type.typbasetype END) AS atttypid FROM pg_attribute INNER JOIN pg_type ON (pg_type.oid = pg_attribute.atttypid) WHERE ((attrelid = 2) AND (attnum > 0) AND NOT attisdropped) ORDER BY attnum"]
p1 = @db.conversion_procs[1]
p1.columns.must_equal [:bar, :baz]
p1.column_oids.must_equal [4, 5]
p1.column_converters.must_equal [p4, p5]
p1.oid.must_equal 1
c = p1.converter
c.superclass.must_equal @m::HashRow
c.columns.must_equal [:bar, :baz]
c.db_type.must_equal Sequel[:foo][:bar]
p1.typecaster.must_equal c
p1.call('(1,b)').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo__bar, %w'1 b').must_equal(:bar=>'1', :baz=>'b')
@db.typecast_value(:pg_row_foo__bar, :bar=>'1', :baz=>'b').must_equal(:bar=>'1', :baz=>'b')
@db.literal(p1.call('(1,b)')).must_equal "ROW(1, 'bb')::foo.bar"
end
with_symbol_splitting "should allow registering row type parsers for schema qualify type symbols" do
@db.conversion_procs[4] = p4 = proc{|s| s.to_i}
@db.conversion_procs[5] = p5 = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo__bar)
@db.sqls.must_equal ["SELECT pg_type.oid, typrelid, typarray FROM pg_type INNER JOIN pg_namespace ON ((pg_namespace.oid = pg_type.typnamespace) AND (pg_namespace.nspname = 'foo')) WHERE ((typtype = 'c') AND (typname = 'bar')) LIMIT 1",
"SELECT attname, (CASE pg_type.typbasetype WHEN 0 THEN atttypid ELSE pg_type.typbasetype END) AS atttypid FROM pg_attribute INNER JOIN pg_type ON (pg_type.oid = pg_attribute.atttypid) WHERE ((attrelid = 2) AND (attnum > 0) AND NOT attisdropped) ORDER BY attnum"]
p1 = @db.conversion_procs[1]
p1.columns.must_equal [:bar, :baz]
p1.column_oids.must_equal [4, 5]
p1.column_converters.must_equal [p4, p5]
p1.oid.must_equal 1
c = p1.converter
c.superclass.must_equal @m::HashRow
c.columns.must_equal [:bar, :baz]
c.db_type.must_equal :foo__bar
p1.typecaster.must_equal c
p1.call('(1,b)').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo__bar, %w'1 b').must_equal(:bar=>'1', :baz=>'b')
@db.typecast_value(:pg_row_foo__bar, :bar=>'1', :baz=>'b').must_equal(:bar=>'1', :baz=>'b')
@db.literal(p1.call('(1,b)')).must_equal "ROW(1, 'bb')::foo.bar"
end
it "should not allow registering on a frozen database" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[], [{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
c = proc{|h| [h]}
@db.freeze
proc{@db.register_row_type(:foo, :converter=>c)}.must_raise RuntimeError, TypeError
end
it "should allow registering with a custom converter" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
c = proc{|h| [h]}
@db.register_row_type(:foo, :converter=>c)
o = @db.conversion_procs[1].call('(1,b)')
o.must_equal [{:bar=>1, :baz=>'bb'}]
o.first.must_be_kind_of(Hash)
end
it "should allow registering with a custom typecaster" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| {:bar=>(h[:bar]||0).to_i, :baz=>(h[:baz] || 'a')*2}})
@db.typecast_value(:pg_row_foo, %w'1 b').must_be_kind_of(Hash)
@db.typecast_value(:pg_row_foo, %w'1 b').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo, :bar=>'1', :baz=>'b').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo, 'bar'=>'1', 'baz'=>'b').must_equal(:bar=>0, :baz=>'aa')
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| {:bar=>(h[:bar] || h['bar'] || 0).to_i, :baz=>(h[:baz] || h['baz'] || 'a')*2}})
@db.typecast_value(:pg_row_foo, %w'1 b').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo, :bar=>'1', :baz=>'b').must_equal(:bar=>1, :baz=>'bb')
@db.typecast_value(:pg_row_foo, 'bar'=>'1', 'baz'=>'b').must_equal(:bar=>1, :baz=>'bb')
end
it "should handle nil values when converting columns" do
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}]]
called = false
@db.conversion_procs[4] = proc{|s| called = true; s}
@db.register_row_type(:foo)
@db.conversion_procs[1].call('()').must_equal(:bar=>nil)
called.must_equal false
end
it "should registering array type for row type if type has an array oid" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| {:bar=>(h[:bar]||0).to_i, :baz=>(h[:baz] || 'a')*2}})
p3 = @db.conversion_procs[3]
p3.call('{"(1,b)"}').must_equal [{:bar=>1, :baz=>'bb'}]
@db.literal(p3.call('{"(1,b)"}')).must_equal "ARRAY[ROW(1, 'bb')::foo]::foo[]"
@db.typecast_value(:foo_array, [{:bar=>'1', :baz=>'b'}]).must_equal [{:bar=>1, :baz=>'bb'}]
end
it "should not register array type for row type if type has an array oid and pg_array extension not loaded" do
@db = Sequel.connect('mock://postgres')
@db.extend_datasets{def quote_identifiers?; false end}
@db.extension(:pg_row)
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| {:bar=>(h[:bar]||0).to_i, :baz=>(h[:baz] || 'a')*2}})
@db.conversion_procs[1].call("(1,b)").must_equal(:bar=>1, :baz=>'bb')
@db.conversion_procs[3].must_be_nil
end
it "should allow creating unregisted row types via Database#row_type" do
@db.literal(@db.row_type(:foo, [1, 2])).must_equal 'ROW(1, 2)::foo'
end
it "should allow typecasting of registered row types via Database#row_type" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| @m::HashRow.subclass(:foo, [:bar, :baz]).new({:bar=>(h[:bar]||0).to_i, :baz=>(h[:baz] || 'a')*2})})
@db.literal(@db.row_type(:foo, ['1', 'b'])).must_equal "ROW(1, 'bb')::foo"
@db.literal(@db.row_type(:foo, {:bar=>'1', :baz=>'b'})).must_equal "ROW(1, 'bb')::foo"
end
it "should allow parsing when typecasting registered row types via Database#row_type" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| @m::HashRow.subclass(:foo, [:bar, :baz]).new(:bar=>(h[:bar]||0).to_i, :baz=>(h[:baz] || 'a')*2)})
@db.literal(@db.row_type(:foo, ['1', 'b'])).must_equal "ROW(1, 'bb')::foo"
end
it "should raise an error if attempt to use Database#row_type with an unregistered type and hash" do
proc{@db.literal(@db.row_type(:foo, {:bar=>'1', :baz=>'b'}))}.must_raise(Sequel::InvalidValue)
end
it "should raise an error if attempt to use Database#row_type with an unhandled type" do
proc{@db.literal(@db.row_type(:foo, 1))}.must_raise(Sequel::InvalidValue)
end
it "should return ArrayRow and HashRow values as-is" do
h = @m::HashRow.call(:a=>1)
a = @m::ArrayRow.call([1])
@db.row_type(:foo, h).object_id.must_equal(h.object_id)
@db.row_type(:foo, a).object_id.must_equal(a.object_id)
end
it "should have Sequel.pg_row return a plain ArrayRow" do
@db.literal(Sequel.pg_row([1, 2, 3])).must_equal 'ROW(1, 2, 3)'
end
it "should raise an error if attempting to typecast a hash for a parser without columns" do
proc{@m::Parser.new.typecast(:a=>1)}.must_raise(Sequel::Error)
end
it "should raise an error if attempting to typecast a unhandled value for a parser" do
proc{@m::Parser.new.typecast(1)}.must_raise(Sequel::Error)
end
it "should handle typecasting for a parser without a typecaster" do
@m::Parser.new.typecast([1]).must_equal [1]
end
it "should raise an error if no columns are returned when registering a custom row type" do
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}]]
proc{@db.register_row_type(:foo)}.must_raise(Sequel::Error)
end
it "should raise an error when registering a custom row type if the type is found found" do
@db.fetch = []
proc{@db.register_row_type(:foo)}.must_raise(Sequel::Error)
end
it "should return correct results for Database#schema_type_class" do
@db.conversion_procs[4] = proc{|s| s.to_i}
@db.conversion_procs[5] = proc{|s| s * 2}
@db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
@db.register_row_type(:foo, :typecaster=>proc{|h| {:bar=>(h[:bar]||0).to_i, :baz=>(h[:baz] || 'a')*2}})
@db.schema_type_class(:pg_row_foo).must_equal [Sequel::Postgres::PGRow::HashRow, Sequel::Postgres::PGRow::ArrayRow]
@db.schema_type_class(:integer).must_equal Integer
end
end
|