rom-sql 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
- data/lib/rom/sql.rb +1 -1
- data/lib/rom/sql/attribute.rb +17 -18
- data/lib/rom/sql/errors.rb +3 -0
- data/lib/rom/sql/extensions/mysql.rb +1 -1
- data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
- data/lib/rom/sql/extensions/postgres.rb +3 -1
- data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
- data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
- data/lib/rom/sql/extensions/postgres/types.rb +24 -477
- data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
- data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
- data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
- data/lib/rom/sql/extensions/sqlite.rb +1 -1
- data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
- data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
- data/lib/rom/sql/foreign_key.rb +17 -0
- data/lib/rom/sql/function.rb +86 -8
- data/lib/rom/sql/gateway.rb +26 -26
- data/lib/rom/sql/index.rb +4 -0
- data/lib/rom/sql/migration.rb +3 -3
- data/lib/rom/sql/migration/inline_runner.rb +9 -83
- data/lib/rom/sql/migration/migrator.rb +35 -12
- data/lib/rom/sql/migration/recorder.rb +21 -0
- data/lib/rom/sql/migration/runner.rb +115 -0
- data/lib/rom/sql/migration/schema_diff.rb +108 -53
- data/lib/rom/sql/migration/writer.rb +61 -0
- data/lib/rom/sql/relation.rb +2 -1
- data/lib/rom/sql/relation/reading.rb +63 -3
- data/lib/rom/sql/relation/writing.rb +38 -0
- data/lib/rom/sql/schema.rb +9 -3
- data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
- data/lib/rom/sql/schema/inferrer.rb +99 -18
- data/lib/rom/sql/schema/type_builder.rb +94 -0
- data/lib/rom/sql/type_dsl.rb +30 -0
- data/lib/rom/sql/type_extensions.rb +11 -6
- data/lib/rom/sql/type_serializer.rb +46 -0
- data/lib/rom/sql/types.rb +12 -0
- data/lib/rom/sql/version.rb +1 -1
- metadata +26 -244
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -17
- data/.rspec +0 -3
- data/.travis.yml +0 -39
- data/.yardopts +0 -2
- data/Gemfile +0 -33
- data/Guardfile +0 -24
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -19
- data/circle.yml +0 -10
- data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
- data/lib/rom/sql/relation/sequel_api.rb +0 -133
- data/log/.gitkeep +0 -0
- data/rom-sql.gemspec +0 -29
- data/spec/extensions/postgres/attribute_spec.rb +0 -217
- data/spec/extensions/postgres/integration_spec.rb +0 -59
- data/spec/extensions/postgres/types_spec.rb +0 -252
- data/spec/extensions/sqlite/types_spec.rb +0 -11
- data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
- data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
- data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
- data/spec/integration/associations/many_to_many_spec.rb +0 -162
- data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
- data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
- data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
- data/spec/integration/associations/many_to_one_spec.rb +0 -117
- data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
- data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
- data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
- data/spec/integration/associations/one_to_many_spec.rb +0 -86
- data/spec/integration/associations/one_to_one_spec.rb +0 -69
- data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
- data/spec/integration/auto_migrations/errors_spec.rb +0 -31
- data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
- data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
- data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
- data/spec/integration/combine_with_spec.rb +0 -43
- data/spec/integration/commands/create_spec.rb +0 -304
- data/spec/integration/commands/delete_spec.rb +0 -84
- data/spec/integration/commands/update_spec.rb +0 -90
- data/spec/integration/commands/upsert_spec.rb +0 -83
- data/spec/integration/gateway_spec.rb +0 -107
- data/spec/integration/migration_spec.rb +0 -55
- data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
- data/spec/integration/plugins/associates_spec.rb +0 -250
- data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
- data/spec/integration/relation_schema_spec.rb +0 -271
- data/spec/integration/schema/call_spec.rb +0 -24
- data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
- data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
- data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
- data/spec/integration/schema/inferrer_spec.rb +0 -390
- data/spec/integration/schema/prefix_spec.rb +0 -16
- data/spec/integration/schema/qualified_spec.rb +0 -16
- data/spec/integration/schema/rename_spec.rb +0 -21
- data/spec/integration/schema/view_spec.rb +0 -29
- data/spec/integration/sequel_api_spec.rb +0 -36
- data/spec/integration/setup_spec.rb +0 -26
- data/spec/integration/support/active_support_notifications_spec.rb +0 -24
- data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
- data/spec/integration/wrap_spec.rb +0 -91
- data/spec/shared/accounts.rb +0 -48
- data/spec/shared/database_setup.rb +0 -70
- data/spec/shared/notes.rb +0 -23
- data/spec/shared/posts.rb +0 -34
- data/spec/shared/puppies.rb +0 -15
- data/spec/shared/relations.rb +0 -8
- data/spec/shared/users.rb +0 -32
- data/spec/shared/users_and_tasks.rb +0 -50
- data/spec/spec_helper.rb +0 -122
- data/spec/support/env_helper.rb +0 -25
- data/spec/support/helpers.rb +0 -24
- data/spec/support/oracle/create_users.sql +0 -7
- data/spec/support/oracle/set_sys_passwords.sql +0 -2
- data/spec/support/test_configuration.rb +0 -16
- data/spec/unit/attribute_spec.rb +0 -104
- data/spec/unit/function_spec.rb +0 -48
- data/spec/unit/gateway_spec.rb +0 -70
- data/spec/unit/logger_spec.rb +0 -14
- data/spec/unit/migration_tasks_spec.rb +0 -111
- data/spec/unit/migrator_spec.rb +0 -25
- data/spec/unit/order_dsl_spec.rb +0 -43
- data/spec/unit/plugin/associates_spec.rb +0 -94
- data/spec/unit/plugin/pagination_spec.rb +0 -91
- data/spec/unit/plugin/timestamp_spec.rb +0 -117
- data/spec/unit/projection_dsl_spec.rb +0 -110
- data/spec/unit/relation/assoc_spec.rb +0 -87
- data/spec/unit/relation/associations_spec.rb +0 -27
- data/spec/unit/relation/avg_spec.rb +0 -11
- data/spec/unit/relation/by_pk_spec.rb +0 -62
- data/spec/unit/relation/dataset_spec.rb +0 -50
- data/spec/unit/relation/distinct_spec.rb +0 -15
- data/spec/unit/relation/exclude_spec.rb +0 -11
- data/spec/unit/relation/exist_predicate_spec.rb +0 -25
- data/spec/unit/relation/exists_spec.rb +0 -18
- data/spec/unit/relation/fetch_spec.rb +0 -21
- data/spec/unit/relation/group_spec.rb +0 -61
- data/spec/unit/relation/having_spec.rb +0 -22
- data/spec/unit/relation/inner_join_spec.rb +0 -158
- data/spec/unit/relation/inspect_spec.rb +0 -11
- data/spec/unit/relation/instrument_spec.rb +0 -45
- data/spec/unit/relation/invert_spec.rb +0 -11
- data/spec/unit/relation/left_join_spec.rb +0 -55
- data/spec/unit/relation/lock_spec.rb +0 -93
- data/spec/unit/relation/map_spec.rb +0 -16
- data/spec/unit/relation/max_spec.rb +0 -11
- data/spec/unit/relation/min_spec.rb +0 -11
- data/spec/unit/relation/order_spec.rb +0 -51
- data/spec/unit/relation/pluck_spec.rb +0 -11
- data/spec/unit/relation/prefix_spec.rb +0 -29
- data/spec/unit/relation/primary_key_spec.rb +0 -27
- data/spec/unit/relation/project_spec.rb +0 -24
- data/spec/unit/relation/qualified_columns_spec.rb +0 -30
- data/spec/unit/relation/qualified_spec.rb +0 -25
- data/spec/unit/relation/read_spec.rb +0 -25
- data/spec/unit/relation/rename_spec.rb +0 -23
- data/spec/unit/relation/right_join_spec.rb +0 -57
- data/spec/unit/relation/select_append_spec.rb +0 -21
- data/spec/unit/relation/select_spec.rb +0 -40
- data/spec/unit/relation/sum_spec.rb +0 -11
- data/spec/unit/relation/union_spec.rb +0 -19
- data/spec/unit/relation/unique_predicate_spec.rb +0 -18
- data/spec/unit/relation/where_spec.rb +0 -133
- data/spec/unit/restriction_dsl_spec.rb +0 -34
- data/spec/unit/schema_spec.rb +0 -25
- data/spec/unit/types_spec.rb +0 -65
@@ -1,21 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Relation, '#select_append' do
|
2
|
-
subject(:relation) { relations[:tasks] }
|
3
|
-
|
4
|
-
include_context 'users and tasks'
|
5
|
-
|
6
|
-
with_adapters do
|
7
|
-
it 'appends new columns' do
|
8
|
-
selected = relation.select(:id).select_append(:title)
|
9
|
-
|
10
|
-
expect(selected.schema.map(&:name)).to eql(%i[id title])
|
11
|
-
expect(selected.first).to eql(id: 1, title: "Joe's task")
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'supports blocks' do
|
15
|
-
selected = relation.select(:id).select_append { string::upper(title).as(:title) }
|
16
|
-
|
17
|
-
expect(selected.schema.map(&:name)).to eql(%i[id title])
|
18
|
-
expect(selected.first).to eql(id: 1, title: "JOE'S TASK")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Relation, '#select' do
|
2
|
-
subject(:relation) { container.relations.tasks }
|
3
|
-
|
4
|
-
include_context 'users and tasks'
|
5
|
-
|
6
|
-
before do
|
7
|
-
conf.relation(:tasks) { schema(infer: true) }
|
8
|
-
end
|
9
|
-
|
10
|
-
with_adapters do
|
11
|
-
it 'projects a relation using a list of symbols' do
|
12
|
-
expect(relation.select(:id, :title).to_a)
|
13
|
-
.to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task"}])
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'projects a relation using a schema' do
|
17
|
-
expect(relation.select(*relation.schema.project(:id, :title)).to_a)
|
18
|
-
.to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task"}])
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'maintains schema' do
|
22
|
-
expect(relation.select(:id, :title).schema.map(&:name)).to eql(%i[id title])
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'supports args and blocks' do
|
26
|
-
expect(relation.select(:id) { [title] }.schema.map(&:name)).to eql(%i[id title])
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'supports blocks' do
|
30
|
-
expect(relation.select { [id, title] }.schema.map(&:name)).to eql(%i[id title])
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'supports selecting literal strings' do
|
34
|
-
new_rel = relation.select { `'event'`.as(:type) }
|
35
|
-
|
36
|
-
expect(new_rel.schema[:type].primitive).to be(String)
|
37
|
-
expect(new_rel.first).to eql(type: 'event')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Relation, '#union' do
|
2
|
-
subject(:relation) { container.relations.users }
|
3
|
-
|
4
|
-
include_context 'users and tasks'
|
5
|
-
|
6
|
-
with_adapters do
|
7
|
-
let(:relation1) { relation.where(id: 1).select(:id, :name) }
|
8
|
-
let(:relation2) { relation.where(id: 2).select(:id, :name) }
|
9
|
-
|
10
|
-
it 'unions two relations and returns a new relation' do
|
11
|
-
result = relation1.union(relation2)
|
12
|
-
|
13
|
-
expect(result.to_a).to match_array([
|
14
|
-
{ id: 1, name: 'Jane' },
|
15
|
-
{ id: 2, name: 'Joe' }
|
16
|
-
])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Relation, '#unique?' do
|
2
|
-
subject(:relation) { container.relations.tasks }
|
3
|
-
|
4
|
-
include_context 'users and tasks'
|
5
|
-
|
6
|
-
with_adapters do
|
7
|
-
before { relation.delete }
|
8
|
-
|
9
|
-
it 'returns true when there is only one tuple matching criteria' do
|
10
|
-
expect(relation.unique?(title: 'Task One')).to be(true)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns true when there are more than one tuple matching criteria' do
|
14
|
-
relation.insert(title: 'Task One')
|
15
|
-
expect(relation.unique?(title: 'Task One')).to be(false)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Relation, '#where' do
|
2
|
-
subject(:relation) { relations[:tasks].select(:id, :title) }
|
3
|
-
|
4
|
-
include_context 'users and tasks'
|
5
|
-
|
6
|
-
with_adapters do
|
7
|
-
context 'without :read types' do
|
8
|
-
it 'restricts relation using provided conditions' do
|
9
|
-
expect(relation.where(id: 1).to_a).
|
10
|
-
to eql([{ id: 1, title: "Joe's task" }])
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'restricts relation using provided conditions and block' do
|
14
|
-
expect(relation.where(id: 1) { title.like("%Jane%") }.to_a).to be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'restricts relation using provided conditions in a block' do
|
18
|
-
expect(relation.where { (id > 2) & title.like("%Jane%") }.to_a).to be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'restricts relation using canonical attributes' do
|
22
|
-
expect(relation.rename(id: :user_id).where { id > 3 }.to_a).to be_empty
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'restricts with or condition' do
|
26
|
-
expect(relation.where { id.is(1) | id.is(2) }.to_a).
|
27
|
-
to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task" }])
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'restricts with a range condition' do
|
31
|
-
expect(relation.where { id.in(-1...2) }.to_a).
|
32
|
-
to eql([{ id: 1, title: "Joe's task" }])
|
33
|
-
|
34
|
-
expect(relation.where { id.in(0...3) }.to_a).
|
35
|
-
to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task" }])
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'restricts with an inclusive range' do
|
39
|
-
expect(relation.where { id.in(0..2) }.to_a).
|
40
|
-
to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task" }])
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'restricts with an ordinary enum' do
|
44
|
-
expect(relation.where { id.in(2, 3) }.to_a).
|
45
|
-
to eql([{ id: 2, title: "Jane's task" }])
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'restricts with enum using self syntax' do
|
49
|
-
expect(relation.where(relation[:id].in(2, 3)).to_a).
|
50
|
-
to eql([{ id: 2, title: "Jane's task" }])
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'using underscored symbols for qualifying' do
|
54
|
-
before { Sequel.split_symbols = true }
|
55
|
-
after { Sequel.split_symbols = false }
|
56
|
-
|
57
|
-
it 'queries with a qualified name' do
|
58
|
-
expect(relation.where(tasks__id: 1).to_a).
|
59
|
-
to eql([{ id: 1, title: "Joe's task" }])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'restricts with a function' do
|
64
|
-
expect(relation.where { string::lower(title).is("joe's task") }.to_a).
|
65
|
-
to eql([{ id: 1, title: "Joe's task" }])
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'restricts with a function using LIKE' do
|
69
|
-
expect(relation.where { string::lower(title).like("joe%") }.to_a).
|
70
|
-
to eql([{ id: 1, title: "Joe's task" }])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'with :read types' do
|
75
|
-
before do
|
76
|
-
conf.relation(:tasks) do
|
77
|
-
schema(infer: true) do
|
78
|
-
attribute :id, ROM::SQL::Types::Serial.constructor(&:to_i)
|
79
|
-
attribute :title, ROM::SQL::Types::Coercible::String
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
module Test
|
84
|
-
Id = Struct.new(:v) do
|
85
|
-
def to_i
|
86
|
-
v.to_i
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
Title = Struct.new(:v) do
|
91
|
-
def to_s
|
92
|
-
v.to_s
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'applies write_schema to hash conditions' do
|
99
|
-
rel = tasks.where(id: Test::Id.new('2'), title: Test::Title.new(:"Jane's task"))
|
100
|
-
|
101
|
-
expect(rel.first).
|
102
|
-
to eql(id: 2, user_id: 1, title: "Jane's task")
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'applies write_schema to hash conditions where value is an array' do
|
106
|
-
ids = %w(1 2).map(&Test::Id.method(:new))
|
107
|
-
rel = tasks.where(id: ids)
|
108
|
-
|
109
|
-
expect(rel.to_a).
|
110
|
-
to eql([
|
111
|
-
{ id: 1, user_id: 2, title: "Joe's task" },
|
112
|
-
{ id: 2, user_id: 1, title: "Jane's task" }
|
113
|
-
])
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'applies write_schema to conditions with operators other than equality' do
|
117
|
-
rel = tasks.where { id >= Test::Id.new('2') }
|
118
|
-
|
119
|
-
expect(rel.first).
|
120
|
-
to eql(id: 2, user_id: 1, title: "Jane's task")
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'applies write_schema to conditions in a block' do
|
124
|
-
rel = tasks.where {
|
125
|
-
id.is(Test::Id.new('2')) & title.is(Test::Title.new(:"Jane's task"))
|
126
|
-
}
|
127
|
-
|
128
|
-
expect(rel.first).
|
129
|
-
to eql(id: 2, user_id: 1, title: "Jane's task")
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ROM::SQL::RestrictionDSL, :sqlite, helpers: true do
|
4
|
-
include_context 'database setup'
|
5
|
-
|
6
|
-
subject(:dsl) do
|
7
|
-
ROM::SQL::RestrictionDSL.new(schema)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:schema) do
|
11
|
-
define_schema(:users, id: ROM::SQL::Types::Serial, name: ROM::SQL::Types::String)
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:ds) do
|
15
|
-
conn[:users]
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#call' do
|
19
|
-
it 'evaluates the block and returns an SQL expression' do
|
20
|
-
expect(conn[:users].literal(dsl.call { count(id) >= 3 })).to eql('(count(`id`) >= 3)')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#method_missing' do
|
25
|
-
it 'responds to methods matching attribute names' do
|
26
|
-
expect(dsl.id.name).to be(:id)
|
27
|
-
expect(dsl.name.name).to be(:name)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'delegates to sequel virtual row' do
|
31
|
-
expect(conn[:users].literal(dsl.count(dsl.id))).to eql('count(`id`)')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/spec/unit/schema_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Schema, :postgres do
|
2
|
-
describe '#primary_key' do
|
3
|
-
it 'returns primary key attributes' do
|
4
|
-
schema_proc = Class.new(ROM::Relation[:sql]).schema do
|
5
|
-
attribute :id, ROM::SQL::Types::Serial
|
6
|
-
end
|
7
|
-
|
8
|
-
schema = schema_proc.call
|
9
|
-
schema.finalize_attributes!.finalize!
|
10
|
-
|
11
|
-
expect(schema.primary_key).to eql([schema[:id]])
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns empty array when there is no PK defined' do
|
15
|
-
schema_proc = Class.new(ROM::Relation[:sql]).schema do
|
16
|
-
attribute :id, ROM::SQL::Types::Int
|
17
|
-
end
|
18
|
-
|
19
|
-
schema = schema_proc.call
|
20
|
-
schema.finalize_attributes!.finalize!
|
21
|
-
|
22
|
-
expect(schema.primary_key).to eql([])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/unit/types_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'rom/sql/types'
|
2
|
-
|
3
|
-
RSpec.describe ROM::SQL::Types, :postgres do
|
4
|
-
describe ROM::SQL::Types::Blob do
|
5
|
-
it 'coerces strings to Sequel::SQL::Blob' do
|
6
|
-
input = 'sutin'
|
7
|
-
output = described_class[input]
|
8
|
-
|
9
|
-
expect(output).to be_instance_of(Sequel::SQL::Blob)
|
10
|
-
expect(output).to eql('sutin')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#sql_literal', helpers: true do
|
15
|
-
subject(:base) { define_attribute(:age, :Int, source: ROM::Relation::Name.new(:users)) }
|
16
|
-
|
17
|
-
include_context 'database setup'
|
18
|
-
|
19
|
-
let(:ds) { container.gateways[:default][:users] }
|
20
|
-
let(:sql_literal) { type.sql_literal(ds) }
|
21
|
-
|
22
|
-
context 'when qualified' do
|
23
|
-
subject(:type) { base.qualified }
|
24
|
-
|
25
|
-
specify do
|
26
|
-
expect(sql_literal).to eql(%("users"."age"))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when aliased' do
|
31
|
-
subject(:type) { base.as(:user_age) }
|
32
|
-
|
33
|
-
specify do
|
34
|
-
expect(sql_literal).to eql(%("age" AS "user_age"))
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when qualified and aliased' do
|
39
|
-
subject(:type) { base.qualified.as(:user_age) }
|
40
|
-
|
41
|
-
specify do
|
42
|
-
expect(sql_literal).to eql(%("users"."age" AS "user_age"))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when aliased and qualified' do
|
47
|
-
subject(:type) { base.as(:user_age).qualified }
|
48
|
-
|
49
|
-
specify do
|
50
|
-
expect(sql_literal).to eql(%("users"."age" AS "user_age"))
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when qualified with a function expr' do
|
55
|
-
subject(:type) { base.meta(sql_expr: func).qualified }
|
56
|
-
|
57
|
-
let(:func) { Sequel::SQL::Function.new(:count, :age) }
|
58
|
-
|
59
|
-
specify do
|
60
|
-
expect { sql_literal }.
|
61
|
-
to raise_error(ROM::SQL::Attribute::QualifyError, "can't qualify :age (#{func.inspect})")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|