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,83 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Association::OneToOne, helpers: true do
|
2
|
-
subject(:assoc) do
|
3
|
-
ROM::SQL::Association::OneToOne.new(source, target, options)
|
4
|
-
end
|
5
|
-
|
6
|
-
let(:options) { {} }
|
7
|
-
|
8
|
-
let(:users) { double(:users, primary_key: :id) }
|
9
|
-
let(:tasks) { double(:tasks) }
|
10
|
-
let(:avatars) { double(:avatars) }
|
11
|
-
|
12
|
-
describe '#associate' do
|
13
|
-
let(:source) { :users }
|
14
|
-
let(:target) { :avatar }
|
15
|
-
|
16
|
-
let(:relations) do
|
17
|
-
{ users: users, avatar: avatars }
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns child tuple with FK set' do
|
21
|
-
expect(avatars).to receive(:foreign_key).with(:users).and_return(:user_id)
|
22
|
-
|
23
|
-
avatar_tuple = { url: 'http://rom-rb.org/images/logo.svg' }
|
24
|
-
user_tuple = { id: 3 }
|
25
|
-
|
26
|
-
expect(assoc.associate(relations, avatar_tuple, user_tuple)).to eql(
|
27
|
-
user_id: 3, url: 'http://rom-rb.org/images/logo.svg'
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
shared_examples_for 'one-to-one association' do
|
33
|
-
describe '#combine_keys' do
|
34
|
-
it 'returns a hash with combine keys' do
|
35
|
-
expect(tasks).to receive(:foreign_key).with(:users).and_return(:user_id)
|
36
|
-
|
37
|
-
expect(assoc.combine_keys(relations)).to eql(id: :user_id)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with default names' do
|
43
|
-
let(:source) { :users }
|
44
|
-
let(:target) { :tasks }
|
45
|
-
|
46
|
-
let(:relations) do
|
47
|
-
{ users: users, tasks: tasks }
|
48
|
-
end
|
49
|
-
|
50
|
-
it_behaves_like 'one-to-one association'
|
51
|
-
|
52
|
-
describe '#join_keys' do
|
53
|
-
it 'returns a hash with combine keys' do
|
54
|
-
expect(tasks).to receive(:foreign_key).with(:users).and_return(:user_id)
|
55
|
-
|
56
|
-
expect(assoc.join_keys(relations)).to eql(
|
57
|
-
qualified_attribute(:users, :id) => qualified_attribute(:tasks, :user_id)
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'with custom relation names' do
|
64
|
-
let(:source) { assoc_name(:users, :people) }
|
65
|
-
let(:target) { assoc_name(:tasks, :user_tasks) }
|
66
|
-
|
67
|
-
let(:relations) do
|
68
|
-
{ users: users, tasks: tasks }
|
69
|
-
end
|
70
|
-
|
71
|
-
it_behaves_like 'one-to-one association'
|
72
|
-
|
73
|
-
describe '#join_keys' do
|
74
|
-
it 'returns a hash with combine keys' do
|
75
|
-
expect(tasks).to receive(:foreign_key).with(:users).and_return(:user_id)
|
76
|
-
|
77
|
-
expect(assoc.join_keys(relations)).to eql(
|
78
|
-
qualified_attribute(:people, :id) => qualified_attribute(:user_tasks, :user_id)
|
79
|
-
)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::SQL::Association::OneToOneThrough, helpers: true do
|
2
|
-
subject(:assoc) do
|
3
|
-
ROM::SQL::Association::OneToOneThrough.new(source, target, options)
|
4
|
-
end
|
5
|
-
|
6
|
-
let(:options) { { through: :tasks_tags } }
|
7
|
-
|
8
|
-
let(:tags) { double(:tags, primary_key: :id) }
|
9
|
-
let(:tasks) { double(:tasks, primary_key: :id) }
|
10
|
-
let(:tasks_tags) { double(:tasks, primary_key: [:task_id, :tag_id]) }
|
11
|
-
|
12
|
-
let(:source) { :tasks }
|
13
|
-
let(:target) { :tags }
|
14
|
-
|
15
|
-
describe '#result' do
|
16
|
-
it 'is :one' do
|
17
|
-
expect(assoc.result).to be(:one)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
shared_examples_for 'many-to-many association' do
|
22
|
-
describe '#combine_keys' do
|
23
|
-
it 'returns a hash with combine keys' do
|
24
|
-
expect(tasks_tags).to receive(:foreign_key).with(:tasks).and_return(:tag_id)
|
25
|
-
|
26
|
-
expect(assoc.combine_keys(relations)).to eql(id: :tag_id)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with default names' do
|
32
|
-
let(:relations) do
|
33
|
-
{ tasks: tasks, tags: tags, tasks_tags: tasks_tags }
|
34
|
-
end
|
35
|
-
|
36
|
-
it_behaves_like 'many-to-many association'
|
37
|
-
|
38
|
-
describe '#join_keys' do
|
39
|
-
it 'returns a hash with combine keys' do
|
40
|
-
expect(tasks_tags).to receive(:foreign_key).with(:tasks).and_return(:tag_id)
|
41
|
-
|
42
|
-
expect(assoc.join_keys(relations)).to eql(
|
43
|
-
qualified_attribute(:tasks, :id) => qualified_attribute(:tasks_tags, :tag_id)
|
44
|
-
)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'with custom relation names' do
|
50
|
-
let(:source) { assoc_name(:tasks, :user_tasks) }
|
51
|
-
let(:target) { assoc_name(:tags, :user_tags) }
|
52
|
-
|
53
|
-
let(:relations) do
|
54
|
-
{ tasks: tasks, tags: tags, tasks_tags: tasks_tags }
|
55
|
-
end
|
56
|
-
|
57
|
-
it_behaves_like 'many-to-many association'
|
58
|
-
|
59
|
-
describe '#join_keys' do
|
60
|
-
it 'returns a hash with combine keys' do
|
61
|
-
expect(tasks_tags).to receive(:foreign_key).with(:tasks).and_return(:tag_id)
|
62
|
-
|
63
|
-
expect(assoc.join_keys(relations)).to eql(
|
64
|
-
qualified_attribute(:user_tasks, :id) => qualified_attribute(:tasks_tags, :tag_id)
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|