~ubuntu-branches/ubuntu/vivid/ruby-sequel/vivid

« back to all changes in this revision

Viewing changes to spec/extensions/pg_row_ops_spec.rb

  • Committer: Package Import Robot
  • Author(s): Dmitry Borodaenko, Dmitry Borodaenko, Cédric Boutillier
  • Date: 2013-08-10 18:38:17 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20130810183817-iqanz804j32i5myi
Tags: 4.1.1-1
[ Dmitry Borodaenko ]
* New upstream release.
* Standards-Version upgraded to 3.9.4 (no changes).
* Added Build-Depend on ruby-sqlite3.

[ Cédric Boutillier ]
* debian/control: remove obsolete DM-Upload-Allowed flag.
* use canonical URI in Vcs-* fields.
* debian/copyright: use DEP5 copyright-format/1.0 official URL for Format
  field.
* Update debian/watch. Thanks Bart Martens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
 
2
 
 
3
Sequel.extension :pg_array, :pg_array_ops, :pg_row, :pg_row_ops
 
4
 
 
5
describe "Sequel::Postgres::PGRowOp" do
 
6
  before do
 
7
    @db = Sequel.connect('mock://postgres', :quote_identifiers=>false)
 
8
    @a = Sequel.pg_row_op(:a)
 
9
  end
 
10
 
 
11
  it "#[] should access members of the composite type" do
 
12
    @db.literal(@a[:b]).should == "(a).b"
 
13
  end
 
14
 
 
15
  it "#[] should be chainable" do
 
16
    @db.literal(@a[:b][:c]).should == "((a).b).c"
 
17
  end
 
18
 
 
19
  it "#[] should support array access if not given an identifier" do
 
20
    @db.literal(@a[:b][1]).should == "(a).b[1]"
 
21
  end
 
22
 
 
23
  it "#[] should be chainable with array access" do
 
24
    @db.literal(@a[1][:b]).should == "(a[1]).b"
 
25
  end
 
26
 
 
27
  it "#splat should return a splatted argument inside parentheses" do
 
28
    @db.literal(@a.splat).should == "(a.*)"
 
29
  end
 
30
 
 
31
  it "#splat(type) should return a splatted argument cast to given type" do
 
32
    @db.literal(@a.splat(:b)).should == "(a.*)::b"
 
33
  end
 
34
 
 
35
  it "#splat should not work on an already accessed composite type" do
 
36
    proc{@a[:a].splat(:b)}.should raise_error(Sequel::Error)
 
37
  end
 
38
 
 
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).*"
 
42
  end
 
43
 
 
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)"
 
47
  end
 
48
 
 
49
  it "#pg_row should be callable on literal strings" do
 
50
    @db.literal(Sequel.lit('a').pg_row[:b]).should == "(a).b"
 
51
  end
 
52
 
 
53
  it "#pg_row should be callable on Sequel expressions" do
 
54
    @db.literal(Sequel.function(:a).pg_row[:b]).should == "(a()).b"
 
55
  end
 
56
 
 
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"
 
59
  end
 
60
end