rdo-postgres 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ describe RDO::Postgres::Array::Bytea do
4
+ it "is a kind of ::Array" do
5
+ RDO::Postgres::Array::Bytea.new.should be_a_kind_of(::Array)
6
+ end
7
+
8
+ describe "#to_s" do
9
+ context "with an empty array" do
10
+ let(:arr) { RDO::Postgres::Array::Bytea[] }
11
+
12
+ it "returns {}" do
13
+ arr.to_s.should == '{}'
14
+ end
15
+ end
16
+
17
+ context "with an array of Strings" do
18
+ let(:arr) { RDO::Postgres::Array::Bytea["\x00\x11", "\x22\x33", "\x44\x55"] }
19
+
20
+ it "escapes the binary data" do
21
+ if arr.to_s =~ /\\x/
22
+ arr.to_s.should == '{"\\x00\\x11","\\x22\\x33","\\x44\\x55"}'
23
+ else
24
+ arr.to_s.should == '{"\\\\000\\\\021","\\"3","DU"}'
25
+ end
26
+ end
27
+
28
+ context "containing nil" do
29
+ let(:arr) { RDO::Postgres::Array::Bytea["\x00\x11", nil] }
30
+
31
+ it "uses NULL" do
32
+ if arr.to_s =~ /\\x/
33
+ arr.to_s.should == '{"\\x00\\x11",NULL}'
34
+ else
35
+ arr.to_s.should == '{"\\\\000\\\\021",NULL}'
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#to_a" do
43
+ let(:arr) { RDO::Postgres::Array::Bytea["\x00\x11", "\x22\x33", "\x44\x55"] }
44
+
45
+ it "returns a Ruby ::Array" do
46
+ arr.to_a.should == ["\x00\x11", "\x22\x33", "\x44\x55"]
47
+ end
48
+ end
49
+
50
+ describe ".parse" do
51
+ let(:str) { '{}' }
52
+ let(:arr) { RDO::Postgres::Array::Bytea.parse(str) }
53
+
54
+ it "returns a RDO::Postgres::Array::Bytea" do
55
+ arr.should be_a_kind_of(RDO::Postgres::Array::Bytea)
56
+ end
57
+
58
+ context "with an empty array string" do
59
+ let(:str) { '{}' }
60
+
61
+ it "returns an empty Array" do
62
+ arr.should be_empty
63
+ end
64
+ end
65
+
66
+ context "with an array of byteas" do
67
+ let(:str) { '{"\\\\x0011","\\\\x2233"}' }
68
+
69
+ it "returns an Array of Strings" do
70
+ arr.to_a.should == ["\x00\x11", "\x22\x33"]
71
+ end
72
+ end
73
+
74
+ context "with an array containing NULL" do
75
+ let(:str) { '{NULL,NULL,"\\\\x0011"}' }
76
+
77
+ it "uses nil as the value" do
78
+ arr.to_a.should == [nil, nil, "\x00\x11"]
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ describe RDO::Postgres::Array::Date do
4
+ it "is a kind of ::Array" do
5
+ RDO::Postgres::Array::Date.new.should be_a_kind_of(::Array)
6
+ end
7
+
8
+ describe "#to_s" do
9
+ context "with an empty array" do
10
+ let(:arr) { RDO::Postgres::Array::Date[] }
11
+
12
+ it "returns {}" do
13
+ arr.to_s.should == '{}'
14
+ end
15
+ end
16
+
17
+ context "with an array of Dates" do
18
+ let(:arr) { RDO::Postgres::Array::Date[Date.new(2012, 9, 22), Date.new(1983, 5, 3)] }
19
+
20
+ it "formats the dates in quotes" do
21
+ arr.to_s.should == '{"2012-09-22","1983-05-03"}'
22
+ end
23
+ end
24
+
25
+ context "with an array containing nil" do
26
+ let(:arr) { RDO::Postgres::Array::Date[nil, Date.new(1983, 5, 3)] }
27
+
28
+ it "uses NULL" do
29
+ arr.to_s.should == '{NULL,"1983-05-03"}'
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#to_a" do
35
+ let(:arr) { RDO::Postgres::Array::Date[Date.new(2012, 9, 22), Date.new(1983, 5, 3)] }
36
+
37
+ it "returns a core ruby Array" do
38
+ arr.to_a.class.should == ::Array
39
+ end
40
+ end
41
+
42
+ describe ".parse" do
43
+ let(:str) { '{}' }
44
+ let(:arr) { RDO::Postgres::Array::Date.parse(str) }
45
+
46
+ it "returns a RDO::Postgres::Array::Date" do
47
+ arr.should be_a_kind_of(RDO::Postgres::Array::Date)
48
+ end
49
+
50
+ context "with an empty array string" do
51
+ let(:str) { '{}' }
52
+
53
+ it "returns an empty Array" do
54
+ arr.should be_empty
55
+ end
56
+ end
57
+
58
+ context "with an array of dates" do
59
+ let(:str) { '{"2012-09-22","1983-05-03"}' }
60
+
61
+ it "returns an Array of Dates" do
62
+ arr.to_a.should == [Date.new(2012, 9, 22), Date.new(1983, 5, 3)]
63
+ end
64
+ end
65
+
66
+ context "with an array containing NULL" do
67
+ let(:str) { '{NULL,"1983-05-03"}' }
68
+
69
+ it "uses nil as the value" do
70
+ arr.to_a.should == [nil, Date.new(1983, 5, 3)]
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,98 @@
1
+ require "spec_helper"
2
+
3
+ describe RDO::Postgres::Array::Float do
4
+ it "is a kind of ::Array" do
5
+ RDO::Postgres::Array::Float.new.should be_a_kind_of(::Array)
6
+ end
7
+
8
+ describe "#to_s" do
9
+ context "with an empty array" do
10
+ let(:arr) { RDO::Postgres::Array::Float[] }
11
+
12
+ it "returns {}" do
13
+ arr.to_s.should == '{}'
14
+ end
15
+ end
16
+
17
+ context "with an array of Floats" do
18
+ let(:arr) { RDO::Postgres::Array::Float[1.2, 2.4, 3.6] }
19
+
20
+ it "comma separates the numbers" do
21
+ arr.to_s.should == '{1.2,2.4,3.6}'
22
+ end
23
+ end
24
+
25
+ context "with an array containing nil" do
26
+ let(:arr) { RDO::Postgres::Array::Float[nil, nil, 7.2] }
27
+
28
+ it "uses NULL" do
29
+ arr.to_s.should == '{NULL,NULL,7.2}'
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#to_a" do
35
+ let(:arr) { RDO::Postgres::Array::Float[1.2, 2.4, 3.6] }
36
+
37
+ it "returns a core ruby Array" do
38
+ arr.to_a.class.should == ::Array
39
+ end
40
+ end
41
+
42
+ describe ".parse" do
43
+ let(:str) { '{}' }
44
+ let(:arr) { RDO::Postgres::Array::Float.parse(str) }
45
+
46
+ it "returns a RDO::Postgres::Array::Float" do
47
+ arr.should be_a_kind_of(RDO::Postgres::Array::Float)
48
+ end
49
+
50
+ context "with an empty array string" do
51
+ let(:str) { '{}' }
52
+
53
+ it "returns an empty Array" do
54
+ arr.should be_empty
55
+ end
56
+ end
57
+
58
+ context "with an array of floats" do
59
+ let(:str) { '{1.2,2.4,3.6}' }
60
+
61
+ it "returns an Array of Floats" do
62
+ arr.to_a.should == [1.2, 2.4, 3.6]
63
+ end
64
+ end
65
+
66
+ context "with an array containing NULL" do
67
+ let(:str) { '{NULL,NULL,7.2}' }
68
+
69
+ it "uses nil as the value" do
70
+ arr.to_a.should == [nil, nil, 7.2]
71
+ end
72
+ end
73
+
74
+ context "with an array containing NaN" do
75
+ let(:str) { '{NaN,7.2}' }
76
+
77
+ it "uses Float::NAN as the value" do
78
+ arr.to_a.should == [Float::NAN, 7.2]
79
+ end
80
+ end
81
+
82
+ context "with an array containing Infinity" do
83
+ let(:str) { '{Infinity,7.2}' }
84
+
85
+ it "uses Float::INFINITY as the value" do
86
+ arr.to_a.should == [Float::INFINITY, 7.2]
87
+ end
88
+ end
89
+
90
+ context "with an array containing -Infinity" do
91
+ let(:str) { '{-Infinity,7.2}' }
92
+
93
+ it "uses -Float::INFINITY as the value" do
94
+ arr.to_a.should == [-Float::INFINITY, 7.2]
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ describe RDO::Postgres::Array::Integer do
4
+ it "is a kind of ::Array" do
5
+ RDO::Postgres::Array::Integer.new.should be_a_kind_of(::Array)
6
+ end
7
+
8
+ describe "#to_s" do
9
+ context "with an empty array" do
10
+ let(:arr) { RDO::Postgres::Array::Integer[] }
11
+
12
+ it "returns {}" do
13
+ arr.to_s.should == '{}'
14
+ end
15
+ end
16
+
17
+ context "with an array of Fixnums" do
18
+ let(:arr) { RDO::Postgres::Array::Integer[1, 2, 3] }
19
+
20
+ it "comma separates the numbers" do
21
+ arr.to_s.should == '{1,2,3}'
22
+ end
23
+ end
24
+
25
+ context "with an array containing nil" do
26
+ let(:arr) { RDO::Postgres::Array::Integer[nil, nil, 7] }
27
+
28
+ it "uses NULL" do
29
+ arr.to_s.should == '{NULL,NULL,7}'
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#to_a" do
35
+ let(:arr) { RDO::Postgres::Array::Integer[1, 2, 3] }
36
+
37
+ it "returns a core ruby Array" do
38
+ arr.to_a.class.should == ::Array
39
+ end
40
+ end
41
+
42
+ describe ".parse" do
43
+ let(:str) { '{}' }
44
+ let(:arr) { RDO::Postgres::Array::Integer.parse(str) }
45
+
46
+ it "returns a RDO::Postgres::Array::Integer" do
47
+ arr.should be_a_kind_of(RDO::Postgres::Array::Integer)
48
+ end
49
+
50
+ context "with an empty array string" do
51
+ let(:str) { '{}' }
52
+
53
+ it "returns an empty Array" do
54
+ arr.should be_empty
55
+ end
56
+ end
57
+
58
+ context "with an array of integers" do
59
+ let(:str) { '{1,2,3}' }
60
+
61
+ it "returns an Array of Fixnums" do
62
+ arr.to_a.should == [1, 2, 3]
63
+ end
64
+ end
65
+
66
+ context "with an array containing NULL" do
67
+ let(:str) { '{NULL,NULL,7}' }
68
+
69
+ it "uses nil as the value" do
70
+ arr.to_a.should == [nil, nil, 7]
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+
3
+ describe RDO::Postgres::Array::Numeric do
4
+ it "is a kind of ::Array" do
5
+ RDO::Postgres::Array::Numeric.new.should be_a_kind_of(::Array)
6
+ end
7
+
8
+ describe "#to_s" do
9
+ context "with an empty array" do
10
+ let(:arr) { RDO::Postgres::Array::Numeric[] }
11
+
12
+ it "returns {}" do
13
+ arr.to_s.should == '{}'
14
+ end
15
+ end
16
+
17
+ context "with an array of BigDecimals" do
18
+ let(:arr) { RDO::Postgres::Array::Numeric[BigDecimal("1.2"), BigDecimal("2.4")] }
19
+
20
+ it "comma separates the numbers" do
21
+ arr.to_s.should == "{#{BigDecimal('1.2').to_s},#{BigDecimal('2.4').to_s}}"
22
+ end
23
+ end
24
+
25
+ context "with an array containing nil" do
26
+ let(:arr) { RDO::Postgres::Array::Numeric[nil, BigDecimal("7.2")] }
27
+
28
+ it "uses NULL" do
29
+ arr.to_s.should == "{NULL,#{BigDecimal('7.2').to_s}}"
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#to_a" do
35
+ let(:arr) { RDO::Postgres::Array::Numeric[BigDecimal("1.2"), BigDecimal("2.4")] }
36
+
37
+ it "returns a core ruby Array" do
38
+ arr.to_a.class.should == ::Array
39
+ end
40
+ end
41
+
42
+ describe ".parse" do
43
+ let(:str) { '{}' }
44
+ let(:arr) { RDO::Postgres::Array::Numeric.parse(str) }
45
+
46
+ it "returns a RDO::Postgres::Array::Numeric" do
47
+ arr.should be_a_kind_of(RDO::Postgres::Array::Numeric)
48
+ end
49
+
50
+ context "with an empty array string" do
51
+ let(:str) { '{}' }
52
+
53
+ it "returns an empty Array" do
54
+ arr.should be_empty
55
+ end
56
+ end
57
+
58
+ context "with an array of decimals" do
59
+ let(:str) { '{1.2,2.4}' }
60
+
61
+ it "returns an Array of BigDecimals" do
62
+ arr.to_a.should == [BigDecimal("1.2"), BigDecimal("2.4")]
63
+ end
64
+ end
65
+
66
+ context "with an array containing NULL" do
67
+ let(:str) { '{NULL,7.2}' }
68
+
69
+ it "uses nil as the value" do
70
+ arr.to_a.should == [nil, BigDecimal("7.2")]
71
+ end
72
+ end
73
+
74
+ context "with an array containing NaN" do
75
+ let(:str) { '{NaN,7.2}' }
76
+
77
+ it "uses BigDecimal('NaN') as the value" do
78
+ arr.to_a[0].should be_nan
79
+ arr.to_a[1].should == BigDecimal("7.2")
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ describe RDO::Postgres::Array::Timestamp do
4
+ it "is a kind of ::Array" do
5
+ RDO::Postgres::Array::Timestamp.new.should be_a_kind_of(::Array)
6
+ end
7
+
8
+ describe "#to_s" do
9
+ context "with an empty array" do
10
+ let(:arr) { RDO::Postgres::Array::Timestamp[] }
11
+
12
+ it "returns {}" do
13
+ arr.to_s.should == '{}'
14
+ end
15
+ end
16
+
17
+ context "with an array of Times" do
18
+ let(:arr) { RDO::Postgres::Array::Timestamp[
19
+ Time.new(2012, 9, 22, 5, 43, 2),
20
+ Time.new(1983, 5, 3, 15, 0, 1)
21
+ ] }
22
+
23
+ it "formats the times in quotes" do
24
+ arr.to_s.should == %Q[{"#{Time.new(2012, 9, 22, 5, 43, 2)}","#{Time.new(1983, 5, 3, 15, 0, 1)}"}]
25
+ end
26
+ end
27
+
28
+ context "with an array containing nil" do
29
+ let(:arr) { RDO::Postgres::Array::Timestamp[nil, Time.new(1983, 5, 3, 0, 0, 1)] }
30
+
31
+ it "uses NULL" do
32
+ arr.to_s.should == %Q[{NULL,"#{Time.new(1983, 5, 3, 0, 0, 1)}"}]
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#to_a" do
38
+ let(:arr) { RDO::Postgres::Array::Timestamp[Time.new(2012, 9, 22, 0, 0, 0)] }
39
+
40
+ it "returns a core ruby Array" do
41
+ arr.to_a.class.should == ::Array
42
+ end
43
+ end
44
+
45
+ describe ".parse" do
46
+ let(:str) { '{}' }
47
+ let(:arr) { RDO::Postgres::Array::Timestamp.parse(str) }
48
+
49
+ it "returns a RDO::Postgres::Array::Timestamp" do
50
+ arr.should be_a_kind_of(RDO::Postgres::Array::Timestamp)
51
+ end
52
+
53
+ context "with an empty array string" do
54
+ let(:str) { '{}' }
55
+
56
+ it "returns an empty Array" do
57
+ arr.should be_empty
58
+ end
59
+ end
60
+
61
+ context "with an array of timestamps" do
62
+ let(:str) { '{"2012-09-22 05:34:01","1983-05-03 13:59:09"}' }
63
+
64
+ it "returns an Array of DateTimes" do
65
+ arr.to_a.should == [
66
+ DateTime.new(2012, 9, 22, 5, 34, 1, DateTime.now.zone),
67
+ DateTime.new(1983, 5, 3, 13, 59, 9, DateTime.now.zone)
68
+ ]
69
+ end
70
+ end
71
+
72
+ context "with an array containing NULL" do
73
+ let(:str) { '{NULL,"1983-05-03 00:04:05"}' }
74
+
75
+ it "uses nil as the value" do
76
+ arr.to_a.should == [nil, DateTime.new(1983, 5, 3, 0, 4, 5, DateTime.now.zone)]
77
+ end
78
+ end
79
+ end
80
+ end