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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbfd7bfbff611c846132965cc13c105ac722f469
|
4
|
+
data.tar.gz: 70179a20ab781629f0f1c56e6639104476e5fbe1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbe960158dfbab549a471033e7e8219f477aa2e3f2c573c685b9eee7ac8bdbbb5d1877f7df9722fb98310f6e67186b4b6103658027f518e4173f1683b4f65d7a
|
7
|
+
data.tar.gz: c380f8f7b8cc6ccbf731dc92e58dd7995c95ac91d4629c856553fd4d672afb3133a2cbffd88220b499c675afe56d5c767d7f64cc9b5141505bbf4ca6d9f493bc
|
data/CHANGELOG.md
CHANGED
@@ -43,6 +43,18 @@ module Perpetuity
|
|
43
43
|
|
44
44
|
def execute sql
|
45
45
|
pg_connection.exec sql
|
46
|
+
rescue PG::AdminShutdown, PG::UnableToSend => e
|
47
|
+
# server closed the connection unexpectedly
|
48
|
+
# Try to reconnect 3 times in case it's just a server restart.
|
49
|
+
unable_to_send_retries ||= 0
|
50
|
+
if unable_to_send_retries < 3
|
51
|
+
connect
|
52
|
+
unable_to_send_retries += 1
|
53
|
+
sleep 1
|
54
|
+
retry
|
55
|
+
else
|
56
|
+
raise
|
57
|
+
end
|
46
58
|
rescue PG::UndefinedFunction => e
|
47
59
|
if e.message =~ /uuid_generate/
|
48
60
|
use_uuid_extension
|
data/perpetuity-postgres.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_runtime_dependency "perpetuity", "~> 1.0.0"
|
25
25
|
spec.add_runtime_dependency "pg"
|
@@ -4,11 +4,11 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe BooleanValue do
|
6
6
|
it 'serializes true into a Postgres true value' do
|
7
|
-
BooleanValue.new(true).to_s.
|
7
|
+
expect(BooleanValue.new(true).to_s).to be == 'TRUE'
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'serializes false into a Postgres false value' do
|
11
|
-
BooleanValue.new(false).to_s.
|
11
|
+
expect(BooleanValue.new(false).to_s).to be == 'FALSE'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -26,19 +26,18 @@ module Perpetuity
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'returns the value of the block' do
|
29
|
-
pool.lend_connection { 1 }.
|
29
|
+
expect(pool.lend_connection { 1 }).to be == 1
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'executes a given SQL statement' do
|
34
34
|
sql = "SELECT TRUE"
|
35
|
-
Connection.
|
36
|
-
.with(sql)
|
35
|
+
expect_any_instance_of(Connection).to receive(:execute).with(sql)
|
37
36
|
pool.execute sql
|
38
37
|
end
|
39
38
|
|
40
39
|
it 'passes the tables message to a connection' do
|
41
|
-
Connection.
|
40
|
+
expect_any_instance_of(Connection).to receive(:tables)
|
42
41
|
pool.tables
|
43
42
|
end
|
44
43
|
|
@@ -7,24 +7,24 @@ module Perpetuity
|
|
7
7
|
|
8
8
|
it 'sanitizes the options for the pg gem' do
|
9
9
|
options = { db: 'db', username: 'user' }
|
10
|
-
connection.sanitize_options(options).
|
10
|
+
expect(connection.sanitize_options(options)).to be == {
|
11
11
|
dbname: 'db',
|
12
12
|
user: 'user'
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'is only activated when it is used' do
|
17
|
-
connection.
|
18
|
-
PG.
|
17
|
+
expect(connection).not_to be_active
|
18
|
+
allow(PG).to receive(:connect) { double(exec: true) }
|
19
19
|
connection.connect
|
20
|
-
connection.
|
20
|
+
expect(connection).to be_active
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'executes SQL' do
|
24
24
|
connection.execute 'CREATE TABLE IF NOT EXISTS abcdefg (name text)'
|
25
|
-
connection.tables.
|
25
|
+
expect(connection.tables).to include 'abcdefg'
|
26
26
|
connection.execute 'DROP TABLE IF EXISTS abcdefg'
|
27
|
-
connection.tables.
|
27
|
+
expect(connection.tables).not_to include 'abcdefg'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -5,19 +5,19 @@ module Perpetuity
|
|
5
5
|
describe DateValue do
|
6
6
|
it 'converts to a SQL string' do
|
7
7
|
date = Date.new(2014, 8, 25)
|
8
|
-
DateValue.new(date).to_s.
|
8
|
+
expect(DateValue.new(date).to_s).to be == "'2014-08-25'::date"
|
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 = DateValue.from_sql('2013-12-01')
|
14
14
|
expected = Date.new(2013, 12, 1)
|
15
|
-
actual.to_date.
|
15
|
+
expect(actual.to_date).to be == expected
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'returns its wrapped value' do
|
20
|
-
DateValue.new(:foo).value.
|
20
|
+
expect(DateValue.new(:foo).value).to be == :foo
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -7,22 +7,22 @@ module Perpetuity
|
|
7
7
|
let(:indexes) { IndexCollection.new(Object) }
|
8
8
|
|
9
9
|
it 'knows which table it is indexing' do
|
10
|
-
indexes.table.
|
10
|
+
expect(indexes.table).to be == 'Object'
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'iterates over its indexes' do
|
14
14
|
indexes << 1
|
15
|
-
indexes.map { |index| index.to_s }.
|
15
|
+
expect(indexes.map { |index| index.to_s }).to include '1'
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'converts to an array' do
|
19
|
-
indexes.to_ary.
|
19
|
+
expect(indexes.to_ary).to be == []
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'removes indexes based on a block' do
|
23
23
|
indexes << double('Index', name: 'lol')
|
24
24
|
indexes.reject! { |index| index.name == 'lol' }
|
25
|
-
indexes.map(&:name).
|
25
|
+
expect(indexes.map(&:name)).not_to include 'lol'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -12,11 +12,11 @@ module Perpetuity
|
|
12
12
|
}
|
13
13
|
|
14
14
|
index = Index.from_sql(index_hash)
|
15
|
-
index.attribute_names.
|
16
|
-
index.name.
|
17
|
-
index.table.
|
18
|
-
index.
|
19
|
-
index.
|
15
|
+
expect(index.attribute_names).to be == ['id', 'name']
|
16
|
+
expect(index.name).to be == 'Object_id_name_index'
|
17
|
+
expect(index.table).to be == 'Object'
|
18
|
+
expect(index).to be_unique
|
19
|
+
expect(index).to be_active
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'sets itself as active' do
|
@@ -24,9 +24,9 @@ module Perpetuity
|
|
24
24
|
name: 'Table',
|
25
25
|
unique: false)
|
26
26
|
|
27
|
-
index.
|
27
|
+
expect(index).not_to be_active
|
28
28
|
index.activate!
|
29
|
-
index.
|
29
|
+
expect(index).to be_active
|
30
30
|
end
|
31
31
|
|
32
32
|
describe 'equality' do
|
@@ -41,7 +41,7 @@ module Perpetuity
|
|
41
41
|
|
42
42
|
it 'is equal to an index with identical state' do
|
43
43
|
new_index = index.dup
|
44
|
-
new_index.
|
44
|
+
expect(new_index).to be == index
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'is not equal to an index with different attributes' do
|
@@ -49,14 +49,14 @@ module Perpetuity
|
|
49
49
|
name: name,
|
50
50
|
unique: unique)
|
51
51
|
|
52
|
-
new_index.
|
52
|
+
expect(new_index).not_to be == index
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'is equal to an index with stringified attributes' do
|
56
56
|
new_index = Index.new(attributes: attributes.map(&:to_s),
|
57
57
|
name: name,
|
58
58
|
unique: unique)
|
59
|
-
new_index.
|
59
|
+
expect(new_index).to be == index
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'is not equal to an index with another name' do
|
@@ -64,18 +64,18 @@ module Perpetuity
|
|
64
64
|
name: 'NotObject',
|
65
65
|
unique: unique)
|
66
66
|
|
67
|
-
new_index.
|
67
|
+
expect(new_index).not_to be == index
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'is not equal to an index with opposite uniqueness' do
|
71
71
|
new_index = Index.new(attributes: attributes,
|
72
72
|
name: name,
|
73
73
|
unique: !unique)
|
74
|
-
new_index.
|
74
|
+
expect(new_index).not_to be == index
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'is not equal to things that are not indexes' do
|
78
|
-
index.
|
78
|
+
expect(index).not_to be == 'lol'
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -4,31 +4,31 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe JSONArray do
|
6
6
|
it 'serializes empty arrays' do
|
7
|
-
JSONArray.new([]).to_s.
|
7
|
+
expect(JSONArray.new([]).to_s).to be == "'[]'"
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'serializes arrays of numeric values' do
|
11
|
-
JSONArray.new([1,2,3]).to_s.
|
11
|
+
expect(JSONArray.new([1,2,3]).to_s).to be == "'[1,2,3]'"
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'serializes arrays of strings' do
|
15
|
-
JSONArray.new(%w(foo bar baz)).to_s.
|
15
|
+
expect(JSONArray.new(%w(foo bar baz)).to_s).to be == %q{'["foo","bar","baz"]'}
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'serializes arrays of hashes' do
|
19
|
-
JSONArray.new([{a: 1}, {b: 2}]).to_s.
|
19
|
+
expect(JSONArray.new([{a: 1}, {b: 2}]).to_s).to be == %q{'[{"a":1},{"b":2}]'}
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'serializes arrays of JSONHashes' do
|
23
|
-
JSONArray.new([JSONHash.new(a: 1)]).to_s.
|
23
|
+
expect(JSONArray.new([JSONHash.new(a: 1)]).to_s).to be == %q{'[{"a":1}]'}
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'serializes arrays of arrays' do
|
27
|
-
JSONArray.new([[1], ['foo']]).to_s.
|
27
|
+
expect(JSONArray.new([[1], ['foo']]).to_s).to be == %q{'[[1],["foo"]]'}
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'serializes elements of arrays' do
|
31
|
-
JSONArray.new([1,'a']).to_s.
|
31
|
+
expect(JSONArray.new([1,'a']).to_s).to be == %q{'[1,"a"]'}
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -4,44 +4,44 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe JSONHash do
|
6
6
|
it 'serializes empty hashes' do
|
7
|
-
JSONHash.new({}).to_s.
|
7
|
+
expect(JSONHash.new({}).to_s).to be == "'{}'"
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'serializes hashes with string elements' do
|
11
|
-
JSONHash.new({a: 'b'}).to_s.
|
11
|
+
expect(JSONHash.new({a: 'b'}).to_s).to be == %q{'{"a":"b"}'}
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'serializes hashes with numeric elements' do
|
15
|
-
JSONHash.new({a: 1}).to_s.
|
15
|
+
expect(JSONHash.new({a: 1}).to_s).to be == %q{'{"a":1}'}
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'serializes hashes with boolean elements' do
|
19
|
-
JSONHash.new({a: true, b: false}).to_s.
|
19
|
+
expect(JSONHash.new({a: true, b: false}).to_s).to be == %q('{"a":true,"b":false}')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'serializes nil values' do
|
23
|
-
JSONHash.new({a: nil}).to_s.
|
23
|
+
expect(JSONHash.new({a: nil}).to_s).to be == %q('{"a":null}')
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not surround the an inner serialized value with quotes' do
|
27
|
-
JSONHash.new({a: 1}, :inner).to_s.
|
27
|
+
expect(JSONHash.new({a: 1}, :inner).to_s).to be == %q[{"a":1}]
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'serializes hashes with multiple entries' do
|
31
|
-
JSONHash.new({a: 1, b: 'c'}).to_s.
|
31
|
+
expect(JSONHash.new({a: 1, b: 'c'}).to_s).to be == %q{'{"a":1,"b":"c"}'}
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'serializes a hash with array values' do
|
35
|
-
JSONHash.new({foo: ['bar', 'baz', 'quux']}).to_s.
|
35
|
+
expect(JSONHash.new({foo: ['bar', 'baz', 'quux']}).to_s).to be ==
|
36
36
|
%q{'{"foo":["bar","baz","quux"]}'}
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'converts back to a hash' do
|
40
|
-
JSONHash.new({a: 1}).to_hash.
|
40
|
+
expect(JSONHash.new({a: 1}).to_hash).to be == { a: 1 }
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'is equal to an identical hash' do
|
44
|
-
JSONHash.new(a: 1).
|
44
|
+
expect(JSONHash.new(a: 1)).to be == JSONHash.new(a: 1)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -4,15 +4,15 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe JSONStringValue do
|
6
6
|
it 'serializes into a JSON string value' do
|
7
|
-
JSONStringValue.new('Jamie').to_s.
|
7
|
+
expect(JSONStringValue.new('Jamie').to_s).to be == '"Jamie"'
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'converts symbols into strings' do
|
11
|
-
JSONStringValue.new(:foo).to_s.
|
11
|
+
expect(JSONStringValue.new(:foo).to_s).to be == '"foo"'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'escapes quotes' do
|
15
|
-
JSONStringValue.new('Anakin "Darth Vader" Skywalker').to_s.
|
15
|
+
expect(JSONStringValue.new('Anakin "Darth Vader" Skywalker').to_s).to be ==
|
16
16
|
'"Anakin \\"Darth Vader\\" Skywalker"'
|
17
17
|
end
|
18
18
|
end
|
@@ -4,35 +4,35 @@ module Perpetuity
|
|
4
4
|
class Postgres
|
5
5
|
describe NegatedQuery do
|
6
6
|
it 'negates equality' do
|
7
|
-
NegatedQuery.new { |o| o.name == 'foo' }.to_db.
|
7
|
+
expect(NegatedQuery.new { |o| o.name == 'foo' }.to_db).to be == "NOT (name = 'foo')"
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'negates regex matching' do
|
11
|
-
NegatedQuery.new { |o| o.name =~ /foo/ }.to_db.
|
11
|
+
expect(NegatedQuery.new { |o| o.name =~ /foo/ }.to_db).to be == "NOT (name ~ 'foo')"
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'negates case-insensitive regex matching' do
|
15
|
-
NegatedQuery.new { |o| o.name =~ /foo/i }.to_db.
|
15
|
+
expect(NegatedQuery.new { |o| o.name =~ /foo/i }.to_db).to be == "NOT (name ~* 'foo')"
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'negates inequality' do
|
19
|
-
NegatedQuery.new { |o| o.name != /foo/i }.to_db.
|
19
|
+
expect(NegatedQuery.new { |o| o.name != /foo/i }.to_db).to be == "NOT (name != 'foo')"
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'negates greater-than' do
|
23
|
-
NegatedQuery.new { |o| o.age > 1 }.to_db.
|
23
|
+
expect(NegatedQuery.new { |o| o.age > 1 }.to_db).to be == "NOT (age > 1)"
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'negates greater-than-or-equal' do
|
27
|
-
NegatedQuery.new { |o| o.age >= 1 }.to_db.
|
27
|
+
expect(NegatedQuery.new { |o| o.age >= 1 }.to_db).to be == "NOT (age >= 1)"
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'negates less-than' do
|
31
|
-
NegatedQuery.new { |o| o.age < 1 }.to_db.
|
31
|
+
expect(NegatedQuery.new { |o| o.age < 1 }.to_db).to be == "NOT (age < 1)"
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'negates less-than-or-equal' do
|
35
|
-
NegatedQuery.new { |o| o.age <= 1 }.to_db.
|
35
|
+
expect(NegatedQuery.new { |o| o.age <= 1 }.to_db).to be == "NOT (age <= 1)"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -6,62 +6,62 @@ module Perpetuity
|
|
6
6
|
let(:attribute) { QueryAttribute.new :attribute_name }
|
7
7
|
|
8
8
|
it 'returns its name' do
|
9
|
-
attribute.name.
|
9
|
+
expect(attribute.name).to be == :attribute_name
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'checks for equality' do
|
13
|
-
(attribute == 1).
|
13
|
+
expect((attribute == 1)).to be_a QueryExpression
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'checks for less than' do
|
17
|
-
(attribute < 1).
|
17
|
+
expect((attribute < 1)).to be_a QueryExpression
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'checks for <=' do
|
21
|
-
(attribute <= 1).
|
21
|
+
expect((attribute <= 1)).to be_a QueryExpression
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'checks for greater than' do
|
25
|
-
(attribute > 1).
|
25
|
+
expect((attribute > 1)).to be_a QueryExpression
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'checks for >=' do
|
29
|
-
(attribute >= 1).
|
29
|
+
expect((attribute >= 1)).to be_a QueryExpression
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'checks for inequality' do
|
33
|
-
(attribute != 1).
|
33
|
+
expect((attribute != 1)).to be_a QueryExpression
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'checks for regexp matches' do
|
37
|
-
(attribute =~ /value/).
|
37
|
+
expect((attribute =~ /value/)).to be_a QueryExpression
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'checks for inclusion' do
|
41
|
-
(attribute.in [1, 2, 3]).
|
41
|
+
expect((attribute.in [1, 2, 3])).to be_a QueryExpression
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'checks for existence' do
|
45
|
-
(attribute.any?).to_db.
|
45
|
+
expect((attribute.any?).to_db).to be == 'json_array_length(attribute_name) > 0'
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'checks for no existence' do
|
49
|
-
(attribute.none?).to_db.
|
49
|
+
expect((attribute.none?).to_db).to be == 'json_array_length(attribute_name) = 0'
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'checks for nil' do
|
53
|
-
attribute.nil
|
53
|
+
expect(attribute.nil?).to be_a QueryExpression
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'checks for truthiness' do
|
57
|
-
attribute.to_db.
|
57
|
+
expect(attribute.to_db).to be == 'attribute_name IS NOT NULL'
|
58
58
|
end
|
59
59
|
|
60
60
|
describe 'nested attributes' do
|
61
61
|
it 'checks for an id' do
|
62
62
|
id = attribute.id
|
63
|
-
id.
|
64
|
-
id.name.
|
63
|
+
expect(id).to be_a QueryAttribute
|
64
|
+
expect(id.name).to be == %q{attribute_name->'__metadata__'->>'id'}
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|