perpetuity-postgres 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/perpetuity/postgres/connection.rb +12 -0
- data/lib/perpetuity/postgres/version.rb +1 -1
- data/perpetuity-postgres.gemspec +1 -1
- data/spec/perpetuity/postgres/boolean_value_spec.rb +2 -2
- data/spec/perpetuity/postgres/connection_pool_spec.rb +3 -4
- data/spec/perpetuity/postgres/connection_spec.rb +6 -6
- data/spec/perpetuity/postgres/date_value_spec.rb +3 -3
- data/spec/perpetuity/postgres/expression_spec.rb +1 -1
- data/spec/perpetuity/postgres/index_collection_spec.rb +4 -4
- data/spec/perpetuity/postgres/index_spec.rb +13 -13
- data/spec/perpetuity/postgres/json_array_spec.rb +7 -7
- data/spec/perpetuity/postgres/json_hash_spec.rb +10 -10
- data/spec/perpetuity/postgres/json_string_value_spec.rb +3 -3
- data/spec/perpetuity/postgres/negated_query_spec.rb +8 -8
- data/spec/perpetuity/postgres/null_value_spec.rb +1 -1
- data/spec/perpetuity/postgres/numeric_value_spec.rb +1 -1
- data/spec/perpetuity/postgres/query_attribute_spec.rb +15 -15
- data/spec/perpetuity/postgres/query_expression_spec.rb +19 -19
- data/spec/perpetuity/postgres/query_intersection_spec.rb +3 -3
- data/spec/perpetuity/postgres/query_spec.rb +3 -3
- data/spec/perpetuity/postgres/query_union_spec.rb +3 -3
- data/spec/perpetuity/postgres/serialized_data_spec.rb +14 -14
- data/spec/perpetuity/postgres/serializer_spec.rb +23 -23
- data/spec/perpetuity/postgres/sql_function_spec.rb +2 -2
- data/spec/perpetuity/postgres/sql_select_spec.rb +11 -11
- data/spec/perpetuity/postgres/sql_update_spec.rb +2 -2
- data/spec/perpetuity/postgres/sql_value_spec.rb +14 -14
- data/spec/perpetuity/postgres/table/attribute_spec.rb +17 -17
- data/spec/perpetuity/postgres/table_name_spec.rb +2 -2
- data/spec/perpetuity/postgres/table_spec.rb +6 -6
- data/spec/perpetuity/postgres/text_value_spec.rb +2 -2
- data/spec/perpetuity/postgres/timestamp_value_spec.rb +4 -4
- data/spec/perpetuity/postgres/value_with_attribute_spec.rb +6 -6
- data/spec/perpetuity/postgres_spec.rb +38 -38
- metadata +6 -6
@@ -8,11 +8,11 @@ module Perpetuity
|
|
8
8
|
let(:title) { Attribute.new('title', String) }
|
9
9
|
|
10
10
|
it 'knows its name' do
|
11
|
-
title.name.
|
11
|
+
expect(title.name).to be == 'title'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'knows its type' do
|
15
|
-
title.type.
|
15
|
+
expect(title.type).to be == String
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'id' do
|
@@ -24,19 +24,19 @@ module Perpetuity
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'is a UUID type' do
|
27
|
-
id.sql_type.
|
27
|
+
expect(id.sql_type).to be == 'UUID'
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'is a primary key' do
|
31
|
-
id.
|
31
|
+
expect(id).to be_primary_key
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'can have a specified default' do
|
35
|
-
id.default.
|
35
|
+
expect(id.default).to be == Expression.new('uuid_generate_v4()')
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'generates the proper SQL' do
|
39
|
-
id.sql_declaration.
|
39
|
+
expect(id.sql_declaration).to be == 'id UUID PRIMARY KEY DEFAULT uuid_generate_v4()'
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -44,11 +44,11 @@ module Perpetuity
|
|
44
44
|
let(:body) { Attribute.new('body', String, default: 'foo') }
|
45
45
|
|
46
46
|
it 'converts to the proper SQL type' do
|
47
|
-
body.sql_type.
|
47
|
+
expect(body.sql_type).to be == 'TEXT'
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'generates the proper SQL' do
|
51
|
-
body.sql_declaration.
|
51
|
+
expect(body.sql_declaration).to be == "body TEXT DEFAULT 'foo'"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -57,8 +57,8 @@ module Perpetuity
|
|
57
57
|
let(:public_key) { Attribute.new('public_key', Bignum) }
|
58
58
|
|
59
59
|
it 'generates the proper SQL' do
|
60
|
-
page_views.sql_declaration.
|
61
|
-
public_key.sql_declaration.
|
60
|
+
expect(page_views.sql_declaration).to be == 'page_views BIGINT DEFAULT 0'
|
61
|
+
expect(public_key.sql_declaration).to be == 'public_key NUMERIC'
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -67,8 +67,8 @@ module Perpetuity
|
|
67
67
|
let(:precise_pi) { Attribute.new('precise_pi', BigDecimal) }
|
68
68
|
|
69
69
|
it 'generates the proper SQL' do
|
70
|
-
pi.sql_declaration.
|
71
|
-
precise_pi.sql_declaration.
|
70
|
+
expect(pi.sql_declaration).to be == 'pi FLOAT'
|
71
|
+
expect(precise_pi.sql_declaration).to be == 'precise_pi NUMERIC'
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,7 +76,7 @@ module Perpetuity
|
|
76
76
|
let(:timestamp) { Attribute.new('timestamp', Time) }
|
77
77
|
|
78
78
|
it 'converts to the SQL TIMESTAMPTZ type' do
|
79
|
-
timestamp.sql_type.
|
79
|
+
expect(timestamp.sql_type).to be == 'TIMESTAMPTZ'
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -84,14 +84,14 @@ module Perpetuity
|
|
84
84
|
let(:date) { Attribute.new('anniversary_date', Date) }
|
85
85
|
|
86
86
|
it 'converts to the SQL DATE type' do
|
87
|
-
date.sql_type.
|
87
|
+
expect(date.sql_type).to be == 'DATE'
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
describe 'booleans' do
|
92
92
|
it 'is stored in a BOOLEAN column' do
|
93
|
-
Attribute.new(:true, TrueClass).sql_type.
|
94
|
-
Attribute.new(:false, FalseClass).sql_type.
|
93
|
+
expect(Attribute.new(:true, TrueClass).sql_type).to be == 'BOOLEAN'
|
94
|
+
expect(Attribute.new(:false, FalseClass).sql_type).to be == 'BOOLEAN'
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -99,7 +99,7 @@ module Perpetuity
|
|
99
99
|
let(:author) { Attribute.new('author', Object) }
|
100
100
|
|
101
101
|
it 'has an SQL type of JSON' do
|
102
|
-
author.sql_type.
|
102
|
+
expect(author.sql_type).to be == 'JSON'
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -4,7 +4,7 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe TableName do
|
6
6
|
it 'converts to a SQL-string table name' do
|
7
|
-
TableName.new('Person').to_s.
|
7
|
+
expect(TableName.new('Person').to_s).to be == '"Person"'
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'cannot contain double quotes' do
|
@@ -12,7 +12,7 @@ module Perpetuity
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'compares equally to its string representation' do
|
15
|
-
TableName.new('Person').
|
15
|
+
expect(TableName.new('Person')).to be == 'Person'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -13,19 +13,19 @@ module Perpetuity
|
|
13
13
|
let(:table) { Table.new('Article', attributes) }
|
14
14
|
|
15
15
|
it 'knows its name' do
|
16
|
-
table.name.
|
16
|
+
expect(table.name).to be == 'Article'
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'knows its attributes' do
|
20
|
-
table.attributes.
|
20
|
+
expect(table.attributes).to be == attributes
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'converts to a string for SQL' do
|
24
|
-
table.to_s.
|
24
|
+
expect(table.to_s).to be == '"Article"'
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'generates proper SQL to create itself' do
|
28
|
-
table.create_table_sql.
|
28
|
+
expect(table.create_table_sql).to be ==
|
29
29
|
'CREATE TABLE IF NOT EXISTS "Article" (id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), title TEXT, body TEXT, author JSON, published_at TIMESTAMPTZ, views BIGINT)'
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ module Perpetuity
|
|
33
33
|
attributes = self.attributes.dup
|
34
34
|
attributes.unshift Table::Attribute.new(:id, String)
|
35
35
|
table = Table.new('Article', attributes)
|
36
|
-
table.create_table_sql.
|
36
|
+
expect(table.create_table_sql).to be ==
|
37
37
|
'CREATE TABLE IF NOT EXISTS "Article" (id TEXT PRIMARY KEY, title TEXT, body TEXT, author JSON, published_at TIMESTAMPTZ, views BIGINT)'
|
38
38
|
end
|
39
39
|
|
@@ -42,7 +42,7 @@ module Perpetuity
|
|
42
42
|
it 'uses the attribute type for the column type' do
|
43
43
|
attributes = [Table::Attribute.new(:id, String, primary_key: true), Table::Attribute.new(:name, String)]
|
44
44
|
table = Table.new('User', attributes)
|
45
|
-
table.create_table_sql.
|
45
|
+
expect(table.create_table_sql).to be == 'CREATE TABLE IF NOT EXISTS "User" (id TEXT PRIMARY KEY, name TEXT)'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -4,11 +4,11 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe TextValue do
|
6
6
|
it 'serializes into a Postgres-compatible string' do
|
7
|
-
TextValue.new('Jamie').to_s.
|
7
|
+
expect(TextValue.new('Jamie').to_s).to be == "'Jamie'"
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'escapes single quotes' do
|
11
|
-
TextValue.new("Jamie's house").to_s.
|
11
|
+
expect(TextValue.new("Jamie's house").to_s).to be == "'Jamie''s house'"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -5,25 +5,25 @@ module Perpetuity
|
|
5
5
|
describe TimestampValue do
|
6
6
|
it 'converts to a SQL string' do
|
7
7
|
time = Time.new(2000, 1, 2, 3, 4, 5.0123456, '-04:00')
|
8
|
-
TimestampValue.new(time).to_s.
|
8
|
+
expect(TimestampValue.new(time).to_s).to be == "'2000-01-02 03:04:05.012345-0400'::timestamptz"
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'conversion from a SQL value string' do
|
12
12
|
it 'converts GMT-X times' do
|
13
13
|
actual = TimestampValue.from_sql('2013-12-01 15:31:23.838367-05')
|
14
14
|
expected = Time.new(2013, 12, 1, 15, 31, 23.838367, '-05:00')
|
15
|
-
actual.to_time.
|
15
|
+
expect(actual.to_time).to be_within(0.0000001).of expected
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'converts GMT+X times' do
|
19
19
|
actual = TimestampValue.from_sql('1982-08-25 22:19:10.123456+08')
|
20
20
|
expected = Time.new(1982, 8, 25, 10, 19, 10.123456, '-04:00')
|
21
|
-
actual.to_time.
|
21
|
+
expect(actual.to_time).to be_within(0.0000001).of expected
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns its wrapped value' do
|
26
|
-
TimestampValue.new(:foo).value.
|
26
|
+
expect(TimestampValue.new(:foo).value).to be == :foo
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -8,18 +8,18 @@ module Perpetuity
|
|
8
8
|
let(:serialized) { ValueWithAttribute.new('foo', attribute) }
|
9
9
|
|
10
10
|
it 'contains a value and an attribute' do
|
11
|
-
serialized.value.
|
12
|
-
serialized.attribute.
|
11
|
+
expect(serialized.value).to be == 'foo'
|
12
|
+
expect(serialized.attribute).to be == attribute
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'knows its type' do
|
16
|
-
serialized.type.
|
16
|
+
expect(serialized.type).to be String
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when attribute is embedded' do
|
20
20
|
let(:attribute) { OpenStruct.new(embedded?: true) }
|
21
21
|
it 'is embedded' do
|
22
|
-
serialized.
|
22
|
+
expect(serialized).to be_embedded
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,12 +27,12 @@ module Perpetuity
|
|
27
27
|
let(:attribute) { OpenStruct.new(embedded?: false) }
|
28
28
|
|
29
29
|
it 'is not embedded' do
|
30
|
-
serialized.
|
30
|
+
expect(serialized).not_to be_embedded
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'passes messages to the value' do
|
35
|
-
serialized.upcase.
|
35
|
+
expect(serialized.upcase).to be == 'FOO'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -28,7 +28,7 @@ module Perpetuity
|
|
28
28
|
|
29
29
|
[:host, :port, :db, :pool_size, :username, :password].each do |attribute|
|
30
30
|
it "returns its #{attribute}" do
|
31
|
-
postgres.public_send(attribute).
|
31
|
+
expect(postgres.public_send(attribute)).to be == send(attribute)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -37,23 +37,23 @@ module Perpetuity
|
|
37
37
|
let(:postgres) { Postgres.new(db: 'my_db') }
|
38
38
|
|
39
39
|
it 'defaults to host = localhost' do
|
40
|
-
postgres.host.
|
40
|
+
expect(postgres.host).to be == 'localhost'
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'defaults to port = 5432 (Postgres default)' do
|
44
|
-
postgres.port.
|
44
|
+
expect(postgres.port).to be == 5432
|
45
45
|
end
|
46
46
|
|
47
47
|
it "defaults to username = #{ENV['USER']}" do
|
48
|
-
postgres.username.
|
48
|
+
expect(postgres.username).to be == ENV['USER']
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'defaults to a blank password' do
|
52
|
-
postgres.password.
|
52
|
+
expect(postgres.password).to be nil
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'defaults to pool_size = 5' do
|
56
|
-
postgres.pool_size.
|
56
|
+
expect(postgres.pool_size).to be == 5
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -64,10 +64,10 @@ module Perpetuity
|
|
64
64
|
Postgres::Table::Attribute.new('body', String),
|
65
65
|
Postgres::Table::Attribute.new('author', Object)
|
66
66
|
]
|
67
|
-
postgres.
|
67
|
+
expect(postgres).to have_table('Article')
|
68
68
|
|
69
69
|
postgres.drop_table 'Article'
|
70
|
-
postgres.
|
70
|
+
expect(postgres).not_to have_table 'Article'
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'adds columns automatically if they are not there' do
|
@@ -86,15 +86,15 @@ module Perpetuity
|
|
86
86
|
["'Jamie'", "'2013-1-1'"])]
|
87
87
|
id = postgres.insert('Article', data, attributes).first
|
88
88
|
|
89
|
-
postgres.find('Article', id)['timestamp'].
|
89
|
+
expect(postgres.find('Article', id)['timestamp']).to be =~ /2013/
|
90
90
|
|
91
91
|
postgres.drop_table 'Article' # Cleanup
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'converts values into something that works with the DB' do
|
95
|
-
postgres.postgresify("string").
|
96
|
-
postgres.postgresify(1).
|
97
|
-
postgres.postgresify(true).
|
95
|
+
expect(postgres.postgresify("string")).to be == "'string'"
|
96
|
+
expect(postgres.postgresify(1)).to be == '1'
|
97
|
+
expect(postgres.postgresify(true)).to be == 'TRUE'
|
98
98
|
end
|
99
99
|
|
100
100
|
describe 'working with data' do
|
@@ -109,8 +109,8 @@ module Perpetuity
|
|
109
109
|
id = postgres.insert('User', data, attributes).first
|
110
110
|
result = postgres.find('User', id)
|
111
111
|
|
112
|
-
id.
|
113
|
-
result['name'].
|
112
|
+
expect(id).to be =~ /[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}/
|
113
|
+
expect(result['name']).to be == 'Jamie'
|
114
114
|
end
|
115
115
|
|
116
116
|
describe 'returning ids' do
|
@@ -118,7 +118,7 @@ module Perpetuity
|
|
118
118
|
data << Postgres::SerializedData.new([:name], ["'Jessica'"]) <<
|
119
119
|
Postgres::SerializedData.new([:name], ["'Kevin'"])
|
120
120
|
ids = postgres.insert('User', data, attributes)
|
121
|
-
ids.
|
121
|
+
expect(ids).to be_a Array
|
122
122
|
expect(ids.count).to eq 3
|
123
123
|
end
|
124
124
|
|
@@ -127,7 +127,7 @@ module Perpetuity
|
|
127
127
|
attributes << Attribute.new(:id, Integer)
|
128
128
|
data.first[:id] = 1234
|
129
129
|
ids = postgres.insert 'User', data, attributes
|
130
|
-
ids.first.
|
130
|
+
expect(ids.first).to be == 1234
|
131
131
|
postgres.drop_table 'User'
|
132
132
|
end
|
133
133
|
end
|
@@ -144,12 +144,12 @@ module Perpetuity
|
|
144
144
|
|
145
145
|
it 'returns a count of 0 when the table does not exist' do
|
146
146
|
postgres.drop_table 'Article'
|
147
|
-
postgres.count('Article').
|
147
|
+
expect(postgres.count('Article')).to be == 0
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'returns no rows when the table does not exist' do
|
151
151
|
postgres.drop_table 'Article'
|
152
|
-
postgres.retrieve('Article', 'TRUE').
|
152
|
+
expect(postgres.retrieve('Article', 'TRUE')).to be == []
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'updates a specific record' do
|
@@ -157,7 +157,7 @@ module Perpetuity
|
|
157
157
|
postgres.update 'User', id, name: 'foo'
|
158
158
|
|
159
159
|
retrieved = postgres.retrieve 'User', "id = '#{id}'"
|
160
|
-
retrieved.first['name'].
|
160
|
+
expect(retrieved.first['name']).to be == 'foo'
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'updates a record when a column does not currently exist' do
|
@@ -165,14 +165,14 @@ module Perpetuity
|
|
165
165
|
postgres.update 'User', id, Postgres::SerializedData.new(['foo'], ["'bar'"])
|
166
166
|
|
167
167
|
retrieved = postgres.retrieve('User', "id = '#{id}'")
|
168
|
-
retrieved.first['foo'].
|
168
|
+
expect(retrieved.first['foo']).to be == 'bar'
|
169
169
|
end
|
170
170
|
|
171
171
|
describe 'deletion' do
|
172
172
|
it 'deletes all records' do
|
173
173
|
postgres.insert 'User', data, attributes
|
174
174
|
postgres.delete_all 'User'
|
175
|
-
postgres.count('User').
|
175
|
+
expect(postgres.count('User')).to be == 0
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'deletes a record with a specific id' do
|
@@ -197,42 +197,42 @@ module Perpetuity
|
|
197
197
|
it 'increments a value for a record' do
|
198
198
|
id = postgres.insert('Increment', data, attributes).first
|
199
199
|
postgres.increment 'Increment', id, :n, 10
|
200
|
-
postgres.find('Increment', id)['n'].
|
200
|
+
expect(postgres.find('Increment', id)['n']).to be == '11'
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
describe 'query generation' do
|
206
206
|
it 'creates SQL queries with a block' do
|
207
|
-
postgres.query { |o| o.name == 'foo' }.to_db.
|
207
|
+
expect(postgres.query { |o| o.name == 'foo' }.to_db).to be ==
|
208
208
|
"name = 'foo'"
|
209
209
|
end
|
210
210
|
|
211
211
|
it 'does not allow SQL injection' do
|
212
212
|
query = postgres.query { |o| o.name == "' OR 1; --" }.to_db
|
213
|
-
query.
|
213
|
+
expect(query).to be == "name = ''' OR 1; --'"
|
214
214
|
end
|
215
215
|
|
216
216
|
it 'limits results' do
|
217
217
|
query = postgres.query
|
218
218
|
sql = postgres.select(from: 'Article', where: query, limit: 2)
|
219
|
-
sql.
|
219
|
+
expect(sql).to be == %Q{SELECT * FROM "Article" WHERE TRUE LIMIT 2}
|
220
220
|
end
|
221
221
|
|
222
222
|
describe 'ordering results' do
|
223
223
|
it 'orders results without a qualifier' do
|
224
224
|
sql = postgres.select(from: 'Article', order: :title)
|
225
|
-
sql.
|
225
|
+
expect(sql).to be == %Q{SELECT * FROM "Article" ORDER BY title}
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'orders results with asc' do
|
229
229
|
sql = postgres.select(from: 'Article', order: { title: :asc })
|
230
|
-
sql.
|
230
|
+
expect(sql).to be == %Q{SELECT * FROM "Article" ORDER BY title ASC}
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'reverse-orders results' do
|
234
234
|
sql = postgres.select(from: 'Article', order: { title: :desc })
|
235
|
-
sql.
|
235
|
+
expect(sql).to be == %Q{SELECT * FROM "Article" ORDER BY title DESC}
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -255,10 +255,10 @@ module Perpetuity
|
|
255
255
|
|
256
256
|
active_indexes = postgres.active_indexes(Object)
|
257
257
|
index = active_indexes.find { |i| i.attribute_names == ['title'] }
|
258
|
-
index.attribute_names.
|
259
|
-
index.table.
|
260
|
-
index.
|
261
|
-
index.
|
258
|
+
expect(index.attribute_names).to be == ['title']
|
259
|
+
expect(index.table).to be == 'Object'
|
260
|
+
expect(index).to be_unique
|
261
|
+
expect(index).to be_active
|
262
262
|
end
|
263
263
|
|
264
264
|
describe 'adding indexes to the database' do
|
@@ -266,17 +266,17 @@ module Perpetuity
|
|
266
266
|
title_attribute = Attribute.new(:title, String)
|
267
267
|
postgres.index Object, title_attribute
|
268
268
|
index = postgres.indexes(Object).find { |i| i.attributes.map(&:name) == [:title] }
|
269
|
-
index.attribute_names.
|
270
|
-
index.table.
|
271
|
-
index.
|
272
|
-
index.
|
269
|
+
expect(index.attribute_names).to be == ['title']
|
270
|
+
expect(index.table).to be == 'Object'
|
271
|
+
expect(index).not_to be_unique
|
272
|
+
expect(index).not_to be_active
|
273
273
|
end
|
274
274
|
|
275
275
|
it 'activates the specified index' do
|
276
276
|
title_attribute = Attribute.new(:title, String)
|
277
277
|
index = postgres.index Object, title_attribute
|
278
278
|
postgres.activate_index! index
|
279
|
-
postgres.active_indexes(Object).map(&:attribute_names).
|
279
|
+
expect(postgres.active_indexes(Object).map(&:attribute_names)).to include ['title']
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
@@ -285,7 +285,7 @@ module Perpetuity
|
|
285
285
|
index = postgres.index(Object, Attribute.new(:title, String))
|
286
286
|
postgres.activate_index! index
|
287
287
|
postgres.remove_index index
|
288
|
-
postgres.active_indexes(Object).map(&:attribute_names).
|
288
|
+
expect(postgres.active_indexes(Object).map(&:attribute_names)).not_to include ['title']
|
289
289
|
end
|
290
290
|
end
|
291
291
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perpetuity-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|