1
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
3
Sequel.extension :pg_array, :pg_array_ops, :pg_row, :pg_row_ops
5
describe "Sequel::Postgres::PGRowOp" do
7
@db = Sequel.connect('mock://postgres', :quote_identifiers=>false)
8
@a = Sequel.pg_row_op(:a)
11
it "#[] should access members of the composite type" do
12
@db.literal(@a[:b]).should == "(a).b"
15
it "#[] should be chainable" do
16
@db.literal(@a[:b][:c]).should == "((a).b).c"
19
it "#[] should support array access if not given an identifier" do
20
@db.literal(@a[:b][1]).should == "(a).b[1]"
23
it "#[] should be chainable with array access" do
24
@db.literal(@a[1][:b]).should == "(a[1]).b"
27
it "#splat should return a splatted argument inside parentheses" do
28
@db.literal(@a.splat).should == "(a.*)"
31
it "#splat(type) should return a splatted argument cast to given type" do
32
@db.literal(@a.splat(:b)).should == "(a.*)::b"
35
it "#splat should not work on an already accessed composite type" do
36
proc{@a[:a].splat(:b)}.should raise_error(Sequel::Error)
39
it "#* should reference all members of the composite type as separate columns if given no arguments" do
40
@db.literal(@a.*).should == "(a).*"
41
@db.literal(@a[:b].*).should == "((a).b).*"
44
it "#* should use a multiplication operation if any arguments are given" do
45
@db.literal(@a.*(1)).should == "(a * 1)"
46
@db.literal(@a[:b].*(1)).should == "((a).b * 1)"
49
it "#pg_row should be callable on literal strings" do
50
@db.literal(Sequel.lit('a').pg_row[:b]).should == "(a).b"
53
it "#pg_row should be callable on Sequel expressions" do
54
@db.literal(Sequel.function(:a).pg_row[:b]).should == "(a()).b"
57
it "Sequel.pg_row should work as well if the pg_row extension is loaded" do
58
@db.literal(Sequel.pg_row(Sequel.function(:a))[:b]).should == "(a()).b"