rom-sql 1.3.5 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -7
- data/Gemfile +7 -5
- data/lib/rom/plugins/relation/sql/auto_restrictions.rb +11 -17
- data/lib/rom/sql.rb +3 -2
- data/lib/rom/sql/associations.rb +5 -0
- data/lib/rom/sql/associations/core.rb +20 -0
- data/lib/rom/sql/associations/many_to_many.rb +83 -0
- data/lib/rom/sql/associations/many_to_one.rb +55 -0
- data/lib/rom/sql/associations/one_to_many.rb +31 -0
- data/lib/rom/sql/{association → associations}/one_to_one.rb +3 -2
- data/lib/rom/sql/{association → associations}/one_to_one_through.rb +3 -2
- data/lib/rom/sql/associations/self_ref.rb +39 -0
- data/lib/rom/sql/attribute.rb +44 -54
- data/lib/rom/sql/errors.rb +2 -0
- data/lib/rom/sql/extensions/mysql.rb +1 -1
- data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +10 -0
- data/lib/rom/sql/extensions/postgres.rb +1 -1
- data/lib/rom/sql/extensions/postgres/{inferrer.rb → attributes_inferrer.rb} +4 -4
- data/lib/rom/sql/extensions/postgres/types.rb +9 -19
- data/lib/rom/sql/extensions/sqlite.rb +1 -1
- data/lib/rom/sql/extensions/sqlite/{inferrer.rb → attributes_inferrer.rb} +2 -2
- data/lib/rom/sql/gateway.rb +29 -30
- data/lib/rom/sql/index.rb +13 -0
- data/lib/rom/sql/migration.rb +10 -0
- data/lib/rom/sql/migration/inline_runner.rb +86 -0
- data/lib/rom/sql/migration/migrator.rb +17 -0
- data/lib/rom/sql/migration/schema_diff.rb +177 -0
- data/lib/rom/sql/plugin/associates.rb +11 -45
- data/lib/rom/sql/plugin/pagination.rb +4 -4
- data/lib/rom/sql/relation.rb +22 -42
- data/lib/rom/sql/relation/reading.rb +3 -3
- data/lib/rom/sql/schema.rb +14 -21
- data/lib/rom/sql/schema/associations_dsl.rb +7 -6
- data/lib/rom/sql/schema/attributes_inferrer.rb +164 -0
- data/lib/rom/sql/schema/inferrer.rb +40 -141
- data/lib/rom/sql/type_extensions.rb +44 -0
- data/lib/rom/sql/version.rb +1 -1
- data/lib/rom/sql/wrap.rb +25 -0
- data/rom-sql.gemspec +2 -2
- data/spec/integration/{association → associations}/many_to_many/custom_fks_spec.rb +4 -2
- data/spec/integration/{association → associations}/many_to_many/from_view_spec.rb +2 -2
- data/spec/integration/{association → associations}/many_to_many_spec.rb +25 -30
- data/spec/integration/{association → associations}/many_to_one/custom_fks_spec.rb +5 -3
- data/spec/integration/{association → associations}/many_to_one/from_view_spec.rb +3 -3
- data/spec/integration/{association → associations}/many_to_one/self_ref_spec.rb +2 -2
- data/spec/integration/{association → associations}/many_to_one_spec.rb +20 -38
- data/spec/integration/{association → associations}/one_to_many/custom_fks_spec.rb +4 -2
- data/spec/integration/{association → associations}/one_to_many/from_view_spec.rb +2 -2
- data/spec/integration/{association → associations}/one_to_many/self_ref_spec.rb +2 -2
- data/spec/integration/{association → associations}/one_to_many_spec.rb +24 -11
- data/spec/integration/{association → associations}/one_to_one_spec.rb +13 -9
- data/spec/integration/{association → associations}/one_to_one_through_spec.rb +15 -11
- data/spec/integration/auto_migrations/errors_spec.rb +31 -0
- data/spec/integration/auto_migrations/indexes_spec.rb +109 -0
- data/spec/integration/auto_migrations/managing_columns_spec.rb +156 -0
- data/spec/integration/auto_migrations/postgres/column_types_spec.rb +63 -0
- data/spec/integration/commands/create_spec.rb +2 -4
- data/spec/integration/commands/delete_spec.rb +2 -2
- data/spec/integration/commands/update_spec.rb +2 -0
- data/spec/integration/graph_spec.rb +9 -3
- data/spec/integration/plugins/associates_spec.rb +16 -55
- data/spec/integration/plugins/auto_restrictions_spec.rb +0 -11
- data/spec/integration/relation_schema_spec.rb +49 -25
- data/spec/integration/schema/inferrer/postgres_spec.rb +1 -1
- data/spec/integration/schema/inferrer_spec.rb +7 -18
- data/spec/integration/setup_spec.rb +4 -0
- data/spec/integration/{plugins/auto_wrap_spec.rb → wrap_spec.rb} +13 -36
- data/spec/shared/accounts.rb +4 -0
- data/spec/shared/database_setup.rb +2 -1
- data/spec/shared/notes.rb +2 -0
- data/spec/shared/posts.rb +2 -0
- data/spec/shared/puppies.rb +2 -0
- data/spec/shared/relations.rb +2 -2
- data/spec/shared/users.rb +2 -0
- data/spec/shared/users_and_tasks.rb +4 -0
- data/spec/spec_helper.rb +3 -6
- data/spec/support/helpers.rb +11 -8
- data/spec/support/test_configuration.rb +16 -0
- data/spec/unit/plugin/associates_spec.rb +5 -10
- data/spec/unit/plugin/pagination_spec.rb +9 -9
- data/spec/unit/plugin/timestamp_spec.rb +9 -9
- data/spec/unit/relation/dataset_spec.rb +7 -5
- data/spec/unit/relation/inner_join_spec.rb +2 -15
- data/spec/unit/relation/primary_key_spec.rb +1 -1
- data/spec/unit/schema_spec.rb +6 -4
- metadata +65 -70
- data/lib/rom/plugins/relation/sql/auto_combine.rb +0 -71
- data/lib/rom/plugins/relation/sql/auto_wrap.rb +0 -62
- data/lib/rom/sql/association.rb +0 -103
- data/lib/rom/sql/association/many_to_many.rb +0 -119
- data/lib/rom/sql/association/many_to_one.rb +0 -73
- data/lib/rom/sql/association/name.rb +0 -78
- data/lib/rom/sql/association/one_to_many.rb +0 -60
- data/lib/rom/sql/extensions/mysql/inferrer.rb +0 -10
- data/lib/rom/sql/qualified_attribute.rb +0 -53
- data/lib/rom/sql/schema/dsl.rb +0 -75
- data/spec/unit/association/many_to_many_spec.rb +0 -89
- data/spec/unit/association/many_to_one_spec.rb +0 -81
- data/spec/unit/association/name_spec.rb +0 -68
- data/spec/unit/association/one_to_many_spec.rb +0 -82
- data/spec/unit/association/one_to_one_spec.rb +0 -83
- data/spec/unit/association/one_to_one_through_spec.rb +0 -69
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::
|
3
|
+
RSpec.describe ROM::SQL::Associations::ManyToOne, '#call' do
|
4
4
|
include_context 'database setup'
|
5
5
|
|
6
6
|
before do
|
@@ -24,6 +24,8 @@ RSpec.describe ROM::SQL::Association::ManyToOne, '#call' do
|
|
24
24
|
column :code, String, null: false
|
25
25
|
end
|
26
26
|
|
27
|
+
conf.relation(:destinations) { schema(infer: true) }
|
28
|
+
|
27
29
|
conf.relation(:flights) do
|
28
30
|
schema(infer: true) do
|
29
31
|
associations do
|
@@ -40,7 +42,7 @@ RSpec.describe ROM::SQL::Association::ManyToOne, '#call' do
|
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'prepares joined relations using correct FKs based on association aliases' do
|
43
|
-
relation = assoc_from.
|
45
|
+
relation = assoc_from.()
|
44
46
|
|
45
47
|
expect(relation.schema.map(&:to_sql_name)).
|
46
48
|
to eql([Sequel.qualify(:destinations, :id),
|
@@ -49,7 +51,7 @@ RSpec.describe ROM::SQL::Association::ManyToOne, '#call' do
|
|
49
51
|
|
50
52
|
expect(relation.first).to eql(id: 1, name: 'FROM', flight_id: 1)
|
51
53
|
|
52
|
-
relation = assoc_to.
|
54
|
+
relation = assoc_to.()
|
53
55
|
|
54
56
|
expect(relation.schema.map(&:to_sql_name)).
|
55
57
|
to eql([Sequel.qualify(:destinations, :id),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::
|
3
|
+
RSpec.describe ROM::SQL::Associations::ManyToOne, '#call' do
|
4
4
|
include_context 'database setup'
|
5
5
|
|
6
6
|
before do
|
@@ -58,7 +58,7 @@ RSpec.describe ROM::SQL::Association::ManyToOne, '#call' do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'prepares joined relations using custom view in target relation' do
|
61
|
-
relation = assoc_inter.
|
61
|
+
relation = assoc_inter.()
|
62
62
|
|
63
63
|
expect(relation.schema.map(&:to_sql_name)).
|
64
64
|
to eql([Sequel.qualify(:destinations, :id),
|
@@ -69,7 +69,7 @@ RSpec.describe ROM::SQL::Association::ManyToOne, '#call' do
|
|
69
69
|
expect(relation.first).to eql(id: 2, intermediate: db_true, name: 'Intermediate', flight_id: 1)
|
70
70
|
expect(relation.count).to be(1)
|
71
71
|
|
72
|
-
relation = assoc_final.
|
72
|
+
relation = assoc_final.()
|
73
73
|
|
74
74
|
expect(relation.schema.map(&:to_sql_name)).
|
75
75
|
to eql([Sequel.qualify(:destinations, :id),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::
|
3
|
+
RSpec.describe ROM::SQL::Associations::ManyToOne, '#call' do
|
4
4
|
subject(:assoc) do
|
5
5
|
relations[:categories].associations[:parent]
|
6
6
|
end
|
@@ -35,7 +35,7 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'prepares joined relations using custom FK for a self-ref association' do
|
38
|
-
relation = assoc.
|
38
|
+
relation = assoc.()
|
39
39
|
|
40
40
|
expect(relation.schema.map(&:to_sql_name)).
|
41
41
|
to eql([Sequel.qualify(:categories, :id),
|
@@ -1,45 +1,36 @@
|
|
1
|
-
RSpec.describe ROM::SQL::
|
1
|
+
RSpec.describe ROM::SQL::Associations::ManyToOne, helpers: true do
|
2
2
|
with_adapters do
|
3
3
|
context 'common name conventions' do
|
4
4
|
include_context 'users and tasks'
|
5
5
|
include_context 'accounts'
|
6
6
|
|
7
|
-
subject(:assoc)
|
8
|
-
|
9
|
-
|
7
|
+
subject(:assoc) do
|
8
|
+
build_assoc(:many_to_one, :tasks, :users)
|
9
|
+
end
|
10
10
|
|
11
11
|
before do
|
12
12
|
conf.relation(:tasks) do
|
13
|
-
schema
|
14
|
-
attribute :id, ROM::SQL::Types::Serial
|
15
|
-
attribute :user_id, ROM::SQL::Types::ForeignKey(:users)
|
16
|
-
attribute :title, ROM::SQL::Types::String
|
17
|
-
end
|
13
|
+
schema(infer: true)
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
21
|
-
describe '#result' do
|
22
|
-
specify { expect(ROM::SQL::Association::ManyToOne.result).to be(:one) }
|
23
|
-
end
|
24
|
-
|
25
17
|
describe '#name' do
|
26
18
|
it 'uses target by default' do
|
27
19
|
expect(assoc.name).to be(:users)
|
28
20
|
end
|
29
21
|
end
|
30
22
|
|
31
|
-
describe '#
|
32
|
-
|
33
|
-
|
23
|
+
describe '#result' do
|
24
|
+
specify { expect(assoc.result).to be(:one) }
|
25
|
+
end
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
27
|
+
describe '#combine_keys' do
|
28
|
+
specify { expect(assoc.combine_keys).to eql(user_id: :id) }
|
38
29
|
end
|
39
30
|
|
40
31
|
describe '#call' do
|
41
32
|
it 'prepares joined relations' do
|
42
|
-
relation = assoc.
|
33
|
+
relation = assoc.(preload: false)
|
43
34
|
|
44
35
|
expect(relation.schema.map(&:to_sql_name)).
|
45
36
|
to eql([Sequel.qualify(:users, :id),
|
@@ -58,15 +49,11 @@ RSpec.describe ROM::SQL::Association::ManyToOne, helpers: true do
|
|
58
49
|
end
|
59
50
|
end
|
60
51
|
|
61
|
-
describe
|
52
|
+
describe '#eager_load' do
|
62
53
|
it 'preloads relation based on association' do
|
63
|
-
relation = users.
|
54
|
+
relation = users.eager_load(assoc).call(tasks.call)
|
64
55
|
|
65
|
-
expect(relation.to_a).
|
66
|
-
to eql([
|
67
|
-
{ id: 1, task_id: 2, name: 'Jane' },
|
68
|
-
{ id: 2, task_id: 1, name: 'Joe' }
|
69
|
-
])
|
56
|
+
expect(relation.to_a).to eql([{ id: 1, name: 'Jane' }, { id: 2, name: 'Joe' }])
|
70
57
|
end
|
71
58
|
|
72
59
|
it 'maintains original relation' do
|
@@ -76,11 +63,11 @@ RSpec.describe ROM::SQL::Association::ManyToOne, helpers: true do
|
|
76
63
|
join(:accounts, user_id: :id).
|
77
64
|
select_append(users.accounts[:number].as(:account_num)).
|
78
65
|
order(:account_num).
|
79
|
-
|
66
|
+
eager_load(assoc).call(tasks.call)
|
80
67
|
|
81
68
|
expect(relation.to_a).
|
82
|
-
to eql([{ id: 2,
|
83
|
-
{ id: 1,
|
69
|
+
to eql([{ id: 2, name: 'Joe', account_num: '31' },
|
70
|
+
{ id: 1, name: 'Jane', account_num: '42' }])
|
84
71
|
end
|
85
72
|
end
|
86
73
|
end
|
@@ -93,23 +80,18 @@ RSpec.describe ROM::SQL::Association::ManyToOne, helpers: true do
|
|
93
80
|
let(:articles) { container.relations[:articles] }
|
94
81
|
|
95
82
|
subject(:assoc) do
|
96
|
-
|
83
|
+
build_assoc(:many_to_one, articles_name, :users)
|
97
84
|
end
|
98
85
|
|
99
86
|
before do
|
100
87
|
conf.relation(:articles) do
|
101
|
-
schema(:posts)
|
102
|
-
attribute :post_id, ROM::SQL::Types::Serial
|
103
|
-
attribute :author_id, ROM::SQL::Types::ForeignKey(:users)
|
104
|
-
attribute :title, ROM::SQL::Types::Strict::String
|
105
|
-
attribute :body, ROM::SQL::Types::Strict::String
|
106
|
-
end
|
88
|
+
schema(:posts, infer: true)
|
107
89
|
end
|
108
90
|
end
|
109
91
|
|
110
92
|
describe '#call' do
|
111
93
|
it 'prepares joined relations' do
|
112
|
-
relation = assoc.
|
94
|
+
relation = assoc.()
|
113
95
|
|
114
96
|
expect(relation.schema.map(&:to_sql_name)).
|
115
97
|
to eql([Sequel.qualify(:users, :id),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::
|
3
|
+
RSpec.describe ROM::SQL::Associations::OneToMany, '#call' do
|
4
4
|
include_context 'users'
|
5
5
|
|
6
6
|
before do
|
@@ -20,6 +20,8 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
20
20
|
column :text, String, null: false
|
21
21
|
end
|
22
22
|
|
23
|
+
conf.relation(:puzzles) { schema(infer: true) }
|
24
|
+
|
23
25
|
conf.relation(:users) do
|
24
26
|
schema(infer: true) do
|
25
27
|
associations do
|
@@ -38,7 +40,7 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
38
40
|
end
|
39
41
|
|
40
42
|
it 'prepares joined relations using custom FK' do
|
41
|
-
relation = assoc.
|
43
|
+
relation = assoc.()
|
42
44
|
|
43
45
|
expect(relation.schema.map(&:to_sql_name)).
|
44
46
|
to eql([Sequel.qualify(:puzzles, :id),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::
|
3
|
+
RSpec.describe ROM::SQL::Associations::OneToMany, '#call' do
|
4
4
|
include_context 'users'
|
5
5
|
|
6
6
|
before do
|
@@ -42,7 +42,7 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'prepares joined relations using custom view' do
|
45
|
-
relation = assoc.
|
45
|
+
relation = assoc.()
|
46
46
|
|
47
47
|
expect(relation.schema.map(&:to_sql_name)).
|
48
48
|
to eql([Sequel.qualify(:puzzles, :id),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ROM::SQL::
|
3
|
+
RSpec.describe ROM::SQL::Associations::OneToMany, '#call' do
|
4
4
|
include_context 'database setup'
|
5
5
|
|
6
6
|
before do
|
@@ -36,7 +36,7 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'prepares joined relations using custom FK for a self-ref association' do
|
39
|
-
relation = assoc.
|
39
|
+
relation = assoc.()
|
40
40
|
|
41
41
|
expect(relation.schema.map(&:to_sql_name)).
|
42
42
|
to eql([Sequel.qualify(:categories, :id),
|
@@ -1,10 +1,10 @@
|
|
1
|
-
RSpec.describe ROM::SQL::
|
2
|
-
subject(:assoc) {
|
3
|
-
ROM::SQL::Association::OneToMany.new(:users, :tasks)
|
4
|
-
}
|
5
|
-
|
1
|
+
RSpec.describe ROM::SQL::Associations::OneToMany, helpers: true do
|
6
2
|
include_context 'users and tasks'
|
7
3
|
|
4
|
+
subject(:assoc) do
|
5
|
+
build_assoc(:one_to_many, :users, :tasks)
|
6
|
+
end
|
7
|
+
|
8
8
|
with_adapters do
|
9
9
|
before do
|
10
10
|
conf.relation(:tasks) do
|
@@ -17,12 +17,25 @@ RSpec.describe ROM::SQL::Association::OneToMany do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '#result' do
|
20
|
-
specify { expect(
|
20
|
+
specify { expect(assoc.result).to be(:many) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#combine_keys' do
|
24
|
+
specify { expect(assoc.combine_keys).to eql(id: :user_id) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#associate' do
|
28
|
+
it 'merges FKs into tuples' do
|
29
|
+
child = { name: 'Child' }
|
30
|
+
parent = { id: 312, name: 'Parent '}
|
31
|
+
|
32
|
+
expect(assoc.associate(child, parent)).to eql(user_id: 312, name: 'Child')
|
33
|
+
end
|
21
34
|
end
|
22
35
|
|
23
36
|
describe '#call' do
|
24
37
|
it 'prepares joined relations' do
|
25
|
-
relation = assoc.
|
38
|
+
relation = assoc.()
|
26
39
|
|
27
40
|
expect(relation.schema.map(&:name)).to eql(%i[id user_id title])
|
28
41
|
|
@@ -41,9 +54,9 @@ RSpec.describe ROM::SQL::Association::OneToMany do
|
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
44
|
-
describe
|
57
|
+
describe '#eager_load' do
|
45
58
|
it 'preloads relation based on association' do
|
46
|
-
relation = tasks.
|
59
|
+
relation = tasks.eager_load(assoc).call(users.call)
|
47
60
|
|
48
61
|
expect(relation.to_a).to eql([
|
49
62
|
{ id: 1, user_id: 2, title: "Joe's task" },
|
@@ -55,7 +68,7 @@ RSpec.describe ROM::SQL::Association::OneToMany do
|
|
55
68
|
relation = tasks.
|
56
69
|
join(:task_tags, tag_id: :id).
|
57
70
|
select_append(tasks.task_tags[:tag_id].qualified).
|
58
|
-
|
71
|
+
eager_load(assoc).call(users.call)
|
59
72
|
|
60
73
|
expect(relation.to_a).to eql([{ id: 1, user_id: 2, title: "Joe's task", tag_id: 1 }])
|
61
74
|
end
|
@@ -63,7 +76,7 @@ RSpec.describe ROM::SQL::Association::OneToMany do
|
|
63
76
|
it 'respects custom order' do
|
64
77
|
relation = tasks.
|
65
78
|
order(tasks[:title].qualified).
|
66
|
-
|
79
|
+
eager_load(assoc).call(users.call)
|
67
80
|
|
68
81
|
expect(relation.to_a).
|
69
82
|
to eql([{ id: 2, user_id: 1, title: "Jane's task" }, { id: 1, user_id: 2, title: "Joe's task" }])
|
@@ -1,10 +1,10 @@
|
|
1
|
-
RSpec.describe ROM::SQL::
|
1
|
+
RSpec.describe ROM::SQL::Associations::OneToOne, helpers: true do
|
2
2
|
include_context 'users'
|
3
3
|
include_context 'accounts'
|
4
4
|
|
5
|
-
subject(:assoc)
|
6
|
-
|
7
|
-
|
5
|
+
subject(:assoc) do
|
6
|
+
build_assoc(:one_to_one, :users, :accounts)
|
7
|
+
end
|
8
8
|
|
9
9
|
with_adapters do
|
10
10
|
before do
|
@@ -21,16 +21,20 @@ RSpec.describe ROM::SQL::Association::OneToOne do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '#result' do
|
24
|
-
specify { expect(
|
24
|
+
specify { expect(assoc.result).to be(:one) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#combine_keys' do
|
28
|
+
specify { expect(assoc.combine_keys).to eql(id: :user_id) }
|
25
29
|
end
|
26
30
|
|
27
31
|
describe '#call' do
|
28
32
|
it 'prepares joined relations' do |example|
|
29
|
-
relation = assoc.
|
33
|
+
relation = assoc.()
|
30
34
|
|
31
35
|
expect(relation.schema.map(&:name)).to eql(%i[id user_id number balance])
|
32
36
|
|
33
|
-
# TODO: this if
|
37
|
+
# TODO: this if clause should be removed when (and if) https://github.com/xerial/sqlite-jdbc/issues/112
|
34
38
|
# will be resolved. See https://github.com/rom-rb/rom-sql/issues/49 for details
|
35
39
|
if jruby? && sqlite?(example)
|
36
40
|
expect(relation.to_a).
|
@@ -44,9 +48,9 @@ RSpec.describe ROM::SQL::Association::OneToOne do
|
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
|
-
describe
|
51
|
+
describe '#eager_load' do
|
48
52
|
it 'preloads relation based on association' do |example|
|
49
|
-
relation = accounts.
|
53
|
+
relation = accounts.eager_load(assoc).call(users.call)
|
50
54
|
|
51
55
|
# TODO: this if caluse should be removed when (and if) https://github.com/xerial/sqlite-jdbc/issues/112
|
52
56
|
# will be resolved. See https://github.com/rom-rb/rom-sql/issues/49 for details
|
@@ -1,10 +1,10 @@
|
|
1
|
-
RSpec.describe ROM::SQL::
|
1
|
+
RSpec.describe ROM::SQL::Associations::OneToOneThrough, helpers: true do
|
2
2
|
include_context 'users'
|
3
3
|
include_context 'accounts'
|
4
4
|
|
5
|
-
subject(:assoc)
|
6
|
-
|
7
|
-
|
5
|
+
subject(:assoc) do
|
6
|
+
build_assoc(:one_to_one_through, :users, :cards, through: :accounts)
|
7
|
+
end
|
8
8
|
|
9
9
|
with_adapters do
|
10
10
|
before do
|
@@ -48,12 +48,16 @@ RSpec.describe ROM::SQL::Association::OneToOneThrough do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
describe '#result' do
|
51
|
-
specify { expect(
|
51
|
+
specify { expect(assoc.result).to be(:one) }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#combine_keys' do
|
55
|
+
specify { expect(assoc.combine_keys).to eql(id: :user_id) }
|
52
56
|
end
|
53
57
|
|
54
58
|
describe '#call' do
|
55
59
|
it 'prepares joined relations' do
|
56
|
-
relation = assoc.
|
60
|
+
relation = assoc.()
|
57
61
|
|
58
62
|
expect(relation.schema.map(&:name)).to eql(%i[id account_id pan user_id])
|
59
63
|
expect(relation.to_a).to eql([id: 1, account_id: 1, pan: '*6789', user_id: 1])
|
@@ -62,24 +66,24 @@ RSpec.describe ROM::SQL::Association::OneToOneThrough do
|
|
62
66
|
|
63
67
|
describe ':through another assoc' do
|
64
68
|
subject(:assoc) do
|
65
|
-
|
69
|
+
build_assoc(:one_to_one_through, :users, :subscriptions, through: :accounts)
|
66
70
|
end
|
67
71
|
|
68
72
|
let(:account_assoc) do
|
69
|
-
|
73
|
+
build_assoc(:one_to_one_through, :accounts, :subscriptions, through: :cards)
|
70
74
|
end
|
71
75
|
|
72
76
|
it 'prepares joined relations through other association' do
|
73
|
-
relation = assoc.
|
77
|
+
relation = assoc.()
|
74
78
|
|
75
79
|
expect(relation.schema.map(&:name)).to eql(%i[id card_id service user_id])
|
76
80
|
expect(relation.to_a).to eql([id: 1, card_id: 1, service: 'aws', user_id: 1])
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
80
|
-
describe
|
84
|
+
describe '#eager_load' do
|
81
85
|
it 'preloads relation based on association' do
|
82
|
-
relation = cards.
|
86
|
+
relation = cards.eager_load(assoc).call(users.call)
|
83
87
|
|
84
88
|
expect(relation.to_a).to eql([id: 1, account_id: 1, pan: '*6789', user_id: 1])
|
85
89
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
RSpec.describe ROM::SQL::Gateway, :postgres do
|
2
|
+
include_context 'database setup'
|
3
|
+
|
4
|
+
subject(:gateway) { container.gateways[:default] }
|
5
|
+
|
6
|
+
before do
|
7
|
+
conn.drop_table?(:users)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'unsupported conversions' do
|
11
|
+
before do
|
12
|
+
conf.relation(:users) do
|
13
|
+
schema do
|
14
|
+
attribute :id, ROM::SQL::Types::Serial
|
15
|
+
attribute :name, ROM::SQL::Types::String
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raises an error' do
|
21
|
+
conn.create_table :users do
|
22
|
+
primary_key :id
|
23
|
+
column :name, Integer, null: false
|
24
|
+
end
|
25
|
+
|
26
|
+
expect {
|
27
|
+
gateway.auto_migrate!(conf)
|
28
|
+
}.to raise_error(ROM::SQL::UnsupportedConversion, /Don't know how to convert/)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|